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 <kfileitemdelegate.h>
35 #include <kfilepreviewgenerator.h>
36 #include <kiconeffect.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 <ktoggleaction.h>
51 #include "dolphindropcontroller.h"
52 #include "dolphinmodel.h"
53 #include "dolphincolumnview.h"
54 #include "dolphincontroller.h"
55 #include "dolphinsortfilterproxymodel.h"
56 #include "dolphindetailsview.h"
57 #include "dolphin_detailsmodesettings.h"
58 #include "dolphiniconsview.h"
59 #include "dolphinsettings.h"
60 #include "dolphin_generalsettings.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, SLOT(slotRedirection(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
;
445 applyViewProperties(m_controller
->url());
448 setActive(oldActivationState
);
451 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
453 if (m_controller
->url() == url
) {
457 m_previewGenerator
->cancelPreviews();
458 m_controller
->setUrl(url
); // emits urlChanged, which we forward
460 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
461 applyViewProperties(rootUrl
);
462 loadDirectory(rootUrl
);
463 if (itemView() == m_columnView
) {
464 m_columnView
->setRootUrl(rootUrl
);
465 m_columnView
->showColumn(url
);
468 applyViewProperties(url
);
472 emit
startedPathLoading(url
);
475 void DolphinView::setNameFilter(const QString
& nameFilter
)
477 m_proxyModel
->setFilterRegExp(nameFilter
);
479 if (isColumnViewActive()) {
480 // adjusting the directory lister is not enough in the case of the
481 // column view, as each column has its own directory lister internally...
482 m_columnView
->setNameFilter(nameFilter
);
486 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
) const
488 foreach (const KFileItem
& item
, m_dirLister
->items()) {
497 QString
DolphinView::statusBarText() const
499 if (hasSelection()) {
500 // give a summary of the status of the selected files
502 const KFileItemList list
= selectedItems();
503 if (list
.isEmpty()) {
504 // when an item is triggered, it is temporary selected but selectedItems()
505 // will return an empty list
511 KIO::filesize_t byteSize
= 0;
512 KFileItemList::const_iterator it
= list
.begin();
513 const KFileItemList::const_iterator end
= list
.end();
515 const KFileItem
& item
= *it
;
520 byteSize
+= item
.size();
525 if (folderCount
> 0) {
526 text
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
533 const QString
sizeText(KIO::convertSize(byteSize
));
534 text
+= i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
538 // Give a summary of the status of the current folder.
541 calculateItemCount(fileCount
, folderCount
);
542 return KIO::itemsSummaryString(fileCount
+ folderCount
,
549 void DolphinView::setUrl(const KUrl
& url
)
551 // remember current item candidate (see restoreCurrentItem())
552 m_currentItemUrl
= url
;
553 updateView(url
, KUrl());
556 void DolphinView::changeSelection(const KFileItemList
& selection
)
559 if (selection
.isEmpty()) {
562 const KUrl
& baseUrl
= url();
564 QItemSelection new_selection
;
565 foreach(const KFileItem
& item
, selection
) {
566 url
= item
.url().upUrl();
567 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
568 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
569 new_selection
.select(index
, index
);
572 itemView()->selectionModel()->select(new_selection
,
573 QItemSelectionModel::ClearAndSelect
574 | QItemSelectionModel::Current
);
577 void DolphinView::renameSelectedItems()
579 const KFileItemList items
= selectedItems();
580 const int itemCount
= items
.count();
586 // More than one item has been selected for renaming. Open
587 // a rename dialog and rename all items afterwards.
588 RenameDialog
dialog(this, items
);
589 if (dialog
.exec() == QDialog::Rejected
) {
593 const QString newName
= dialog
.newName();
594 if (newName
.isEmpty()) {
595 emit
errorMessage(dialog
.errorString());
597 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
598 // as one operation instead of n rename operations like it is done now...
599 Q_ASSERT(newName
.contains('#'));
601 // iterate through all selected items and rename them...
603 foreach (const KFileItem
&item
, items
) {
604 const KUrl
& oldUrl
= item
.url();
606 number
.setNum(index
++);
608 QString name
= newName
;
609 name
.replace('#', number
);
611 if (oldUrl
.fileName() != name
) {
612 KUrl newUrl
= oldUrl
;
613 newUrl
.setFileName(name
);
614 KonqOperations::rename(this, oldUrl
, newUrl
);
618 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
619 Q_ASSERT(itemCount
== 1);
621 if (isColumnViewActive()) {
622 m_columnView
->editItem(items
.first());
624 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
625 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
626 itemView()->edit(proxyIndex
);
629 Q_ASSERT(itemCount
== 1);
631 RenameDialog
dialog(this, items
);
632 if (dialog
.exec() == QDialog::Rejected
) {
636 const QString
& newName
= dialog
.newName();
637 if (newName
.isEmpty()) {
638 emit
errorMessage(dialog
.errorString());
640 const KUrl
& oldUrl
= items
.first().url();
641 KUrl newUrl
= oldUrl
;
642 newUrl
.setFileName(newName
);
643 KonqOperations::rename(this, oldUrl
, newUrl
);
648 void DolphinView::trashSelectedItems()
650 const KUrl::List list
= simplifiedSelectedUrls();
651 KonqOperations::del(this, KonqOperations::TRASH
, list
);
654 void DolphinView::deleteSelectedItems()
656 const KUrl::List list
= simplifiedSelectedUrls();
657 const bool del
= KonqOperations::askDeleteConfirmation(list
,
659 KonqOperations::DEFAULT_CONFIRMATION
,
663 KIO::Job
* job
= KIO::del(list
);
664 connect(job
, SIGNAL(result(KJob
*)),
665 this, SLOT(slotDeleteFileFinished(KJob
*)));
669 void DolphinView::cutSelectedItems()
671 QMimeData
* mimeData
= new QMimeData();
672 const KUrl::List kdeUrls
= simplifiedSelectedUrls();
673 const KUrl::List mostLocalUrls
;
674 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
675 QApplication::clipboard()->setMimeData(mimeData
);
678 void DolphinView::copySelectedItems()
680 QMimeData
* mimeData
= new QMimeData();
681 const KUrl::List kdeUrls
= selectedUrls();
682 const KUrl::List mostLocalUrls
;
683 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
684 QApplication::clipboard()->setMimeData(mimeData
);
687 void DolphinView::paste()
692 void DolphinView::pasteIntoFolder()
694 const KFileItemList items
= selectedItems();
695 if ((items
.count() == 1) && items
.first().isDir()) {
696 pasteToUrl(items
.first().url());
700 void DolphinView::setShowPreview(bool show
)
702 if (m_showPreview
== show
) {
706 const KUrl viewPropsUrl
= viewPropertiesUrl();
707 ViewProperties
props(viewPropsUrl
);
708 props
.setShowPreview(show
);
710 m_showPreview
= show
;
711 m_previewGenerator
->setPreviewShown(show
);
713 const int oldZoomLevel
= m_controller
->zoomLevel();
714 emit
showPreviewChanged();
716 // Enabling or disabling the preview might change the icon size of the view.
717 // As the view does not emit a signal when the icon size has been changed,
718 // the used zoom level of the controller must be adjusted manually:
719 updateZoomLevel(oldZoomLevel
);
721 loadDirectory(viewPropsUrl
);
724 void DolphinView::setShowHiddenFiles(bool show
)
726 if (m_dirLister
->showingDotFiles() == show
) {
730 const KUrl viewPropsUrl
= viewPropertiesUrl();
731 ViewProperties
props(viewPropsUrl
);
732 props
.setShowHiddenFiles(show
);
734 m_dirLister
->setShowingDotFiles(show
);
735 emit
showHiddenFilesChanged();
737 loadDirectory(viewPropsUrl
);
740 void DolphinView::setCategorizedSorting(bool categorized
)
742 if (categorized
== categorizedSorting()) {
746 // setCategorizedSorting(true) may only get invoked
747 // if the view supports categorized sorting
748 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
750 ViewProperties
props(viewPropertiesUrl());
751 props
.setCategorizedSorting(categorized
);
754 m_storedCategorizedSorting
= categorized
;
755 m_proxyModel
->setCategorizedModel(categorized
);
757 emit
categorizedSortingChanged();
760 void DolphinView::toggleSortOrder()
762 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
763 Qt::DescendingOrder
:
768 void DolphinView::toggleAdditionalInfo(QAction
* action
)
770 const KFileItemDelegate::Information info
=
771 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
773 KFileItemDelegate::InformationList list
= additionalInfo();
775 const bool show
= action
->isChecked();
777 const int index
= list
.indexOf(info
);
778 const bool containsInfo
= (index
>= 0);
779 if (show
&& !containsInfo
) {
781 setAdditionalInfo(list
);
782 } else if (!show
&& containsInfo
) {
783 list
.removeAt(index
);
784 setAdditionalInfo(list
);
785 Q_ASSERT(list
.indexOf(info
) < 0);
789 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
791 QWidget::mouseReleaseEvent(event
);
795 void DolphinView::wheelEvent(QWheelEvent
* event
)
797 if (event
->modifiers() & Qt::ControlModifier
) {
798 const int delta
= event
->delta();
799 const int level
= zoomLevel();
801 setZoomLevel(level
+ 1);
802 } else if (delta
< 0) {
803 setZoomLevel(level
- 1);
809 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
811 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
812 m_controller
->requestActivation();
815 return QWidget::eventFilter(watched
, event
);
818 void DolphinView::activate()
823 void DolphinView::triggerItem(const KFileItem
& item
)
825 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
826 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
827 // items are selected by the user, hence don't trigger the
828 // item specified by 'index'
832 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
833 if (item
.isNull() || m_isContextMenuOpen
) {
837 if (m_toolTipManager
!= 0) {
838 m_toolTipManager
->hideTip();
840 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
843 void DolphinView::emitSelectionChangedSignal()
845 emit
selectionChanged(DolphinView::selectedItems());
848 void DolphinView::openContextMenu(const QPoint
& pos
)
851 if (isColumnViewActive()) {
852 item
= m_columnView
->itemAt(pos
);
854 const QModelIndex index
= itemView()->indexAt(pos
);
855 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
856 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
857 item
= m_dolphinModel
->itemForIndex(dolphinModelIndex
);
861 if (m_toolTipManager
!= 0) {
862 m_toolTipManager
->hideTip();
865 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
866 emit
requestContextMenu(item
, url());
867 m_isContextMenuOpen
= false;
870 void DolphinView::dropUrls(const KFileItem
& destItem
,
871 const KUrl
& destPath
,
874 DolphinDropController::dropUrls(destItem
, destPath
, event
, this);
877 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
879 ViewProperties
props(viewPropertiesUrl());
880 props
.setSorting(sorting
);
882 m_proxyModel
->setSorting(sorting
);
884 emit
sortingChanged(sorting
);
887 void DolphinView::updateSortOrder(Qt::SortOrder order
)
889 ViewProperties
props(viewPropertiesUrl());
890 props
.setSortOrder(order
);
892 m_proxyModel
->setSortOrder(order
);
894 emit
sortOrderChanged(order
);
897 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
899 ViewProperties
props(viewPropertiesUrl());
900 props
.setAdditionalInfo(info
);
903 m_fileItemDelegate
->setShowInformation(info
);
905 emit
additionalInfoChanged();
908 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
910 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
911 (m_mode
== DolphinView::IconsView
);
913 QAction
* showSizeInfo
= collection
->action("show_size_info");
914 QAction
* showDateInfo
= collection
->action("show_date_info");
915 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
916 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
917 QAction
* showGroupInfo
= collection
->action("show_group_info");
918 QAction
* showMimeInfo
= collection
->action("show_mime_info");
920 showSizeInfo
->setChecked(false);
921 showDateInfo
->setChecked(false);
922 showPermissionsInfo
->setChecked(false);
923 showOwnerInfo
->setChecked(false);
924 showGroupInfo
->setChecked(false);
925 showMimeInfo
->setChecked(false);
927 showSizeInfo
->setEnabled(enable
);
928 showDateInfo
->setEnabled(enable
);
929 showPermissionsInfo
->setEnabled(enable
);
930 showOwnerInfo
->setEnabled(enable
);
931 showGroupInfo
->setEnabled(enable
);
932 showMimeInfo
->setEnabled(enable
);
934 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
936 case KFileItemDelegate::Size
:
937 showSizeInfo
->setChecked(true);
939 case KFileItemDelegate::ModificationTime
:
940 showDateInfo
->setChecked(true);
942 case KFileItemDelegate::Permissions
:
943 showPermissionsInfo
->setChecked(true);
945 case KFileItemDelegate::Owner
:
946 showOwnerInfo
->setChecked(true);
948 case KFileItemDelegate::OwnerAndGroup
:
949 showGroupInfo
->setChecked(true);
951 case KFileItemDelegate::FriendlyMimeType
:
952 showMimeInfo
->setChecked(true);
960 QPair
<bool, QString
> DolphinView::pasteInfo() const
962 QPair
<bool, QString
> ret
;
963 QClipboard
* clipboard
= QApplication::clipboard();
964 const QMimeData
* mimeData
= clipboard
->mimeData();
966 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
967 if (!urls
.isEmpty()) {
968 // disable the paste action if no writing is supported
969 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url());
970 ret
.first
= KonqFileItemCapabilities(KFileItemList() << item
).supportsWriting();
972 if (urls
.count() == 1) {
973 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
974 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
975 i18nc("@action:inmenu", "Paste One File");
978 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
982 ret
.second
= i18nc("@action:inmenu", "Paste");
988 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
990 m_tabsForFiles
= tabsForFiles
;
993 bool DolphinView::isTabsForFilesEnabled() const
995 return m_tabsForFiles
;
998 void DolphinView::emitContentsMoved()
1000 // only emit the contents moved signal if:
1001 // - no directory loading is ongoing (this would reset the contents position
1002 // always to (0, 0))
1003 // - if the Column View is active: the column view does an automatic
1004 // positioning during the loading operation, which must be remembered
1005 if (!m_loadingDirectory
|| isColumnViewActive()) {
1006 const QPoint
pos(contentsPosition());
1007 emit
contentsMoved(pos
.x(), pos
.y());
1011 void DolphinView::showHoverInformation(const KFileItem
& item
)
1013 emit
requestItemInfo(item
);
1016 void DolphinView::clearHoverInformation()
1018 emit
requestItemInfo(KFileItem());
1021 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1023 if (job
->error() == 0) {
1024 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1026 emit
errorMessage(job
->errorString());
1030 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1032 if (oldUrl
== m_controller
->url()) {
1033 m_controller
->setUrl(newUrl
);
1037 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1039 emit
requestUrlChange(url
);
1040 m_controller
->setUrl(url
);
1043 void DolphinView::restoreCurrentItem()
1045 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
1046 if (dirIndex
.isValid()) {
1047 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
1048 QAbstractItemView
* view
= itemView();
1049 const bool clearSelection
= !hasSelection();
1050 view
->setCurrentIndex(proxyIndex
);
1051 if (clearSelection
) {
1052 view
->clearSelection();
1057 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1059 if (!url
.isValid()) {
1060 const QString
location(url
.pathOrUrl());
1061 if (location
.isEmpty()) {
1062 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1064 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1069 m_loadingDirectory
= true;
1071 m_dirLister
->stop();
1072 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1074 if (isColumnViewActive()) {
1075 // adjusting the directory lister is not enough in the case of the
1076 // column view, as each column has its own directory lister internally...
1078 m_columnView
->reload();
1080 m_columnView
->showColumn(url
);
1085 KUrl
DolphinView::viewPropertiesUrl() const
1087 if (isColumnViewActive()) {
1088 return m_columnView
->rootUrl();
1094 void DolphinView::applyViewProperties(const KUrl
& url
)
1096 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1097 // The column view is active, hence don't apply the view properties
1098 // of sub directories (represented by columns) to the view. The
1099 // view always represents the properties of the first column.
1103 const ViewProperties
props(url
);
1105 const Mode mode
= props
.viewMode();
1106 if (m_mode
!= mode
) {
1107 const int oldZoomLevel
= m_controller
->zoomLevel();
1113 updateZoomLevel(oldZoomLevel
);
1115 if (itemView() == 0) {
1118 Q_ASSERT(itemView() != 0);
1119 Q_ASSERT(m_fileItemDelegate
!= 0);
1121 const bool showHiddenFiles
= props
.showHiddenFiles();
1122 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1123 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1124 emit
showHiddenFilesChanged();
1127 m_storedCategorizedSorting
= props
.categorizedSorting();
1128 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1129 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1130 m_proxyModel
->setCategorizedModel(categorized
);
1131 emit
categorizedSortingChanged();
1134 const DolphinView::Sorting sorting
= props
.sorting();
1135 if (sorting
!= m_proxyModel
->sorting()) {
1136 m_proxyModel
->setSorting(sorting
);
1137 emit
sortingChanged(sorting
);
1140 const Qt::SortOrder sortOrder
= props
.sortOrder();
1141 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1142 m_proxyModel
->setSortOrder(sortOrder
);
1143 emit
sortOrderChanged(sortOrder
);
1146 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1147 if (info
!= m_fileItemDelegate
->showInformation()) {
1148 m_fileItemDelegate
->setShowInformation(info
);
1149 emit
additionalInfoChanged();
1152 const bool showPreview
= props
.showPreview();
1153 if (showPreview
!= m_showPreview
) {
1154 m_showPreview
= showPreview
;
1155 m_previewGenerator
->setPreviewShown(showPreview
);
1157 const int oldZoomLevel
= m_controller
->zoomLevel();
1158 emit
showPreviewChanged();
1160 // Enabling or disabling the preview might change the icon size of the view.
1161 // As the view does not emit a signal when the icon size has been changed,
1162 // the used zoom level of the controller must be adjusted manually:
1163 updateZoomLevel(oldZoomLevel
);
1167 void DolphinView::createView()
1170 Q_ASSERT(m_iconsView
== 0);
1171 Q_ASSERT(m_detailsView
== 0);
1172 Q_ASSERT(m_columnView
== 0);
1174 QAbstractItemView
* view
= 0;
1177 m_iconsView
= new DolphinIconsView(this, m_controller
);
1183 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1184 view
= m_detailsView
;
1188 m_columnView
= new DolphinColumnView(this, m_controller
);
1189 view
= m_columnView
;
1193 Q_ASSERT(view
!= 0);
1194 view
->installEventFilter(this);
1196 if (m_mode
!= ColumnView
) {
1197 // Give the view the ability to auto-expand its directories on hovering
1198 // (the column view takes care about this itself). If the details view
1199 // uses expandable folders, the auto-expanding should be used always.
1200 DolphinSettings
& settings
= DolphinSettings::instance();
1201 const bool enabled
= settings
.generalSettings()->autoExpandFolders() ||
1202 ((m_detailsView
!= 0) && settings
.detailsModeSettings()->expandableFolders());
1204 FolderExpander
* folderExpander
= new FolderExpander(view
, m_proxyModel
);
1205 folderExpander
->setEnabled(enabled
);
1206 connect(folderExpander
, SIGNAL(enterDir(const QModelIndex
&)),
1207 m_controller
, SLOT(triggerItem(const QModelIndex
&)));
1210 m_controller
->setItemView(view
);
1212 m_fileItemDelegate
= new KFileItemDelegate(view
);
1213 m_fileItemDelegate
->setShowToolTipWhenElided(false);
1214 view
->setItemDelegate(m_fileItemDelegate
);
1216 view
->setModel(m_proxyModel
);
1217 if (m_selectionModel
!= 0) {
1218 view
->setSelectionModel(m_selectionModel
);
1220 m_selectionModel
= view
->selectionModel();
1223 // reparent the selection model, as it should not be deleted
1224 // when deleting the model
1225 m_selectionModel
->setParent(this);
1227 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1229 m_previewGenerator
= new KFilePreviewGenerator(view
);
1230 m_previewGenerator
->setPreviewShown(m_showPreview
);
1232 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1233 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1236 m_topLayout
->insertWidget(1, view
);
1238 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1239 this, SLOT(emitSelectionChangedSignal()));
1240 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1241 this, SLOT(emitContentsMoved()));
1242 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1243 this, SLOT(emitContentsMoved()));
1246 void DolphinView::deleteView()
1248 QAbstractItemView
* view
= itemView();
1250 // It's important to set the keyboard focus to the parent
1251 // before deleting the view: Otherwise when having a split
1252 // view the other view will get the focus and will request
1253 // an activation (see DolphinView::eventFilter()).
1256 m_topLayout
->removeWidget(view
);
1258 view
->deleteLater();
1263 m_fileItemDelegate
= 0;
1264 m_previewGenerator
= 0;
1265 m_toolTipManager
= 0;
1269 QAbstractItemView
* DolphinView::itemView() const
1271 if (m_detailsView
!= 0) {
1272 return m_detailsView
;
1273 } else if (m_columnView
!= 0) {
1274 return m_columnView
;
1280 bool DolphinView::isCutItem(const KFileItem
& item
) const
1282 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1283 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1285 const KUrl
& itemUrl
= item
.url();
1286 KUrl::List::const_iterator it
= cutUrls
.begin();
1287 const KUrl::List::const_iterator end
= cutUrls
.end();
1289 if (*it
== itemUrl
) {
1298 void DolphinView::pasteToUrl(const KUrl
& url
)
1300 QClipboard
* clipboard
= QApplication::clipboard();
1301 const QMimeData
* mimeData
= clipboard
->mimeData();
1303 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1304 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1305 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1308 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1312 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1314 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(itemView()->iconSize());
1315 if (oldZoomLevel
!= newZoomLevel
) {
1316 m_controller
->setZoomLevel(newZoomLevel
);
1317 emit
zoomLevelChanged(newZoomLevel
);
1321 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1323 KUrl::List list
= selectedUrls();
1324 if (itemsExpandable() ) {
1325 list
= KonqOperations::simplifiedUrlList(list
);
1330 bool DolphinView::itemsExpandable() const
1332 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1335 #include "dolphinview.moc"