1 /***************************************************************************
2 * Copyright (C) 2006 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 <QApplication>
26 #include <QItemSelection>
31 #include <kactioncollection.h>
32 #include <kcolorscheme.h>
33 #include <kdirlister.h>
34 #include <kfilepreviewgenerator.h>
35 #include <kiconeffect.h>
37 #include <kio/deletejob.h>
38 #include <kio/netaccess.h>
39 #include <kio/previewjob.h>
42 #include <kmessagebox.h>
43 #include <kmimetyperesolver.h>
44 #include <konq_fileitemcapabilities.h>
45 #include <konq_operations.h>
46 #include <konqmimedata.h>
47 #include <ktoggleaction.h>
50 #include "dolphinmodel.h"
51 #include "dolphincolumnview.h"
52 #include "dolphincontroller.h"
53 #include "dolphinfileitemdelegate.h"
54 #include "dolphinsortfilterproxymodel.h"
55 #include "dolphindetailsview.h"
56 #include "dolphin_detailsmodesettings.h"
57 #include "dolphiniconsview.h"
58 #include "dolphinsettings.h"
59 #include "dolphin_generalsettings.h"
60 #include "draganddrophelper.h"
61 #include "folderexpander.h"
62 #include "renamedialog.h"
63 #include "tooltipmanager.h"
64 #include "viewproperties.h"
65 #include "zoomlevelinfo.h"
67 DolphinView::DolphinView(QWidget
* parent
,
69 KDirLister
* dirLister
,
70 DolphinModel
* dolphinModel
,
71 DolphinSortFilterProxyModel
* proxyModel
) :
75 m_loadingDirectory(false),
76 m_storedCategorizedSorting(false),
77 m_tabsForFiles(false),
78 m_isContextMenuOpen(false),
79 m_mode(DolphinView::IconsView
),
85 m_fileItemDelegate(0),
87 m_dolphinModel(dolphinModel
),
88 m_dirLister(dirLister
),
89 m_proxyModel(proxyModel
),
90 m_previewGenerator(0),
95 m_topLayout
= new QVBoxLayout(this);
96 m_topLayout
->setSpacing(0);
97 m_topLayout
->setMargin(0);
99 m_controller
= new DolphinController(this);
100 m_controller
->setUrl(url
);
102 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
103 this, SIGNAL(urlChanged(const KUrl
&)));
104 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
105 this, SLOT(slotRequestUrlChange(const KUrl
&)));
107 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
108 this, SLOT(openContextMenu(const QPoint
&)));
109 connect(m_controller
, SIGNAL(urlsDropped(const KFileItem
&, const KUrl
&, QDropEvent
*)),
110 this, SLOT(dropUrls(const KFileItem
&, const KUrl
&, QDropEvent
*)));
111 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
112 this, SLOT(updateSorting(DolphinView::Sorting
)));
113 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
114 this, SLOT(updateSortOrder(Qt::SortOrder
)));
115 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
116 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
117 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
118 this, SLOT(triggerItem(const KFileItem
&)));
119 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
120 this, SIGNAL(tabRequested(const KUrl
&)));
121 connect(m_controller
, SIGNAL(activated()),
122 this, SLOT(activate()));
123 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
124 this, SLOT(showHoverInformation(const KFileItem
&)));
125 connect(m_controller
, SIGNAL(viewportEntered()),
126 this, SLOT(clearHoverInformation()));
128 connect(m_dirLister
, SIGNAL(redirection(KUrl
, KUrl
)),
129 this, SIGNAL(redirection(KUrl
, KUrl
)));
130 connect(m_dirLister
, SIGNAL(completed()),
131 this, SLOT(restoreCurrentItem()));
133 applyViewProperties(url
);
134 m_topLayout
->addWidget(itemView());
137 DolphinView::~DolphinView()
141 const KUrl
& DolphinView::url() const
143 return m_controller
->url();
146 KUrl
DolphinView::rootUrl() const
148 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
151 void DolphinView::setActive(bool active
)
153 if (active
== m_active
) {
159 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
161 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
162 // bypasses the problem when having a split view and changing the active view to
163 // update the some URL dependent states. A nicer approach should be no big deal...
164 emit
urlChanged(url());
165 emit
selectionChanged(selectedItems());
170 QWidget
* viewport
= itemView()->viewport();
172 palette
.setColor(viewport
->backgroundRole(), color
);
173 viewport
->setPalette(palette
);
178 itemView()->setFocus();
182 m_controller
->indicateActivationChange(active
);
185 bool DolphinView::isActive() const
190 void DolphinView::setMode(Mode mode
)
192 if (mode
== m_mode
) {
193 return; // the wished mode is already set
196 const int oldZoomLevel
= m_controller
->zoomLevel();
201 const KUrl viewPropsUrl
= viewPropertiesUrl();
202 ViewProperties
props(viewPropsUrl
);
203 props
.setViewMode(m_mode
);
206 // the file item delegate has been recreated, apply the current
207 // additional information manually
208 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
209 m_fileItemDelegate
->setShowInformation(infoList
);
210 emit
additionalInfoChanged();
212 // Not all view modes support categorized sorting. Adjust the sorting model
213 // if changing the view mode results in a change of the categorized sorting
215 m_storedCategorizedSorting
= props
.categorizedSorting();
216 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
217 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
218 m_proxyModel
->setCategorizedModel(categorized
);
219 emit
categorizedSortingChanged();
223 updateZoomLevel(oldZoomLevel
);
226 DolphinView::Mode
DolphinView::mode() const
231 bool DolphinView::showPreview() const
233 return m_showPreview
;
236 bool DolphinView::showHiddenFiles() const
238 return m_dirLister
->showingDotFiles();
241 bool DolphinView::categorizedSorting() const
243 // If all view modes would support categorized sorting, returning
244 // m_proxyModel->isCategorizedModel() would be the way to go. As
245 // currently only the icons view supports caterized sorting, we remember
246 // the stored view properties state in m_storedCategorizedSorting and
247 // return this state. The application takes care to disable the corresponding
248 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
249 // that this setting is not applied to the current view mode.
250 return m_storedCategorizedSorting
;
253 bool DolphinView::supportsCategorizedSorting() const
255 return m_iconsView
!= 0;
258 void DolphinView::selectAll()
260 QAbstractItemView
* view
= itemView();
261 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
262 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
263 // selection instead of selecting all items. This is bypassed for KDE 4.0
264 // by invoking clearSelection() first.
265 view
->clearSelection();
269 void DolphinView::invertSelection()
271 if (isColumnViewActive()) {
272 // QAbstractItemView does not offer a virtual method invertSelection()
273 // as counterpart to QAbstractItemView::selectAll(). This makes it
274 // necessary to delegate the inverting of the selection to the
275 // column view, as only the selection of the active column should
277 m_columnView
->invertSelection();
279 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
280 const QAbstractItemModel
* itemModel
= selectionModel
->model();
282 const QModelIndex topLeft
= itemModel
->index(0, 0);
283 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
284 itemModel
->columnCount() - 1);
286 const QItemSelection
selection(topLeft
, bottomRight
);
287 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
291 bool DolphinView::hasSelection() const
293 return itemView()->selectionModel()->hasSelection();
296 void DolphinView::clearSelection()
298 itemView()->selectionModel()->clear();
301 KFileItemList
DolphinView::selectedItems() const
303 if (isColumnViewActive()) {
304 return m_columnView
->selectedItems();
307 const QAbstractItemView
* view
= itemView();
309 // Our view has a selection, we will map them back to the DolphinModel
310 // and then fill the KFileItemList.
311 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
313 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
314 KFileItemList itemList
;
316 const QModelIndexList indexList
= selection
.indexes();
317 foreach (const QModelIndex
&index
, indexList
) {
318 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
319 if (!item
.isNull()) {
320 itemList
.append(item
);
327 KUrl::List
DolphinView::selectedUrls() const
330 const KFileItemList list
= selectedItems();
331 foreach (const KFileItem
&item
, list
) {
332 urls
.append(item
.url());
337 int DolphinView::selectedItemsCount() const
339 if (isColumnViewActive()) {
340 // TODO: get rid of this special case by adjusting the dir lister
341 // to the current column
342 return m_columnView
->selectedItems().count();
345 return itemView()->selectionModel()->selection().count();
348 void DolphinView::setContentsPosition(int x
, int y
)
350 QAbstractItemView
* view
= itemView();
352 // the ColumnView takes care itself for the horizontal scrolling
353 if (!isColumnViewActive()) {
354 view
->horizontalScrollBar()->setValue(x
);
356 view
->verticalScrollBar()->setValue(y
);
358 m_loadingDirectory
= false;
361 QPoint
DolphinView::contentsPosition() const
363 const int x
= itemView()->horizontalScrollBar()->value();
364 const int y
= itemView()->verticalScrollBar()->value();
368 void DolphinView::setZoomLevel(int level
)
370 if (level
< ZoomLevelInfo::minimumLevel()) {
371 level
= ZoomLevelInfo::minimumLevel();
372 } else if (level
> ZoomLevelInfo::maximumLevel()) {
373 level
= ZoomLevelInfo::maximumLevel();
376 if (level
!= zoomLevel()) {
377 m_controller
->setZoomLevel(level
);
378 m_previewGenerator
->updatePreviews();
379 emit
zoomLevelChanged(level
);
383 int DolphinView::zoomLevel() const
385 return m_controller
->zoomLevel();
388 void DolphinView::setSorting(Sorting sorting
)
390 if (sorting
!= this->sorting()) {
391 updateSorting(sorting
);
395 DolphinView::Sorting
DolphinView::sorting() const
397 return m_proxyModel
->sorting();
400 void DolphinView::setSortOrder(Qt::SortOrder order
)
402 if (sortOrder() != order
) {
403 updateSortOrder(order
);
407 Qt::SortOrder
DolphinView::sortOrder() const
409 return m_proxyModel
->sortOrder();
412 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
414 const KUrl viewPropsUrl
= viewPropertiesUrl();
415 ViewProperties
props(viewPropsUrl
);
416 props
.setAdditionalInfo(info
);
417 m_fileItemDelegate
->setShowInformation(info
);
419 emit
additionalInfoChanged();
421 if (itemView() != m_detailsView
) {
422 // the details view requires no reloading of the directory, as it maps
423 // the file item delegate info to its columns internally
424 loadDirectory(viewPropsUrl
);
428 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
430 return m_fileItemDelegate
->showInformation();
433 void DolphinView::reload()
436 loadDirectory(url(), true);
439 void DolphinView::refresh()
441 const bool oldActivationState
= m_active
;
442 const int oldZoomLevel
= m_controller
->zoomLevel();
446 applyViewProperties(m_controller
->url());
449 setActive(oldActivationState
);
450 updateZoomLevel(oldZoomLevel
);
453 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
455 if (m_controller
->url() == url
) {
459 m_previewGenerator
->cancelPreviews();
460 m_controller
->setUrl(url
); // emits urlChanged, which we forward
462 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
463 applyViewProperties(rootUrl
);
464 loadDirectory(rootUrl
);
465 if (itemView() == m_columnView
) {
466 m_columnView
->setRootUrl(rootUrl
);
467 m_columnView
->showColumn(url
);
470 applyViewProperties(url
);
474 emit
startedPathLoading(url
);
477 void DolphinView::setNameFilter(const QString
& nameFilter
)
479 m_proxyModel
->setFilterRegExp(nameFilter
);
481 if (isColumnViewActive()) {
482 // adjusting the directory lister is not enough in the case of the
483 // column view, as each column has its own directory lister internally...
484 m_columnView
->setNameFilter(nameFilter
);
488 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
) const
490 foreach (const KFileItem
& item
, m_dirLister
->items()) {
499 QString
DolphinView::statusBarText() const
501 if (hasSelection()) {
502 // give a summary of the status of the selected files
504 const KFileItemList list
= selectedItems();
505 if (list
.isEmpty()) {
506 // when an item is triggered, it is temporary selected but selectedItems()
507 // will return an empty list
513 KIO::filesize_t byteSize
= 0;
514 KFileItemList::const_iterator it
= list
.begin();
515 const KFileItemList::const_iterator end
= list
.end();
517 const KFileItem
& item
= *it
;
522 byteSize
+= item
.size();
527 if (folderCount
> 0) {
528 text
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
535 const QString
sizeText(KIO::convertSize(byteSize
));
536 text
+= i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
540 // Give a summary of the status of the current folder.
543 calculateItemCount(fileCount
, folderCount
);
544 return KIO::itemsSummaryString(fileCount
+ folderCount
,
551 void DolphinView::setUrl(const KUrl
& url
)
553 // remember current item candidate (see restoreCurrentItem())
554 m_currentItemUrl
= url
;
555 updateView(url
, KUrl());
558 void DolphinView::changeSelection(const KFileItemList
& selection
)
561 if (selection
.isEmpty()) {
564 const KUrl
& baseUrl
= url();
566 QItemSelection new_selection
;
567 foreach(const KFileItem
& item
, selection
) {
568 url
= item
.url().upUrl();
569 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
570 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
571 new_selection
.select(index
, index
);
574 itemView()->selectionModel()->select(new_selection
,
575 QItemSelectionModel::ClearAndSelect
576 | QItemSelectionModel::Current
);
579 void DolphinView::renameSelectedItems()
581 const KFileItemList items
= selectedItems();
582 const int itemCount
= items
.count();
588 // More than one item has been selected for renaming. Open
589 // a rename dialog and rename all items afterwards.
590 RenameDialog
dialog(this, items
);
591 if (dialog
.exec() == QDialog::Rejected
) {
595 const QString newName
= dialog
.newName();
596 if (newName
.isEmpty()) {
597 emit
errorMessage(dialog
.errorString());
599 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
600 // as one operation instead of n rename operations like it is done now...
601 Q_ASSERT(newName
.contains('#'));
603 // iterate through all selected items and rename them...
605 foreach (const KFileItem
&item
, items
) {
606 const KUrl
& oldUrl
= item
.url();
608 number
.setNum(index
++);
610 QString name
= newName
;
611 name
.replace('#', number
);
613 if (oldUrl
.fileName() != name
) {
614 KUrl newUrl
= oldUrl
;
615 newUrl
.setFileName(name
);
616 KonqOperations::rename(this, oldUrl
, newUrl
);
620 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
621 Q_ASSERT(itemCount
== 1);
623 if (isColumnViewActive()) {
624 m_columnView
->editItem(items
.first());
626 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
627 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
628 itemView()->edit(proxyIndex
);
631 Q_ASSERT(itemCount
== 1);
633 RenameDialog
dialog(this, items
);
634 if (dialog
.exec() == QDialog::Rejected
) {
638 const QString
& newName
= dialog
.newName();
639 if (newName
.isEmpty()) {
640 emit
errorMessage(dialog
.errorString());
642 const KUrl
& oldUrl
= items
.first().url();
643 KUrl newUrl
= oldUrl
;
644 newUrl
.setFileName(newName
);
645 KonqOperations::rename(this, oldUrl
, newUrl
);
650 void DolphinView::trashSelectedItems()
652 const KUrl::List list
= simplifiedSelectedUrls();
653 KonqOperations::del(this, KonqOperations::TRASH
, list
);
656 void DolphinView::deleteSelectedItems()
658 const KUrl::List list
= simplifiedSelectedUrls();
659 const bool del
= KonqOperations::askDeleteConfirmation(list
,
661 KonqOperations::DEFAULT_CONFIRMATION
,
665 KIO::Job
* job
= KIO::del(list
);
666 connect(job
, SIGNAL(result(KJob
*)),
667 this, SLOT(slotDeleteFileFinished(KJob
*)));
671 void DolphinView::cutSelectedItems()
673 QMimeData
* mimeData
= new QMimeData();
674 const KUrl::List kdeUrls
= simplifiedSelectedUrls();
675 const KUrl::List mostLocalUrls
;
676 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
677 QApplication::clipboard()->setMimeData(mimeData
);
680 void DolphinView::copySelectedItems()
682 QMimeData
* mimeData
= new QMimeData();
683 const KUrl::List kdeUrls
= selectedUrls();
684 const KUrl::List mostLocalUrls
;
685 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
686 QApplication::clipboard()->setMimeData(mimeData
);
689 void DolphinView::paste()
694 void DolphinView::pasteIntoFolder()
696 const KFileItemList items
= selectedItems();
697 if ((items
.count() == 1) && items
.first().isDir()) {
698 pasteToUrl(items
.first().url());
702 void DolphinView::setShowPreview(bool show
)
704 if (m_showPreview
== show
) {
708 const KUrl viewPropsUrl
= viewPropertiesUrl();
709 ViewProperties
props(viewPropsUrl
);
710 props
.setShowPreview(show
);
712 m_showPreview
= show
;
713 m_previewGenerator
->setPreviewShown(show
);
715 const int oldZoomLevel
= m_controller
->zoomLevel();
716 emit
showPreviewChanged();
718 // Enabling or disabling the preview might change the icon size of the view.
719 // As the view does not emit a signal when the icon size has been changed,
720 // the used zoom level of the controller must be adjusted manually:
721 updateZoomLevel(oldZoomLevel
);
723 loadDirectory(viewPropsUrl
);
726 void DolphinView::setShowHiddenFiles(bool show
)
728 if (m_dirLister
->showingDotFiles() == show
) {
732 const KUrl viewPropsUrl
= viewPropertiesUrl();
733 ViewProperties
props(viewPropsUrl
);
734 props
.setShowHiddenFiles(show
);
736 m_dirLister
->setShowingDotFiles(show
);
737 emit
showHiddenFilesChanged();
739 loadDirectory(viewPropsUrl
);
742 void DolphinView::setCategorizedSorting(bool categorized
)
744 if (categorized
== categorizedSorting()) {
748 // setCategorizedSorting(true) may only get invoked
749 // if the view supports categorized sorting
750 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
752 ViewProperties
props(viewPropertiesUrl());
753 props
.setCategorizedSorting(categorized
);
756 m_storedCategorizedSorting
= categorized
;
757 m_proxyModel
->setCategorizedModel(categorized
);
759 emit
categorizedSortingChanged();
762 void DolphinView::toggleSortOrder()
764 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
765 Qt::DescendingOrder
:
770 void DolphinView::toggleAdditionalInfo(QAction
* action
)
772 const KFileItemDelegate::Information info
=
773 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
775 KFileItemDelegate::InformationList list
= additionalInfo();
777 const bool show
= action
->isChecked();
779 const int index
= list
.indexOf(info
);
780 const bool containsInfo
= (index
>= 0);
781 if (show
&& !containsInfo
) {
783 setAdditionalInfo(list
);
784 } else if (!show
&& containsInfo
) {
785 list
.removeAt(index
);
786 setAdditionalInfo(list
);
787 Q_ASSERT(list
.indexOf(info
) < 0);
791 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
793 QWidget::mouseReleaseEvent(event
);
797 void DolphinView::wheelEvent(QWheelEvent
* event
)
799 if (event
->modifiers() & Qt::ControlModifier
) {
800 const int delta
= event
->delta();
801 const int level
= zoomLevel();
803 setZoomLevel(level
+ 1);
804 } else if (delta
< 0) {
805 setZoomLevel(level
- 1);
811 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
813 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
814 m_controller
->requestActivation();
817 return QWidget::eventFilter(watched
, event
);
820 void DolphinView::activate()
825 void DolphinView::triggerItem(const KFileItem
& item
)
827 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
828 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
829 // items are selected by the user, hence don't trigger the
830 // item specified by 'index'
834 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
835 if (item
.isNull() || m_isContextMenuOpen
) {
839 if (m_toolTipManager
!= 0) {
840 m_toolTipManager
->hideTip();
842 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
845 void DolphinView::emitSelectionChangedSignal()
847 emit
selectionChanged(DolphinView::selectedItems());
850 void DolphinView::openContextMenu(const QPoint
& pos
)
853 if (isColumnViewActive()) {
854 item
= m_columnView
->itemAt(pos
);
856 const QModelIndex index
= itemView()->indexAt(pos
);
857 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
858 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
859 item
= m_dolphinModel
->itemForIndex(dolphinModelIndex
);
863 if (m_toolTipManager
!= 0) {
864 m_toolTipManager
->hideTip();
867 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
868 emit
requestContextMenu(item
, url());
869 m_isContextMenuOpen
= false;
872 void DolphinView::dropUrls(const KFileItem
& destItem
,
873 const KUrl
& destPath
,
876 DragAndDropHelper::dropUrls(destItem
, destPath
, event
, this);
879 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
881 ViewProperties
props(viewPropertiesUrl());
882 props
.setSorting(sorting
);
884 m_proxyModel
->setSorting(sorting
);
886 emit
sortingChanged(sorting
);
889 void DolphinView::updateSortOrder(Qt::SortOrder order
)
891 ViewProperties
props(viewPropertiesUrl());
892 props
.setSortOrder(order
);
894 m_proxyModel
->setSortOrder(order
);
896 emit
sortOrderChanged(order
);
899 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
901 ViewProperties
props(viewPropertiesUrl());
902 props
.setAdditionalInfo(info
);
905 m_fileItemDelegate
->setShowInformation(info
);
907 emit
additionalInfoChanged();
910 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
912 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
913 (m_mode
== DolphinView::IconsView
);
915 QAction
* showSizeInfo
= collection
->action("show_size_info");
916 QAction
* showDateInfo
= collection
->action("show_date_info");
917 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
918 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
919 QAction
* showGroupInfo
= collection
->action("show_group_info");
920 QAction
* showMimeInfo
= collection
->action("show_mime_info");
922 showSizeInfo
->setChecked(false);
923 showDateInfo
->setChecked(false);
924 showPermissionsInfo
->setChecked(false);
925 showOwnerInfo
->setChecked(false);
926 showGroupInfo
->setChecked(false);
927 showMimeInfo
->setChecked(false);
929 showSizeInfo
->setEnabled(enable
);
930 showDateInfo
->setEnabled(enable
);
931 showPermissionsInfo
->setEnabled(enable
);
932 showOwnerInfo
->setEnabled(enable
);
933 showGroupInfo
->setEnabled(enable
);
934 showMimeInfo
->setEnabled(enable
);
936 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
938 case KFileItemDelegate::Size
:
939 showSizeInfo
->setChecked(true);
941 case KFileItemDelegate::ModificationTime
:
942 showDateInfo
->setChecked(true);
944 case KFileItemDelegate::Permissions
:
945 showPermissionsInfo
->setChecked(true);
947 case KFileItemDelegate::Owner
:
948 showOwnerInfo
->setChecked(true);
950 case KFileItemDelegate::OwnerAndGroup
:
951 showGroupInfo
->setChecked(true);
953 case KFileItemDelegate::FriendlyMimeType
:
954 showMimeInfo
->setChecked(true);
962 QPair
<bool, QString
> DolphinView::pasteInfo() const
964 QPair
<bool, QString
> ret
;
965 QClipboard
* clipboard
= QApplication::clipboard();
966 const QMimeData
* mimeData
= clipboard
->mimeData();
968 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
969 if (!urls
.isEmpty()) {
970 // disable the paste action if no writing is supported
971 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url());
972 ret
.first
= KonqFileItemCapabilities(KFileItemList() << item
).supportsWriting();
974 if (urls
.count() == 1) {
975 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
976 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
977 i18nc("@action:inmenu", "Paste One File");
980 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
984 ret
.second
= i18nc("@action:inmenu", "Paste");
990 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
992 m_tabsForFiles
= tabsForFiles
;
995 bool DolphinView::isTabsForFilesEnabled() const
997 return m_tabsForFiles
;
1000 void DolphinView::emitContentsMoved()
1002 // only emit the contents moved signal if:
1003 // - no directory loading is ongoing (this would reset the contents position
1004 // always to (0, 0))
1005 // - if the Column View is active: the column view does an automatic
1006 // positioning during the loading operation, which must be remembered
1007 if (!m_loadingDirectory
|| isColumnViewActive()) {
1008 const QPoint
pos(contentsPosition());
1009 emit
contentsMoved(pos
.x(), pos
.y());
1013 void DolphinView::showHoverInformation(const KFileItem
& item
)
1015 emit
requestItemInfo(item
);
1018 void DolphinView::clearHoverInformation()
1020 emit
requestItemInfo(KFileItem());
1023 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1025 if (job
->error() == 0) {
1026 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1027 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1028 emit
errorMessage(job
->errorString());
1032 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1034 emit
requestUrlChange(url
);
1035 m_controller
->setUrl(url
);
1038 void DolphinView::restoreCurrentItem()
1040 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
1041 if (dirIndex
.isValid()) {
1042 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
1043 QAbstractItemView
* view
= itemView();
1044 const bool clearSelection
= !hasSelection();
1045 view
->setCurrentIndex(proxyIndex
);
1046 if (clearSelection
) {
1047 view
->clearSelection();
1052 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1054 if (!url
.isValid()) {
1055 const QString
location(url
.pathOrUrl());
1056 if (location
.isEmpty()) {
1057 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1059 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1064 m_loadingDirectory
= true;
1066 m_dirLister
->stop();
1067 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1069 if (isColumnViewActive()) {
1070 // adjusting the directory lister is not enough in the case of the
1071 // column view, as each column has its own directory lister internally...
1073 m_columnView
->reload();
1075 m_columnView
->showColumn(url
);
1080 KUrl
DolphinView::viewPropertiesUrl() const
1082 if (isColumnViewActive()) {
1083 return m_columnView
->rootUrl();
1089 void DolphinView::applyViewProperties(const KUrl
& url
)
1091 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1092 // The column view is active, hence don't apply the view properties
1093 // of sub directories (represented by columns) to the view. The
1094 // view always represents the properties of the first column.
1098 const ViewProperties
props(url
);
1100 const Mode mode
= props
.viewMode();
1101 if (m_mode
!= mode
) {
1102 const int oldZoomLevel
= m_controller
->zoomLevel();
1108 updateZoomLevel(oldZoomLevel
);
1110 if (itemView() == 0) {
1113 Q_ASSERT(itemView() != 0);
1114 Q_ASSERT(m_fileItemDelegate
!= 0);
1116 const bool showHiddenFiles
= props
.showHiddenFiles();
1117 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1118 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1119 emit
showHiddenFilesChanged();
1122 m_storedCategorizedSorting
= props
.categorizedSorting();
1123 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1124 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1125 m_proxyModel
->setCategorizedModel(categorized
);
1126 emit
categorizedSortingChanged();
1129 const DolphinView::Sorting sorting
= props
.sorting();
1130 if (sorting
!= m_proxyModel
->sorting()) {
1131 m_proxyModel
->setSorting(sorting
);
1132 emit
sortingChanged(sorting
);
1135 const Qt::SortOrder sortOrder
= props
.sortOrder();
1136 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1137 m_proxyModel
->setSortOrder(sortOrder
);
1138 emit
sortOrderChanged(sortOrder
);
1141 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1142 if (info
!= m_fileItemDelegate
->showInformation()) {
1143 m_fileItemDelegate
->setShowInformation(info
);
1144 emit
additionalInfoChanged();
1147 const bool showPreview
= props
.showPreview();
1148 if (showPreview
!= m_showPreview
) {
1149 m_showPreview
= showPreview
;
1150 m_previewGenerator
->setPreviewShown(showPreview
);
1152 const int oldZoomLevel
= m_controller
->zoomLevel();
1153 emit
showPreviewChanged();
1155 // Enabling or disabling the preview might change the icon size of the view.
1156 // As the view does not emit a signal when the icon size has been changed,
1157 // the used zoom level of the controller must be adjusted manually:
1158 updateZoomLevel(oldZoomLevel
);
1162 void DolphinView::createView()
1165 Q_ASSERT(m_iconsView
== 0);
1166 Q_ASSERT(m_detailsView
== 0);
1167 Q_ASSERT(m_columnView
== 0);
1169 QAbstractItemView
* view
= 0;
1172 m_iconsView
= new DolphinIconsView(this, m_controller
);
1178 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1179 view
= m_detailsView
;
1183 m_columnView
= new DolphinColumnView(this, m_controller
);
1184 view
= m_columnView
;
1188 Q_ASSERT(view
!= 0);
1189 view
->installEventFilter(this);
1191 if (m_mode
!= ColumnView
) {
1192 // Give the view the ability to auto-expand its directories on hovering
1193 // (the column view takes care about this itself). If the details view
1194 // uses expandable folders, the auto-expanding should be used always.
1195 DolphinSettings
& settings
= DolphinSettings::instance();
1196 const bool enabled
= settings
.generalSettings()->autoExpandFolders() ||
1197 ((m_detailsView
!= 0) && settings
.detailsModeSettings()->expandableFolders());
1199 FolderExpander
* folderExpander
= new FolderExpander(view
, m_proxyModel
);
1200 folderExpander
->setEnabled(enabled
);
1201 connect(folderExpander
, SIGNAL(enterDir(const QModelIndex
&)),
1202 m_controller
, SLOT(triggerItem(const QModelIndex
&)));
1205 m_controller
->setItemView(view
);
1207 m_fileItemDelegate
= new DolphinFileItemDelegate(view
);
1208 m_fileItemDelegate
->setShowToolTipWhenElided(false);
1209 m_fileItemDelegate
->setMinimizedNameColumn(m_mode
== DetailsView
);
1210 view
->setItemDelegate(m_fileItemDelegate
);
1212 view
->setModel(m_proxyModel
);
1213 if (m_selectionModel
!= 0) {
1214 view
->setSelectionModel(m_selectionModel
);
1216 m_selectionModel
= view
->selectionModel();
1219 // reparent the selection model, as it should not be deleted
1220 // when deleting the model
1221 m_selectionModel
->setParent(this);
1223 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1225 m_previewGenerator
= new KFilePreviewGenerator(view
);
1226 m_previewGenerator
->setPreviewShown(m_showPreview
);
1228 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1229 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1230 connect(m_controller
, SIGNAL(hideToolTip()),
1231 m_toolTipManager
, SLOT(hideTip()));
1234 m_topLayout
->insertWidget(1, view
);
1236 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1237 this, SLOT(emitSelectionChangedSignal()));
1238 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1239 this, SLOT(emitContentsMoved()));
1240 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1241 this, SLOT(emitContentsMoved()));
1244 void DolphinView::deleteView()
1246 QAbstractItemView
* view
= itemView();
1248 // It's important to set the keyboard focus to the parent
1249 // before deleting the view: Otherwise when having a split
1250 // view the other view will get the focus and will request
1251 // an activation (see DolphinView::eventFilter()).
1254 m_topLayout
->removeWidget(view
);
1256 view
->deleteLater();
1261 m_fileItemDelegate
= 0;
1262 m_previewGenerator
= 0;
1263 m_toolTipManager
= 0;
1267 QAbstractItemView
* DolphinView::itemView() const
1269 if (m_detailsView
!= 0) {
1270 return m_detailsView
;
1271 } else if (m_columnView
!= 0) {
1272 return m_columnView
;
1278 bool DolphinView::isCutItem(const KFileItem
& item
) const
1280 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1281 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1283 const KUrl
& itemUrl
= item
.url();
1284 KUrl::List::const_iterator it
= cutUrls
.begin();
1285 const KUrl::List::const_iterator end
= cutUrls
.end();
1287 if (*it
== itemUrl
) {
1296 void DolphinView::pasteToUrl(const KUrl
& url
)
1298 QClipboard
* clipboard
= QApplication::clipboard();
1299 const QMimeData
* mimeData
= clipboard
->mimeData();
1301 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1302 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1303 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1306 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1310 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1312 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(itemView()->iconSize());
1313 if (oldZoomLevel
!= newZoomLevel
) {
1314 m_controller
->setZoomLevel(newZoomLevel
);
1315 emit
zoomLevelChanged(newZoomLevel
);
1319 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1321 KUrl::List list
= selectedUrls();
1322 if (itemsExpandable() ) {
1323 list
= KonqOperations::simplifiedUrlList(list
);
1328 bool DolphinView::itemsExpandable() const
1330 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1333 #include "dolphinview.moc"