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()
442 loadDirectory(url(), true);
445 void DolphinView::refresh()
447 m_ignoreViewProperties
= false;
449 const bool oldActivationState
= m_active
;
450 const int oldZoomLevel
= m_controller
->zoomLevel();
454 applyViewProperties();
457 setActive(oldActivationState
);
458 updateZoomLevel(oldZoomLevel
);
461 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
463 Q_UNUSED(rootUrl
); // TODO: remove after columnview-cleanup has been finished
465 if (m_controller
->url() == url
) {
469 m_controller
->setUrl(url
); // emits urlChanged, which we forward
470 m_viewAccessor
.prepareUrlChange(url
);
471 applyViewProperties();
474 // When changing the URL there is no need to keep the version
475 // data of the previous URL.
476 m_viewAccessor
.dirModel()->clearVersionData();
478 emit
startedPathLoading(url
);
481 void DolphinView::setNameFilter(const QString
& nameFilter
)
483 m_controller
->setNameFilter(nameFilter
);
486 void DolphinView::calculateItemCount(int& fileCount
,
488 KIO::filesize_t
& totalFileSize
) const
490 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
495 totalFileSize
+= item
.size();
500 QString
DolphinView::statusBarText() const
505 KIO::filesize_t totalFileSize
= 0;
507 if (hasSelection()) {
508 // give a summary of the status of the selected files
509 const KFileItemList list
= selectedItems();
510 if (list
.isEmpty()) {
511 // when an item is triggered, it is temporary selected but selectedItems()
512 // will return an empty list
516 KFileItemList::const_iterator it
= list
.begin();
517 const KFileItemList::const_iterator end
= list
.end();
519 const KFileItem
& item
= *it
;
524 totalFileSize
+= item
.size();
529 if (folderCount
+ fileCount
== 1) {
530 // if only one item is selected, show the filename
531 const QString name
= list
.first().name();
532 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
533 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
534 name
, KIO::convertSize(totalFileSize
));
536 // at least 2 items are selected
537 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
538 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
539 if ((folderCount
> 0) && (fileCount
> 0)) {
540 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
541 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
542 } else if (fileCount
> 0) {
543 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
545 Q_ASSERT(folderCount
> 0);
550 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
551 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
552 fileCount
, folderCount
,
553 totalFileSize
, true);
559 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
561 return m_controller
->versionControlActions(items
);
564 void DolphinView::setUrl(const KUrl
& url
)
566 m_newFileNames
.clear();
567 updateView(url
, KUrl());
570 void DolphinView::selectAll()
572 QAbstractItemView
* view
= m_viewAccessor
.itemView();
573 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
574 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
575 // selection instead of selecting all items. This is bypassed for KDE 4.0
576 // by invoking clearSelection() first.
577 view
->clearSelection();
581 void DolphinView::invertSelection()
583 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
584 const QAbstractItemModel
* itemModel
= selectionModel
->model();
586 const QModelIndex topLeft
= itemModel
->index(0, 0);
587 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
588 itemModel
->columnCount() - 1);
590 const QItemSelection
selection(topLeft
, bottomRight
);
591 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
594 void DolphinView::clearSelection()
596 QItemSelectionModel
* selModel
= m_viewAccessor
.itemView()->selectionModel();
597 const QModelIndex currentIndex
= selModel
->currentIndex();
598 selModel
->setCurrentIndex(currentIndex
, QItemSelectionModel::Current
|
599 QItemSelectionModel::Clear
);
600 m_selectedItems
.clear();
603 void DolphinView::changeSelection(const KFileItemList
& selection
)
606 if (selection
.isEmpty()) {
609 const KUrl
& baseUrl
= url();
611 QItemSelection newSelection
;
612 foreach(const KFileItem
& item
, selection
) {
613 url
= item
.url().upUrl();
614 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
615 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
616 newSelection
.select(index
, index
);
619 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
620 QItemSelectionModel::ClearAndSelect
621 | QItemSelectionModel::Current
);
624 void DolphinView::renameSelectedItems()
626 KFileItemList items
= selectedItems();
627 const int itemCount
= items
.count();
633 // More than one item has been selected for renaming. Open
634 // a rename dialog and rename all items afterwards.
635 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
636 if (dialog
->exec() == QDialog::Rejected
) {
641 const QString newName
= dialog
->newName();
642 if (newName
.isEmpty()) {
643 emit
errorMessage(dialog
->errorString());
649 // the selection would be invalid after renaming the items, so just clear
653 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
654 // as one operation instead of n rename operations like it is done now...
655 Q_ASSERT(newName
.contains('#'));
657 // currently the items are sorted by the selection order, resort
658 // them by the file name
659 qSort(items
.begin(), items
.end(), lessThan
);
661 // iterate through all selected items and rename them...
663 foreach (const KFileItem
& item
, items
) {
664 const KUrl
& oldUrl
= item
.url();
666 number
.setNum(index
++);
668 QString name
= newName
;
669 name
.replace('#', number
);
671 if (oldUrl
.fileName() != name
) {
672 KUrl newUrl
= oldUrl
;
673 newUrl
.setFileName(name
);
674 KonqOperations::rename(this, oldUrl
, newUrl
);
677 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
678 Q_ASSERT(itemCount
== 1);
679 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
680 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
681 m_viewAccessor
.itemView()->edit(proxyIndex
);
683 Q_ASSERT(itemCount
== 1);
685 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
686 if (dialog
->exec() == QDialog::Rejected
) {
691 const QString newName
= dialog
->newName();
692 if (newName
.isEmpty()) {
693 emit
errorMessage(dialog
->errorString());
699 const KUrl
& oldUrl
= items
.first().url();
700 KUrl newUrl
= oldUrl
;
701 newUrl
.setFileName(newName
);
702 KonqOperations::rename(this, oldUrl
, newUrl
);
705 // assure that the current index remains visible when KDirLister
706 // will notify the view about changed items
707 m_assureVisibleCurrentIndex
= true;
710 void DolphinView::trashSelectedItems()
712 const KUrl::List list
= simplifiedSelectedUrls();
713 KonqOperations::del(this, KonqOperations::TRASH
, list
);
716 void DolphinView::deleteSelectedItems()
718 const KUrl::List list
= simplifiedSelectedUrls();
719 const bool del
= KonqOperations::askDeleteConfirmation(list
,
721 KonqOperations::DEFAULT_CONFIRMATION
,
725 KIO::Job
* job
= KIO::del(list
);
726 connect(job
, SIGNAL(result(KJob
*)),
727 this, SLOT(slotDeleteFileFinished(KJob
*)));
731 void DolphinView::cutSelectedItems()
733 QMimeData
* mimeData
= selectionMimeData();
734 KonqMimeData::addIsCutSelection(mimeData
, true);
735 QApplication::clipboard()->setMimeData(mimeData
);
738 void DolphinView::copySelectedItems()
740 QMimeData
* mimeData
= selectionMimeData();
741 QApplication::clipboard()->setMimeData(mimeData
);
744 void DolphinView::paste()
749 void DolphinView::pasteIntoFolder()
751 const KFileItemList items
= selectedItems();
752 if ((items
.count() == 1) && items
.first().isDir()) {
753 pasteToUrl(items
.first().url());
757 void DolphinView::setShowPreview(bool show
)
759 if (m_showPreview
== show
) {
763 const KUrl viewPropsUrl
= rootUrl();
764 ViewProperties
props(viewPropsUrl
);
765 props
.setShowPreview(show
);
767 m_showPreview
= show
;
768 const int oldZoomLevel
= m_controller
->zoomLevel();
769 emit
showPreviewChanged();
771 // Enabling or disabling the preview might change the icon size of the view.
772 // As the view does not emit a signal when the icon size has been changed,
773 // the used zoom level of the controller must be adjusted manually:
774 updateZoomLevel(oldZoomLevel
);
777 void DolphinView::setShowHiddenFiles(bool show
)
779 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
783 const KUrl viewPropsUrl
= rootUrl();
784 ViewProperties
props(viewPropsUrl
);
785 props
.setShowHiddenFiles(show
);
787 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
788 emit
showHiddenFilesChanged();
791 void DolphinView::setCategorizedSorting(bool categorized
)
793 if (categorized
== categorizedSorting()) {
797 // setCategorizedSorting(true) may only get invoked
798 // if the view supports categorized sorting
799 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
801 ViewProperties
props(rootUrl());
802 props
.setCategorizedSorting(categorized
);
805 m_storedCategorizedSorting
= categorized
;
806 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
808 emit
categorizedSortingChanged();
811 void DolphinView::toggleSortOrder()
813 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
814 Qt::DescendingOrder
:
819 void DolphinView::toggleSortFoldersFirst()
821 setSortFoldersFirst(!sortFoldersFirst());
824 void DolphinView::toggleAdditionalInfo(QAction
* action
)
826 const KFileItemDelegate::Information info
=
827 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
829 KFileItemDelegate::InformationList list
= additionalInfo();
831 const bool show
= action
->isChecked();
833 const int index
= list
.indexOf(info
);
834 const bool containsInfo
= (index
>= 0);
835 if (show
&& !containsInfo
) {
837 setAdditionalInfo(list
);
838 } else if (!show
&& containsInfo
) {
839 list
.removeAt(index
);
840 setAdditionalInfo(list
);
841 Q_ASSERT(list
.indexOf(info
) < 0);
845 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
847 QWidget::mouseReleaseEvent(event
);
851 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
853 switch (event
->type()) {
854 case QEvent::FocusIn
:
855 if (watched
== m_viewAccessor
.itemView()) {
856 m_controller
->requestActivation();
860 case QEvent::DragEnter
:
861 if (watched
== m_viewAccessor
.itemView()->viewport()) {
866 case QEvent::KeyPress
:
867 if (watched
== m_viewAccessor
.itemView()) {
868 // clear the selection when Escape has been pressed
869 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
870 if (keyEvent
->key() == Qt::Key_Escape
) {
877 if (watched
== m_viewAccessor
.itemView()->viewport()) {
878 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
879 // (the user is probably trying to scroll during a selection in that case)
880 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
881 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
882 const int delta
= wheelEvent
->delta();
883 const int level
= zoomLevel();
885 setZoomLevel(level
+ 1);
886 } else if (delta
< 0) {
887 setZoomLevel(level
- 1);
898 return QWidget::eventFilter(watched
, event
);
901 void DolphinView::activate()
906 void DolphinView::triggerItem(const KFileItem
& item
)
908 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
909 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
910 // items are selected by the user, hence don't trigger the
911 // item specified by 'index'
915 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
916 if (item
.isNull() || m_isContextMenuOpen
) {
920 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
923 void DolphinView::emitDelayedSelectionChangedSignal()
925 // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
926 // that fast selection changes don't result in expensive operations to
927 // collect all file items for the signal (see DolphinView::selectedItems()).
928 m_selectionChangedTimer
->start();
931 void DolphinView::emitSelectionChangedSignal()
933 emit
selectionChanged(DolphinView::selectedItems());
936 void DolphinView::openContextMenu(const QPoint
& pos
,
937 const QList
<QAction
*>& customActions
)
940 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
941 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
942 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
943 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
946 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
947 emit
requestContextMenu(item
, url(), customActions
);
948 m_isContextMenuOpen
= false;
951 void DolphinView::dropUrls(const KFileItem
& destItem
,
952 const KUrl
& destPath
,
955 addNewFileNames(event
->mimeData());
956 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
959 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
961 ViewProperties
props(rootUrl());
962 props
.setSorting(sorting
);
964 m_viewAccessor
.proxyModel()->setSorting(sorting
);
966 emit
sortingChanged(sorting
);
969 void DolphinView::updateSortOrder(Qt::SortOrder order
)
971 ViewProperties
props(rootUrl());
972 props
.setSortOrder(order
);
974 m_viewAccessor
.proxyModel()->setSortOrder(order
);
976 emit
sortOrderChanged(order
);
979 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
981 ViewProperties
props(rootUrl());
982 props
.setSortFoldersFirst(foldersFirst
);
984 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
986 emit
sortFoldersFirstChanged(foldersFirst
);
989 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
991 ViewProperties
props(rootUrl());
992 props
.setAdditionalInfo(info
);
995 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
997 emit
additionalInfoChanged();
1000 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
1002 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
1003 (m_mode
== DolphinView::IconsView
);
1005 QAction
* showSizeInfo
= collection
->action("show_size_info");
1006 QAction
* showDateInfo
= collection
->action("show_date_info");
1007 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
1008 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
1009 QAction
* showGroupInfo
= collection
->action("show_group_info");
1010 QAction
* showMimeInfo
= collection
->action("show_mime_info");
1012 showSizeInfo
->setChecked(false);
1013 showDateInfo
->setChecked(false);
1014 showPermissionsInfo
->setChecked(false);
1015 showOwnerInfo
->setChecked(false);
1016 showGroupInfo
->setChecked(false);
1017 showMimeInfo
->setChecked(false);
1019 showSizeInfo
->setEnabled(enable
);
1020 showDateInfo
->setEnabled(enable
);
1021 showPermissionsInfo
->setEnabled(enable
);
1022 showOwnerInfo
->setEnabled(enable
);
1023 showGroupInfo
->setEnabled(enable
);
1024 showMimeInfo
->setEnabled(enable
);
1026 foreach (KFileItemDelegate::Information info
, m_viewAccessor
.itemDelegate()->showInformation()) {
1028 case KFileItemDelegate::Size
:
1029 showSizeInfo
->setChecked(true);
1031 case KFileItemDelegate::ModificationTime
:
1032 showDateInfo
->setChecked(true);
1034 case KFileItemDelegate::Permissions
:
1035 showPermissionsInfo
->setChecked(true);
1037 case KFileItemDelegate::Owner
:
1038 showOwnerInfo
->setChecked(true);
1040 case KFileItemDelegate::OwnerAndGroup
:
1041 showGroupInfo
->setChecked(true);
1043 case KFileItemDelegate::FriendlyMimeType
:
1044 showMimeInfo
->setChecked(true);
1052 QPair
<bool, QString
> DolphinView::pasteInfo() const
1054 return KonqOperations::pasteInfo(url());
1057 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1059 m_tabsForFiles
= tabsForFiles
;
1062 bool DolphinView::isTabsForFilesEnabled() const
1064 return m_tabsForFiles
;
1067 void DolphinView::activateItem(const KUrl
& url
)
1069 // TODO: If DolphinViewContainer uses DolphinView::restoreState(...) to restore the
1070 // view state in KDE 4.5, this function can be removed.
1071 m_activeItemUrl
= url
;
1074 bool DolphinView::itemsExpandable() const
1076 return m_viewAccessor
.itemsExpandable();
1079 void DolphinView::restoreState(QDataStream
&stream
)
1082 stream
>> m_activeItemUrl
;
1085 stream
>> m_restoredContentsPosition
;
1087 // expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1088 QSet
<KUrl
> urlsToExpand
;
1089 stream
>> urlsToExpand
;
1090 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
1093 m_expanderActive
= true;
1094 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
1097 m_expanderActive
= false;
1101 void DolphinView::saveState(QDataStream
&stream
)
1104 KFileItem currentItem
;
1105 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1108 const QModelIndex proxyIndex
= view
->currentIndex();
1109 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1110 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
1114 if (!currentItem
.isNull())
1115 currentUrl
= currentItem
.url();
1117 stream
<< currentUrl
;
1120 stream
<< contentsPosition();
1122 // expanded folders (only relevant for the details view - the set will be empty in other view modes)
1123 stream
<< m_viewAccessor
.expandedUrls();
1126 void DolphinView::observeCreatedItem(const KUrl
& url
)
1128 m_createdItemUrl
= url
;
1129 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1130 this, SLOT(selectAndScrollToCreatedItem()));
1133 void DolphinView::selectAndScrollToCreatedItem()
1135 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
1136 if (dirIndex
.isValid()) {
1137 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1138 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
1141 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1142 this, SLOT(selectAndScrollToCreatedItem()));
1143 m_createdItemUrl
= KUrl();
1146 void DolphinView::restoreSelection()
1148 disconnect(m_viewAccessor
.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
1149 changeSelection(m_selectedItems
);
1152 void DolphinView::emitContentsMoved()
1154 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
1155 // view state in KDE 4.5, the contentsMoved signal might not be needed anymore,
1156 // depending on how the implementation is done.
1157 // In that case, the code in contentsPosition() can be moved to saveState().
1159 // only emit the contents moved signal if no directory loading is ongoing
1160 // (this would reset the contents position always to (0, 0))
1161 if (!m_loadingDirectory
) {
1162 const QPoint
pos(contentsPosition());
1163 emit
contentsMoved(pos
.x(), pos
.y());
1167 void DolphinView::showHoverInformation(const KFileItem
& item
)
1169 emit
requestItemInfo(item
);
1172 void DolphinView::clearHoverInformation()
1174 emit
requestItemInfo(KFileItem());
1177 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1179 if (job
->error() == 0) {
1180 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1181 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1182 emit
errorMessage(job
->errorString());
1186 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1188 emit
requestUrlChange(url
);
1189 m_controller
->setUrl(url
);
1192 void DolphinView::slotDirListerCompleted()
1194 if (!m_expanderActive
) {
1195 slotLoadingCompleted();
1198 if (!m_newFileNames
.isEmpty()) {
1199 // select all newly added items created by a paste operation or
1200 // a drag & drop operation
1201 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1202 QItemSelection selection
;
1203 for (int row
= 0; row
< rowCount
; ++row
) {
1204 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1205 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1206 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1207 if (m_newFileNames
.contains(url
.fileName())) {
1208 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1211 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1213 m_newFileNames
.clear();
1217 void DolphinView::slotLoadingCompleted()
1219 m_expanderActive
= false;
1220 m_loadingDirectory
= false;
1222 if (!m_activeItemUrl
.isEmpty()) {
1223 // assure that the current item remains visible
1224 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1225 if (dirIndex
.isValid()) {
1226 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1227 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1228 const bool clearSelection
= !hasSelection();
1229 view
->setCurrentIndex(proxyIndex
);
1230 if (clearSelection
) {
1231 view
->clearSelection();
1233 m_activeItemUrl
.clear();
1237 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1238 // because the view might not be in its final state yet.
1239 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1242 void DolphinView::slotRefreshItems()
1244 if (m_assureVisibleCurrentIndex
) {
1245 m_assureVisibleCurrentIndex
= false;
1246 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1250 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1252 if (!url
.isValid()) {
1253 const QString
location(url
.pathOrUrl());
1254 if (location
.isEmpty()) {
1255 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1257 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1262 m_loadingDirectory
= true;
1263 m_expanderActive
= false;
1266 m_selectedItems
= selectedItems();
1267 connect(m_viewAccessor
.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
1270 m_viewAccessor
.dirLister()->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1273 void DolphinView::applyViewProperties()
1275 if (m_ignoreViewProperties
) {
1279 const ViewProperties
props(rootUrl());
1281 const Mode mode
= props
.viewMode();
1282 if (m_mode
!= mode
) {
1283 const int oldZoomLevel
= m_controller
->zoomLevel();
1289 updateZoomLevel(oldZoomLevel
);
1291 if (m_viewAccessor
.itemView() == 0) {
1294 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1295 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1297 const bool showHiddenFiles
= props
.showHiddenFiles();
1298 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1299 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1300 emit
showHiddenFilesChanged();
1303 m_storedCategorizedSorting
= props
.categorizedSorting();
1304 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1305 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1306 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1307 emit
categorizedSortingChanged();
1310 const DolphinView::Sorting sorting
= props
.sorting();
1311 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1312 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1313 emit
sortingChanged(sorting
);
1316 const Qt::SortOrder sortOrder
= props
.sortOrder();
1317 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1318 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1319 emit
sortOrderChanged(sortOrder
);
1322 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1323 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1324 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1325 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1328 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1329 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1330 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1331 emit
additionalInfoChanged();
1334 const bool showPreview
= props
.showPreview();
1335 if (showPreview
!= m_showPreview
) {
1336 m_showPreview
= showPreview
;
1337 const int oldZoomLevel
= m_controller
->zoomLevel();
1338 emit
showPreviewChanged();
1340 // Enabling or disabling the preview might change the icon size of the view.
1341 // As the view does not emit a signal when the icon size has been changed,
1342 // the used zoom level of the controller must be adjusted manually:
1343 updateZoomLevel(oldZoomLevel
);
1346 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1347 // During the lifetime of a DolphinView instance the global view properties
1348 // should not be changed. This allows e. g. to split a view and use different
1349 // view properties for each view.
1350 m_ignoreViewProperties
= true;
1354 void DolphinView::createView()
1358 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1359 m_viewAccessor
.createView(this, m_controller
, m_mode
);
1361 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1362 Q_ASSERT(view
!= 0);
1363 view
->installEventFilter(this);
1364 view
->viewport()->installEventFilter(this);
1366 m_controller
->setItemView(view
);
1367 connect(m_controller
, SIGNAL(selectionChanged()),
1368 this, SLOT(emitDelayedSelectionChangedSignal()));
1370 // When changing the view mode, the selection is lost due to reinstantiating
1371 // a new item view with a custom selection model. Pass the ownership of the
1372 // selection model to DolphinView, so that it can be shared by all item views.
1373 if (m_selectionModel
!= 0) {
1374 view
->setSelectionModel(m_selectionModel
);
1376 m_selectionModel
= view
->selectionModel();
1378 m_selectionModel
->setParent(this);
1380 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1381 this, SLOT(emitContentsMoved()));
1382 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1383 this, SLOT(emitContentsMoved()));
1385 setFocusProxy(m_viewAccessor
.layoutTarget());
1386 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1389 void DolphinView::deleteView()
1391 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1393 // It's important to set the keyboard focus to the parent
1394 // before deleting the view: Otherwise when having a split
1395 // view the other view will get the focus and will request
1396 // an activation (see DolphinView::eventFilter()).
1400 m_topLayout
->removeWidget(view
);
1403 // disconnect all signal/slots
1405 m_controller
->disconnect(view
);
1407 disconnect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1408 this, SLOT(emitContentsMoved()));
1409 disconnect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1410 this, SLOT(emitContentsMoved()));
1412 m_viewAccessor
.deleteView();
1416 void DolphinView::pasteToUrl(const KUrl
& url
)
1418 addNewFileNames(QApplication::clipboard()->mimeData());
1419 KonqOperations::doPaste(this, url
);
1422 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1424 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1425 if (oldZoomLevel
!= newZoomLevel
) {
1426 m_controller
->setZoomLevel(newZoomLevel
);
1427 emit
zoomLevelChanged(newZoomLevel
);
1431 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1433 KUrl::List list
= selectedUrls();
1434 if (itemsExpandable() ) {
1435 list
= KDirModel::simplifiedUrlList(list
);
1440 QMimeData
* DolphinView::selectionMimeData() const
1442 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1443 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1444 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1445 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1448 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1450 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1451 foreach (const KUrl
& url
, urls
) {
1452 m_newFileNames
.insert(url
.fileName());
1456 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1459 m_columnsContainer(0),
1460 m_proxyModel(proxyModel
),
1465 DolphinView::ViewAccessor::~ViewAccessor()
1467 delete m_dragSource
;
1471 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1472 DolphinController
* controller
,
1475 Q_ASSERT(itemView() == 0);
1479 m_iconsView
= new DolphinIconsView(parent
, controller
, m_proxyModel
);
1483 m_detailsView
= new DolphinDetailsView(parent
, controller
, m_proxyModel
);
1487 m_columnsContainer
= new DolphinColumnViewContainer(parent
, controller
);
1495 void DolphinView::ViewAccessor::deleteView()
1497 QAbstractItemView
* view
= itemView();
1499 if (DragAndDropHelper::instance().isDragSource(view
)) {
1500 // The view is a drag source (the feature "Open folders
1501 // during drag operations" is used). Deleting the view
1502 // during an ongoing drag operation is not allowed, so
1503 // this will postponed.
1504 if (m_dragSource
!= 0) {
1505 // the old stored view is obviously not the drag source anymore
1506 m_dragSource
->deleteLater();
1510 m_dragSource
= view
;
1512 view
->deleteLater();
1519 if (m_columnsContainer
!= 0) {
1520 m_columnsContainer
->deleteLater();
1522 m_columnsContainer
= 0;
1526 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1528 if (m_columnsContainer
!= 0) {
1529 m_columnsContainer
->showColumn(url
);
1532 if(!m_detailsViewExpander
.isNull()) {
1533 // Stop expanding items in the current folder
1534 m_detailsViewExpander
->stop();
1538 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1540 if (m_iconsView
!= 0) {
1544 if (m_detailsView
!= 0) {
1545 return m_detailsView
;
1548 if (m_columnsContainer
!= 0) {
1549 return m_columnsContainer
->activeColumn();
1555 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1557 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1560 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1562 if (m_columnsContainer
!= 0) {
1563 return m_columnsContainer
;
1568 KUrl
DolphinView::ViewAccessor::rootUrl() const
1570 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : KUrl();
1573 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1575 return m_iconsView
!= 0;
1578 bool DolphinView::ViewAccessor::itemsExpandable() const
1580 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1584 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1586 if(m_detailsView
!= 0) {
1587 return m_detailsView
->expandedUrls();
1590 return QSet
<KUrl
>();
1594 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1596 if((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1597 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1598 return m_detailsViewExpander
;
1605 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1607 // the details view requires no reloading of the directory, as it maps
1608 // the file item delegate info to its columns internally
1609 return m_detailsView
!= 0;
1612 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1614 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1617 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1619 if (m_columnsContainer
!= 0) {
1620 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1622 return m_proxyModel
;
1625 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1627 return dirModel()->dirLister();
1630 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1632 emit
redirection(oldUrl
, newUrl
);
1633 m_controller
->redirectToUrl(newUrl
); // #186947
1636 void DolphinView::restoreContentsPosition()
1638 if (!m_restoredContentsPosition
.isNull()) {
1639 setContentsPosition(m_restoredContentsPosition
.x(), m_restoredContentsPosition
.y());
1640 m_restoredContentsPosition
= QPoint();
1644 #include "dolphinview.moc"