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();
225 // remember the currently selected items, so that they will
226 // be restored after reloading the directory
227 m_selectedItems
= selectedItems();
231 const KUrl viewPropsUrl
= rootUrl();
232 ViewProperties
props(viewPropsUrl
);
233 props
.setViewMode(m_mode
);
236 // the file item delegate has been recreated, apply the current
237 // additional information manually
238 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
239 m_viewAccessor
.itemDelegate()->setShowInformation(infoList
);
240 emit
additionalInfoChanged();
242 // Not all view modes support categorized sorting. Adjust the sorting model
243 // if changing the view mode results in a change of the categorized sorting
245 m_storedCategorizedSorting
= props
.categorizedSorting();
246 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
247 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
248 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
249 emit
categorizedSortingChanged();
254 updateZoomLevel(oldZoomLevel
);
255 loadDirectory(viewPropsUrl
);
258 DolphinView::Mode
DolphinView::mode() const
263 bool DolphinView::showPreview() const
265 return m_showPreview
;
268 bool DolphinView::showHiddenFiles() const
270 return m_viewAccessor
.dirLister()->showingDotFiles();
273 bool DolphinView::categorizedSorting() const
275 // If all view modes would support categorized sorting, returning
276 // m_viewAccessor.proxyModel()->isCategorizedModel() would be the way to go. As
277 // currently only the icons view supports caterized sorting, we remember
278 // the stored view properties state in m_storedCategorizedSorting and
279 // return this state. The application takes care to disable the corresponding
280 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
281 // that this setting is not applied to the current view mode.
282 return m_storedCategorizedSorting
;
285 bool DolphinView::supportsCategorizedSorting() const
287 return m_viewAccessor
.supportsCategorizedSorting();
290 bool DolphinView::hasSelection() const
292 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
293 return view
&& view
->selectionModel()->hasSelection();
296 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
298 foreach (const KUrl
& url
, urls
) {
299 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
300 m_selectedItems
.append(item
);
304 KFileItemList
DolphinView::selectedItems() const
306 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
308 // Our view has a selection, we will map them back to the DolphinModel
309 // and then fill the KFileItemList.
310 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
312 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
313 KFileItemList itemList
;
315 const QModelIndexList indexList
= selection
.indexes();
316 foreach (const QModelIndex
&index
, indexList
) {
317 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
318 if (!item
.isNull()) {
319 itemList
.append(item
);
326 KUrl::List
DolphinView::selectedUrls() const
329 const KFileItemList list
= selectedItems();
330 foreach (const KFileItem
&item
, list
) {
331 urls
.append(item
.url());
336 int DolphinView::selectedItemsCount() const
338 return m_viewAccessor
.itemView()->selectionModel()->selectedIndexes().count();
341 QItemSelectionModel
* DolphinView::selectionModel() const
343 return m_viewAccessor
.itemView()->selectionModel();
346 void DolphinView::setContentsPosition(int x
, int y
)
348 QAbstractItemView
* view
= m_viewAccessor
.itemView();
350 view
->horizontalScrollBar()->setValue(x
);
351 view
->verticalScrollBar()->setValue(y
);
353 m_loadingDirectory
= false;
356 void DolphinView::setRestoredContentsPosition(const QPoint
& pos
)
358 // TODO: This function is called by DolphinViewContainer.
359 // If it makes use of DolphinView::restoreState(...) to restore the
360 // view state in KDE 4.5, this function can be removed.
361 m_restoredContentsPosition
= pos
;
364 QPoint
DolphinView::contentsPosition() const
366 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
367 // view state in KDE 4.5, this code can be moved to DolphinView::saveState.
368 QAbstractItemView
* view
= m_viewAccessor
.itemView();
370 const int x
= view
->horizontalScrollBar()->value();
371 const int y
= view
->verticalScrollBar()->value();
375 void DolphinView::setZoomLevel(int level
)
377 if (level
< ZoomLevelInfo::minimumLevel()) {
378 level
= ZoomLevelInfo::minimumLevel();
379 } else if (level
> ZoomLevelInfo::maximumLevel()) {
380 level
= ZoomLevelInfo::maximumLevel();
383 if (level
!= zoomLevel()) {
384 m_controller
->setZoomLevel(level
);
385 emit
zoomLevelChanged(level
);
389 int DolphinView::zoomLevel() const
391 return m_controller
->zoomLevel();
394 void DolphinView::setSorting(Sorting sorting
)
396 if (sorting
!= this->sorting()) {
397 updateSorting(sorting
);
401 DolphinView::Sorting
DolphinView::sorting() const
403 return m_viewAccessor
.proxyModel()->sorting();
406 void DolphinView::setSortOrder(Qt::SortOrder order
)
408 if (sortOrder() != order
) {
409 updateSortOrder(order
);
413 Qt::SortOrder
DolphinView::sortOrder() const
415 return m_viewAccessor
.proxyModel()->sortOrder();
418 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
420 if (sortFoldersFirst() != foldersFirst
) {
421 updateSortFoldersFirst(foldersFirst
);
425 bool DolphinView::sortFoldersFirst() const
427 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
430 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
432 const KUrl viewPropsUrl
= rootUrl();
433 ViewProperties
props(viewPropsUrl
);
434 props
.setAdditionalInfo(info
);
435 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
437 emit
additionalInfoChanged();
439 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
440 loadDirectory(viewPropsUrl
);
444 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
446 return m_viewAccessor
.itemDelegate()->showInformation();
449 void DolphinView::reload()
451 QByteArray viewState
;
452 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
453 saveState(saveStream
);
454 m_selectedItems
= selectedItems();
457 loadDirectory(url(), true);
459 QDataStream
restoreStream(viewState
);
460 restoreState(restoreStream
);
463 void DolphinView::refresh()
465 m_ignoreViewProperties
= false;
467 const bool oldActivationState
= m_active
;
468 const int oldZoomLevel
= m_controller
->zoomLevel();
472 applyViewProperties();
475 setActive(oldActivationState
);
476 updateZoomLevel(oldZoomLevel
);
479 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
481 Q_UNUSED(rootUrl
); // TODO: remove after columnview-cleanup has been finished
483 if (m_controller
->url() == url
) {
487 m_controller
->setUrl(url
); // emits urlChanged, which we forward
488 m_viewAccessor
.prepareUrlChange(url
);
489 applyViewProperties();
492 // When changing the URL there is no need to keep the version
493 // data of the previous URL.
494 m_viewAccessor
.dirModel()->clearVersionData();
496 emit
startedPathLoading(url
);
499 void DolphinView::setNameFilter(const QString
& nameFilter
)
501 m_controller
->setNameFilter(nameFilter
);
504 void DolphinView::calculateItemCount(int& fileCount
,
506 KIO::filesize_t
& totalFileSize
) const
508 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
513 totalFileSize
+= item
.size();
518 QString
DolphinView::statusBarText() const
523 KIO::filesize_t totalFileSize
= 0;
525 if (hasSelection()) {
526 // give a summary of the status of the selected files
527 const KFileItemList list
= selectedItems();
528 if (list
.isEmpty()) {
529 // when an item is triggered, it is temporary selected but selectedItems()
530 // will return an empty list
534 KFileItemList::const_iterator it
= list
.begin();
535 const KFileItemList::const_iterator end
= list
.end();
537 const KFileItem
& item
= *it
;
542 totalFileSize
+= item
.size();
547 if (folderCount
+ fileCount
== 1) {
548 // if only one item is selected, show the filename
549 const QString name
= list
.first().name();
550 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
551 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
552 name
, KIO::convertSize(totalFileSize
));
554 // at least 2 items are selected
555 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
556 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
557 if ((folderCount
> 0) && (fileCount
> 0)) {
558 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
559 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
560 } else if (fileCount
> 0) {
561 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
563 Q_ASSERT(folderCount
> 0);
568 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
569 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
570 fileCount
, folderCount
,
571 totalFileSize
, true);
577 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
579 return m_controller
->versionControlActions(items
);
582 void DolphinView::setUrl(const KUrl
& url
)
584 m_newFileNames
.clear();
585 updateView(url
, KUrl());
588 void DolphinView::selectAll()
590 m_viewAccessor
.itemView()->selectAll();
593 void DolphinView::invertSelection()
595 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
596 const QAbstractItemModel
* itemModel
= selectionModel
->model();
598 const QModelIndex topLeft
= itemModel
->index(0, 0);
599 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
600 itemModel
->columnCount() - 1);
602 const QItemSelection
selection(topLeft
, bottomRight
);
603 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
606 void DolphinView::clearSelection()
608 m_viewAccessor
.itemView()->clearSelection();
611 void DolphinView::renameSelectedItems()
613 KFileItemList items
= selectedItems();
614 const int itemCount
= items
.count();
620 // More than one item has been selected for renaming. Open
621 // a rename dialog and rename all items afterwards.
622 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
623 if (dialog
->exec() == QDialog::Rejected
) {
628 const QString newName
= dialog
->newName();
629 if (newName
.isEmpty()) {
630 emit
errorMessage(dialog
->errorString());
636 // the selection would be invalid after renaming the items, so just clear
640 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
641 // as one operation instead of n rename operations like it is done now...
642 Q_ASSERT(newName
.contains('#'));
644 // currently the items are sorted by the selection order, resort
645 // them by the file name
646 qSort(items
.begin(), items
.end(), lessThan
);
648 // iterate through all selected items and rename them...
650 foreach (const KFileItem
& item
, items
) {
651 const KUrl
& oldUrl
= item
.url();
653 number
.setNum(index
++);
655 QString name
= newName
;
656 name
.replace('#', number
);
658 if (oldUrl
.fileName() != name
) {
659 KUrl newUrl
= oldUrl
;
660 newUrl
.setFileName(name
);
661 KonqOperations::rename(this, oldUrl
, newUrl
);
664 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
665 Q_ASSERT(itemCount
== 1);
666 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
667 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
668 m_viewAccessor
.itemView()->edit(proxyIndex
);
670 Q_ASSERT(itemCount
== 1);
672 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
673 if (dialog
->exec() == QDialog::Rejected
) {
678 const QString newName
= dialog
->newName();
679 if (newName
.isEmpty()) {
680 emit
errorMessage(dialog
->errorString());
686 const KUrl
& oldUrl
= items
.first().url();
687 KUrl newUrl
= oldUrl
;
688 newUrl
.setFileName(newName
);
689 KonqOperations::rename(this, oldUrl
, newUrl
);
692 // assure that the current index remains visible when KDirLister
693 // will notify the view about changed items
694 m_assureVisibleCurrentIndex
= true;
697 void DolphinView::trashSelectedItems()
699 const KUrl::List list
= simplifiedSelectedUrls();
700 KonqOperations::del(this, KonqOperations::TRASH
, list
);
703 void DolphinView::deleteSelectedItems()
705 const KUrl::List list
= simplifiedSelectedUrls();
706 const bool del
= KonqOperations::askDeleteConfirmation(list
,
708 KonqOperations::DEFAULT_CONFIRMATION
,
712 KIO::Job
* job
= KIO::del(list
);
713 connect(job
, SIGNAL(result(KJob
*)),
714 this, SLOT(slotDeleteFileFinished(KJob
*)));
718 void DolphinView::cutSelectedItems()
720 QMimeData
* mimeData
= selectionMimeData();
721 KonqMimeData::addIsCutSelection(mimeData
, true);
722 QApplication::clipboard()->setMimeData(mimeData
);
725 void DolphinView::copySelectedItems()
727 QMimeData
* mimeData
= selectionMimeData();
728 QApplication::clipboard()->setMimeData(mimeData
);
731 void DolphinView::paste()
736 void DolphinView::pasteIntoFolder()
738 const KFileItemList items
= selectedItems();
739 if ((items
.count() == 1) && items
.first().isDir()) {
740 pasteToUrl(items
.first().url());
744 void DolphinView::setShowPreview(bool show
)
746 if (m_showPreview
== show
) {
750 const KUrl viewPropsUrl
= rootUrl();
751 ViewProperties
props(viewPropsUrl
);
752 props
.setShowPreview(show
);
754 m_showPreview
= show
;
755 const int oldZoomLevel
= m_controller
->zoomLevel();
756 emit
showPreviewChanged();
758 // Enabling or disabling the preview might change the icon size of the view.
759 // As the view does not emit a signal when the icon size has been changed,
760 // the used zoom level of the controller must be adjusted manually:
761 updateZoomLevel(oldZoomLevel
);
764 void DolphinView::setShowHiddenFiles(bool show
)
766 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
770 const KUrl viewPropsUrl
= rootUrl();
771 ViewProperties
props(viewPropsUrl
);
772 props
.setShowHiddenFiles(show
);
774 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
775 emit
showHiddenFilesChanged();
778 void DolphinView::setCategorizedSorting(bool categorized
)
780 if (categorized
== categorizedSorting()) {
784 // setCategorizedSorting(true) may only get invoked
785 // if the view supports categorized sorting
786 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
788 ViewProperties
props(rootUrl());
789 props
.setCategorizedSorting(categorized
);
792 m_storedCategorizedSorting
= categorized
;
793 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
795 emit
categorizedSortingChanged();
798 void DolphinView::toggleSortOrder()
800 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
801 Qt::DescendingOrder
:
806 void DolphinView::toggleSortFoldersFirst()
808 setSortFoldersFirst(!sortFoldersFirst());
811 void DolphinView::toggleAdditionalInfo(QAction
* action
)
813 const KFileItemDelegate::Information info
=
814 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
816 KFileItemDelegate::InformationList list
= additionalInfo();
818 const bool show
= action
->isChecked();
820 const int index
= list
.indexOf(info
);
821 const bool containsInfo
= (index
>= 0);
822 if (show
&& !containsInfo
) {
824 setAdditionalInfo(list
);
825 } else if (!show
&& containsInfo
) {
826 list
.removeAt(index
);
827 setAdditionalInfo(list
);
828 Q_ASSERT(list
.indexOf(info
) < 0);
832 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
834 QWidget::mouseReleaseEvent(event
);
838 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
840 switch (event
->type()) {
841 case QEvent::FocusIn
:
842 if (watched
== m_viewAccessor
.itemView()) {
843 m_controller
->requestActivation();
847 case QEvent::DragEnter
:
848 if (watched
== m_viewAccessor
.itemView()->viewport()) {
853 case QEvent::KeyPress
:
854 if (watched
== m_viewAccessor
.itemView()) {
855 // clear the selection when Escape has been pressed
856 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
857 if (keyEvent
->key() == Qt::Key_Escape
) {
864 if (watched
== m_viewAccessor
.itemView()->viewport()) {
865 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
866 // (the user is probably trying to scroll during a selection in that case)
867 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
868 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
869 const int delta
= wheelEvent
->delta();
870 const int level
= zoomLevel();
872 setZoomLevel(level
+ 1);
873 } else if (delta
< 0) {
874 setZoomLevel(level
- 1);
885 return QWidget::eventFilter(watched
, event
);
888 void DolphinView::activate()
893 void DolphinView::triggerItem(const KFileItem
& item
)
895 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
896 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
897 // items are selected by the user, hence don't trigger the
898 // item specified by 'index'
902 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
903 if (item
.isNull() || m_isContextMenuOpen
) {
907 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
910 void DolphinView::emitDelayedSelectionChangedSignal()
912 // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
913 // that fast selection changes don't result in expensive operations to
914 // collect all file items for the signal (see DolphinView::selectedItems()).
915 m_selectionChangedTimer
->start();
918 void DolphinView::emitSelectionChangedSignal()
920 emit
selectionChanged(DolphinView::selectedItems());
923 void DolphinView::openContextMenu(const QPoint
& pos
,
924 const QList
<QAction
*>& customActions
)
927 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
928 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
929 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
930 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
933 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
934 emit
requestContextMenu(item
, url(), customActions
);
935 m_isContextMenuOpen
= false;
938 void DolphinView::dropUrls(const KFileItem
& destItem
,
939 const KUrl
& destPath
,
942 addNewFileNames(event
->mimeData());
943 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
946 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
948 ViewProperties
props(rootUrl());
949 props
.setSorting(sorting
);
951 m_viewAccessor
.proxyModel()->setSorting(sorting
);
953 emit
sortingChanged(sorting
);
956 void DolphinView::updateSortOrder(Qt::SortOrder order
)
958 ViewProperties
props(rootUrl());
959 props
.setSortOrder(order
);
961 m_viewAccessor
.proxyModel()->setSortOrder(order
);
963 emit
sortOrderChanged(order
);
966 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
968 ViewProperties
props(rootUrl());
969 props
.setSortFoldersFirst(foldersFirst
);
971 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
973 emit
sortFoldersFirstChanged(foldersFirst
);
976 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
978 ViewProperties
props(rootUrl());
979 props
.setAdditionalInfo(info
);
982 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
984 emit
additionalInfoChanged();
987 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
989 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
990 (m_mode
== DolphinView::IconsView
);
992 QAction
* showSizeInfo
= collection
->action("show_size_info");
993 QAction
* showDateInfo
= collection
->action("show_date_info");
994 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
995 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
996 QAction
* showGroupInfo
= collection
->action("show_group_info");
997 QAction
* showMimeInfo
= collection
->action("show_mime_info");
999 showSizeInfo
->setChecked(false);
1000 showDateInfo
->setChecked(false);
1001 showPermissionsInfo
->setChecked(false);
1002 showOwnerInfo
->setChecked(false);
1003 showGroupInfo
->setChecked(false);
1004 showMimeInfo
->setChecked(false);
1006 showSizeInfo
->setEnabled(enable
);
1007 showDateInfo
->setEnabled(enable
);
1008 showPermissionsInfo
->setEnabled(enable
);
1009 showOwnerInfo
->setEnabled(enable
);
1010 showGroupInfo
->setEnabled(enable
);
1011 showMimeInfo
->setEnabled(enable
);
1013 foreach (KFileItemDelegate::Information info
, m_viewAccessor
.itemDelegate()->showInformation()) {
1015 case KFileItemDelegate::Size
:
1016 showSizeInfo
->setChecked(true);
1018 case KFileItemDelegate::ModificationTime
:
1019 showDateInfo
->setChecked(true);
1021 case KFileItemDelegate::Permissions
:
1022 showPermissionsInfo
->setChecked(true);
1024 case KFileItemDelegate::Owner
:
1025 showOwnerInfo
->setChecked(true);
1027 case KFileItemDelegate::OwnerAndGroup
:
1028 showGroupInfo
->setChecked(true);
1030 case KFileItemDelegate::FriendlyMimeType
:
1031 showMimeInfo
->setChecked(true);
1039 QPair
<bool, QString
> DolphinView::pasteInfo() const
1041 return KonqOperations::pasteInfo(url());
1044 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1046 m_tabsForFiles
= tabsForFiles
;
1049 bool DolphinView::isTabsForFilesEnabled() const
1051 return m_tabsForFiles
;
1054 void DolphinView::activateItem(const KUrl
& url
)
1056 // TODO: If DolphinViewContainer uses DolphinView::restoreState(...) to restore the
1057 // view state in KDE 4.5, this function can be removed.
1058 m_activeItemUrl
= url
;
1061 bool DolphinView::itemsExpandable() const
1063 return m_viewAccessor
.itemsExpandable();
1066 void DolphinView::restoreState(QDataStream
&stream
)
1069 stream
>> m_activeItemUrl
;
1072 stream
>> m_restoredContentsPosition
;
1074 // expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1075 QSet
<KUrl
> urlsToExpand
;
1076 stream
>> urlsToExpand
;
1077 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
1080 m_expanderActive
= true;
1081 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
1084 m_expanderActive
= false;
1088 void DolphinView::saveState(QDataStream
&stream
)
1091 KFileItem currentItem
;
1092 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1095 const QModelIndex proxyIndex
= view
->currentIndex();
1096 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1097 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
1101 if (!currentItem
.isNull())
1102 currentUrl
= currentItem
.url();
1104 stream
<< currentUrl
;
1107 stream
<< contentsPosition();
1109 // expanded folders (only relevant for the details view - the set will be empty in other view modes)
1110 stream
<< m_viewAccessor
.expandedUrls();
1113 void DolphinView::observeCreatedItem(const KUrl
& url
)
1115 m_createdItemUrl
= url
;
1116 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1117 this, SLOT(selectAndScrollToCreatedItem()));
1120 void DolphinView::selectAndScrollToCreatedItem()
1122 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
1123 if (dirIndex
.isValid()) {
1124 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1125 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
1128 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1129 this, SLOT(selectAndScrollToCreatedItem()));
1130 m_createdItemUrl
= KUrl();
1133 void DolphinView::emitContentsMoved()
1135 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
1136 // view state in KDE 4.5, the contentsMoved signal might not be needed anymore,
1137 // depending on how the implementation is done.
1138 // In that case, the code in contentsPosition() can be moved to saveState().
1140 // only emit the contents moved signal if no directory loading is ongoing
1141 // (this would reset the contents position always to (0, 0))
1142 if (!m_loadingDirectory
) {
1143 const QPoint
pos(contentsPosition());
1144 emit
contentsMoved(pos
.x(), pos
.y());
1148 void DolphinView::showHoverInformation(const KFileItem
& item
)
1150 emit
requestItemInfo(item
);
1153 void DolphinView::clearHoverInformation()
1155 emit
requestItemInfo(KFileItem());
1158 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1160 if (job
->error() == 0) {
1161 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1162 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1163 emit
errorMessage(job
->errorString());
1167 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1169 emit
requestUrlChange(url
);
1170 m_controller
->setUrl(url
);
1173 void DolphinView::slotDirListerCompleted()
1175 if (!m_expanderActive
) {
1176 slotLoadingCompleted();
1179 if (!m_newFileNames
.isEmpty()) {
1180 // select all newly added items created by a paste operation or
1181 // a drag & drop operation
1182 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1183 QItemSelection selection
;
1184 for (int row
= 0; row
< rowCount
; ++row
) {
1185 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1186 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1187 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1188 if (m_newFileNames
.contains(url
.fileName())) {
1189 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1192 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1194 m_newFileNames
.clear();
1198 void DolphinView::slotLoadingCompleted()
1200 m_expanderActive
= false;
1201 m_loadingDirectory
= false;
1203 if (!m_activeItemUrl
.isEmpty()) {
1204 // assure that the current item remains visible
1205 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1206 if (dirIndex
.isValid()) {
1207 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1208 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1209 const bool clearSelection
= !hasSelection();
1210 view
->setCurrentIndex(proxyIndex
);
1211 if (clearSelection
) {
1212 view
->clearSelection();
1214 m_activeItemUrl
.clear();
1218 if (!m_selectedItems
.isEmpty()) {
1219 const KUrl
& baseUrl
= url();
1221 QItemSelection newSelection
;
1222 foreach(const KFileItem
& item
, m_selectedItems
) {
1223 url
= item
.url().upUrl();
1224 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
1225 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
1226 newSelection
.select(index
, index
);
1229 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
1230 QItemSelectionModel::ClearAndSelect
1231 | QItemSelectionModel::Current
);
1232 m_selectedItems
.clear();
1235 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1236 // because the view might not be in its final state yet.
1237 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1240 void DolphinView::slotRefreshItems()
1242 if (m_assureVisibleCurrentIndex
) {
1243 m_assureVisibleCurrentIndex
= false;
1244 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1248 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1250 if (!url
.isValid()) {
1251 const QString
location(url
.pathOrUrl());
1252 if (location
.isEmpty()) {
1253 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1255 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1260 m_loadingDirectory
= true;
1261 m_expanderActive
= false;
1263 m_viewAccessor
.dirLister()->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1266 void DolphinView::applyViewProperties()
1268 if (m_ignoreViewProperties
) {
1272 const ViewProperties
props(rootUrl());
1274 const Mode mode
= props
.viewMode();
1275 if (m_mode
!= mode
) {
1276 const int oldZoomLevel
= m_controller
->zoomLevel();
1282 updateZoomLevel(oldZoomLevel
);
1284 if (m_viewAccessor
.itemView() == 0) {
1287 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1288 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1290 const bool showHiddenFiles
= props
.showHiddenFiles();
1291 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1292 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1293 emit
showHiddenFilesChanged();
1296 m_storedCategorizedSorting
= props
.categorizedSorting();
1297 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1298 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1299 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1300 emit
categorizedSortingChanged();
1303 const DolphinView::Sorting sorting
= props
.sorting();
1304 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1305 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1306 emit
sortingChanged(sorting
);
1309 const Qt::SortOrder sortOrder
= props
.sortOrder();
1310 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1311 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1312 emit
sortOrderChanged(sortOrder
);
1315 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1316 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1317 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1318 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1321 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1322 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1323 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1324 emit
additionalInfoChanged();
1327 const bool showPreview
= props
.showPreview();
1328 if (showPreview
!= m_showPreview
) {
1329 m_showPreview
= showPreview
;
1330 const int oldZoomLevel
= m_controller
->zoomLevel();
1331 emit
showPreviewChanged();
1333 // Enabling or disabling the preview might change the icon size of the view.
1334 // As the view does not emit a signal when the icon size has been changed,
1335 // the used zoom level of the controller must be adjusted manually:
1336 updateZoomLevel(oldZoomLevel
);
1339 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1340 // During the lifetime of a DolphinView instance the global view properties
1341 // should not be changed. This allows e. g. to split a view and use different
1342 // view properties for each view.
1343 m_ignoreViewProperties
= true;
1347 void DolphinView::createView()
1351 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1352 m_viewAccessor
.createView(this, m_controller
, m_mode
);
1354 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1355 Q_ASSERT(view
!= 0);
1356 view
->installEventFilter(this);
1357 view
->viewport()->installEventFilter(this);
1359 m_controller
->setItemView(view
);
1360 connect(m_controller
, SIGNAL(selectionChanged()),
1361 this, SLOT(emitDelayedSelectionChangedSignal()));
1363 // When changing the view mode, the selection is lost due to reinstantiating
1364 // a new item view with a custom selection model. Pass the ownership of the
1365 // selection model to DolphinView, so that it can be shared by all item views.
1366 if (m_selectionModel
!= 0) {
1367 view
->setSelectionModel(m_selectionModel
);
1369 m_selectionModel
= view
->selectionModel();
1371 m_selectionModel
->setParent(this);
1373 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1374 this, SLOT(emitContentsMoved()));
1375 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1376 this, SLOT(emitContentsMoved()));
1378 setFocusProxy(m_viewAccessor
.layoutTarget());
1379 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1382 void DolphinView::deleteView()
1384 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1386 // It's important to set the keyboard focus to the parent
1387 // before deleting the view: Otherwise when having a split
1388 // view the other view will get the focus and will request
1389 // an activation (see DolphinView::eventFilter()).
1393 m_topLayout
->removeWidget(view
);
1396 // disconnect all signal/slots
1398 m_controller
->disconnect(view
);
1400 disconnect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1401 this, SLOT(emitContentsMoved()));
1402 disconnect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1403 this, SLOT(emitContentsMoved()));
1405 m_viewAccessor
.deleteView();
1409 void DolphinView::pasteToUrl(const KUrl
& url
)
1411 addNewFileNames(QApplication::clipboard()->mimeData());
1412 KonqOperations::doPaste(this, url
);
1415 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1417 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1418 if (oldZoomLevel
!= newZoomLevel
) {
1419 m_controller
->setZoomLevel(newZoomLevel
);
1420 emit
zoomLevelChanged(newZoomLevel
);
1424 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1426 KUrl::List list
= selectedUrls();
1427 if (itemsExpandable() ) {
1428 list
= KDirModel::simplifiedUrlList(list
);
1433 QMimeData
* DolphinView::selectionMimeData() const
1435 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1436 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1437 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1438 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1441 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1443 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1444 foreach (const KUrl
& url
, urls
) {
1445 m_newFileNames
.insert(url
.fileName());
1449 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1452 m_columnsContainer(0),
1453 m_proxyModel(proxyModel
),
1458 DolphinView::ViewAccessor::~ViewAccessor()
1460 delete m_dragSource
;
1464 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1465 DolphinController
* controller
,
1468 Q_ASSERT(itemView() == 0);
1472 m_iconsView
= new DolphinIconsView(parent
, controller
, m_proxyModel
);
1476 m_detailsView
= new DolphinDetailsView(parent
, controller
, m_proxyModel
);
1480 m_columnsContainer
= new DolphinColumnViewContainer(parent
, controller
);
1488 void DolphinView::ViewAccessor::deleteView()
1490 QAbstractItemView
* view
= itemView();
1492 if (DragAndDropHelper::instance().isDragSource(view
)) {
1493 // The view is a drag source (the feature "Open folders
1494 // during drag operations" is used). Deleting the view
1495 // during an ongoing drag operation is not allowed, so
1496 // this will postponed.
1497 if (m_dragSource
!= 0) {
1498 // the old stored view is obviously not the drag source anymore
1499 m_dragSource
->deleteLater();
1503 m_dragSource
= view
;
1505 view
->deleteLater();
1512 if (m_columnsContainer
!= 0) {
1513 m_columnsContainer
->deleteLater();
1515 m_columnsContainer
= 0;
1519 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1521 if (m_columnsContainer
!= 0) {
1522 m_columnsContainer
->showColumn(url
);
1525 if(!m_detailsViewExpander
.isNull()) {
1526 // Stop expanding items in the current folder
1527 m_detailsViewExpander
->stop();
1531 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1533 if (m_iconsView
!= 0) {
1537 if (m_detailsView
!= 0) {
1538 return m_detailsView
;
1541 if (m_columnsContainer
!= 0) {
1542 return m_columnsContainer
->activeColumn();
1548 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1550 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1553 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1555 if (m_columnsContainer
!= 0) {
1556 return m_columnsContainer
;
1561 KUrl
DolphinView::ViewAccessor::rootUrl() const
1563 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : KUrl();
1566 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1568 return m_iconsView
!= 0;
1571 bool DolphinView::ViewAccessor::itemsExpandable() const
1573 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1577 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1579 if(m_detailsView
!= 0) {
1580 return m_detailsView
->expandedUrls();
1583 return QSet
<KUrl
>();
1587 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1589 if((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1590 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1591 return m_detailsViewExpander
;
1598 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1600 // the details view requires no reloading of the directory, as it maps
1601 // the file item delegate info to its columns internally
1602 return m_detailsView
!= 0;
1605 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1607 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1610 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1612 if (m_columnsContainer
!= 0) {
1613 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1615 return m_proxyModel
;
1618 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1620 return dirModel()->dirLister();
1623 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1625 emit
redirection(oldUrl
, newUrl
);
1626 m_controller
->redirectToUrl(newUrl
); // #186947
1629 void DolphinView::restoreContentsPosition()
1631 if (!m_restoredContentsPosition
.isNull()) {
1632 setContentsPosition(m_restoredContentsPosition
.x(), m_restoredContentsPosition
.y());
1633 m_restoredContentsPosition
= QPoint();
1637 #include "dolphinview.moc"