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 <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 "dolphindropcontroller.h"
51 #include "dolphinmodel.h"
52 #include "dolphincolumnview.h"
53 #include "dolphincontroller.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 "folderexpander.h"
61 #include "iconmanager.h"
62 #include "renamedialog.h"
63 #include "tooltipmanager.h"
64 #include "viewproperties.h"
66 DolphinView::DolphinView(QWidget
* parent
,
68 KDirLister
* dirLister
,
69 DolphinModel
* dolphinModel
,
70 DolphinSortFilterProxyModel
* proxyModel
) :
74 m_loadingDirectory(false),
75 m_storedCategorizedSorting(false),
76 m_tabsForFiles(false),
77 m_isContextMenuOpen(false),
78 m_mode(DolphinView::IconsView
),
84 m_fileItemDelegate(0),
86 m_dolphinModel(dolphinModel
),
87 m_dirLister(dirLister
),
88 m_proxyModel(proxyModel
),
94 m_topLayout
= new QVBoxLayout(this);
95 m_topLayout
->setSpacing(0);
96 m_topLayout
->setMargin(0);
98 m_controller
= new DolphinController(this);
99 m_controller
->setUrl(url
);
101 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
102 this, SIGNAL(urlChanged(const KUrl
&)));
103 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
104 this, SLOT(slotRequestUrlChange(const KUrl
&)));
106 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
107 this, SLOT(openContextMenu(const QPoint
&)));
108 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
109 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
110 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
111 this, SLOT(updateSorting(DolphinView::Sorting
)));
112 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
113 this, SLOT(updateSortOrder(Qt::SortOrder
)));
114 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
115 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
116 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
117 this, SLOT(triggerItem(const KFileItem
&)));
118 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
119 this, SIGNAL(tabRequested(const KUrl
&)));
120 connect(m_controller
, SIGNAL(activated()),
121 this, SLOT(activate()));
122 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
123 this, SLOT(showHoverInformation(const KFileItem
&)));
124 connect(m_controller
, SIGNAL(viewportEntered()),
125 this, SLOT(clearHoverInformation()));
127 connect(m_dirLister
, SIGNAL(redirection(KUrl
, KUrl
)),
128 this, SLOT(slotRedirection(KUrl
, KUrl
)));
129 connect(m_dirLister
, SIGNAL(completed()),
130 this, SLOT(restoreCurrentItem()));
132 applyViewProperties(url
);
133 m_topLayout
->addWidget(itemView());
136 DolphinView::~DolphinView()
140 const KUrl
& DolphinView::url() const
142 return m_controller
->url();
145 KUrl
DolphinView::rootUrl() const
147 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
150 void DolphinView::setActive(bool active
)
152 if (active
== m_active
) {
158 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
160 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
161 // bypasses the problem when having a split view and changing the active view to
162 // update the some URL dependent states. A nicer approach should be no big deal...
163 emit
urlChanged(url());
164 emit
selectionChanged(selectedItems());
169 QWidget
* viewport
= itemView()->viewport();
171 palette
.setColor(viewport
->backgroundRole(), color
);
172 viewport
->setPalette(palette
);
177 itemView()->setFocus();
181 m_controller
->indicateActivationChange(active
);
184 bool DolphinView::isActive() const
189 void DolphinView::setMode(Mode mode
)
191 if (mode
== m_mode
) {
192 return; // the wished mode is already set
199 const KUrl viewPropsUrl
= viewPropertiesUrl();
200 ViewProperties
props(viewPropsUrl
);
201 props
.setViewMode(m_mode
);
204 // the file item delegate has been recreated, apply the current
205 // additional information manually
206 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
207 m_fileItemDelegate
->setShowInformation(infoList
);
208 emit
additionalInfoChanged();
210 // Not all view modes support categorized sorting. Adjust the sorting model
211 // if changing the view mode results in a change of the categorized sorting
213 m_storedCategorizedSorting
= props
.categorizedSorting();
214 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
215 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
216 m_proxyModel
->setCategorizedModel(categorized
);
217 emit
categorizedSortingChanged();
223 DolphinView::Mode
DolphinView::mode() const
228 bool DolphinView::showPreview() const
230 return m_showPreview
;
233 bool DolphinView::showHiddenFiles() const
235 return m_dirLister
->showingDotFiles();
238 bool DolphinView::categorizedSorting() const
240 // If all view modes would support categorized sorting, returning
241 // m_proxyModel->isCategorizedModel() would be the way to go. As
242 // currently only the icons view supports caterized sorting, we remember
243 // the stored view properties state in m_storedCategorizedSorting and
244 // return this state. The application takes care to disable the corresponding
245 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
246 // that this setting is not applied to the current view mode.
247 return m_storedCategorizedSorting
;
250 bool DolphinView::supportsCategorizedSorting() const
252 return m_iconsView
!= 0;
255 void DolphinView::selectAll()
257 QAbstractItemView
* view
= itemView();
258 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
259 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
260 // selection instead of selecting all items. This is bypassed for KDE 4.0
261 // by invoking clearSelection() first.
262 view
->clearSelection();
266 void DolphinView::invertSelection()
268 if (isColumnViewActive()) {
269 // QAbstractItemView does not offer a virtual method invertSelection()
270 // as counterpart to QAbstractItemView::selectAll(). This makes it
271 // necessary to delegate the inverting of the selection to the
272 // column view, as only the selection of the active column should
274 m_columnView
->invertSelection();
276 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
277 const QAbstractItemModel
* itemModel
= selectionModel
->model();
279 const QModelIndex topLeft
= itemModel
->index(0, 0);
280 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
281 itemModel
->columnCount() - 1);
283 const QItemSelection
selection(topLeft
, bottomRight
);
284 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
288 bool DolphinView::hasSelection() const
290 return itemView()->selectionModel()->hasSelection();
293 void DolphinView::clearSelection()
295 itemView()->selectionModel()->clear();
298 KFileItemList
DolphinView::selectedItems() const
300 if (isColumnViewActive()) {
301 return m_columnView
->selectedItems();
304 const QAbstractItemView
* view
= itemView();
306 // Our view has a selection, we will map them back to the DolphinModel
307 // and then fill the KFileItemList.
308 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
310 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
311 KFileItemList itemList
;
313 const QModelIndexList indexList
= selection
.indexes();
314 foreach (const QModelIndex
&index
, indexList
) {
315 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
316 if (!item
.isNull()) {
317 itemList
.append(item
);
324 KUrl::List
DolphinView::selectedUrls() const
327 const KFileItemList list
= selectedItems();
328 foreach (const KFileItem
&item
, list
) {
329 urls
.append(item
.url());
334 int DolphinView::selectedItemsCount() const
336 if (isColumnViewActive()) {
337 // TODO: get rid of this special case by adjusting the dir lister
338 // to the current column
339 return m_columnView
->selectedItems().count();
342 return itemView()->selectionModel()->selection().count();
345 void DolphinView::setContentsPosition(int x
, int y
)
347 QAbstractItemView
* view
= itemView();
349 // the ColumnView takes care itself for the horizontal scrolling
350 if (!isColumnViewActive()) {
351 view
->horizontalScrollBar()->setValue(x
);
353 view
->verticalScrollBar()->setValue(y
);
355 m_loadingDirectory
= false;
358 QPoint
DolphinView::contentsPosition() const
360 const int x
= itemView()->horizontalScrollBar()->value();
361 const int y
= itemView()->verticalScrollBar()->value();
365 void DolphinView::setZoomLevel(int level
)
367 if (level
< zoomLevelMinimum()) {
368 level
= zoomLevelMinimum();
369 } else if (level
> zoomLevelMaximum()) {
370 level
= zoomLevelMaximum();
373 if (level
!= zoomLevel()) {
374 m_controller
->setZoomLevel(level
);
375 m_iconManager
->updatePreviews();
376 emit
zoomLevelChanged(level
);
380 int DolphinView::zoomLevel() const
382 return m_controller
->zoomLevel();
385 int DolphinView::zoomLevelMinimum() const
387 return m_controller
->zoomLevelMinimum();
390 int DolphinView::zoomLevelMaximum() const
392 return m_controller
->zoomLevelMaximum();
395 void DolphinView::setSorting(Sorting sorting
)
397 if (sorting
!= this->sorting()) {
398 updateSorting(sorting
);
402 DolphinView::Sorting
DolphinView::sorting() const
404 return m_proxyModel
->sorting();
407 void DolphinView::setSortOrder(Qt::SortOrder order
)
409 if (sortOrder() != order
) {
410 updateSortOrder(order
);
414 Qt::SortOrder
DolphinView::sortOrder() const
416 return m_proxyModel
->sortOrder();
419 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
421 const KUrl viewPropsUrl
= viewPropertiesUrl();
422 ViewProperties
props(viewPropsUrl
);
423 props
.setAdditionalInfo(info
);
424 m_fileItemDelegate
->setShowInformation(info
);
426 emit
additionalInfoChanged();
428 if (itemView() != m_detailsView
) {
429 // the details view requires no reloading of the directory, as it maps
430 // the file item delegate info to its columns internally
431 loadDirectory(viewPropsUrl
);
435 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
437 return m_fileItemDelegate
->showInformation();
440 void DolphinView::reload()
443 loadDirectory(url(), true);
446 void DolphinView::refresh()
448 const bool oldActivationState
= m_active
;
452 applyViewProperties(m_controller
->url());
455 setActive(oldActivationState
);
458 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
460 if (m_controller
->url() == url
) {
464 m_iconManager
->cancelPreviews();
465 m_controller
->setUrl(url
); // emits urlChanged, which we forward
467 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
468 applyViewProperties(rootUrl
);
469 loadDirectory(rootUrl
);
470 if (itemView() == m_columnView
) {
471 m_columnView
->setRootUrl(rootUrl
);
472 m_columnView
->showColumn(url
);
475 applyViewProperties(url
);
479 emit
startedPathLoading(url
);
482 void DolphinView::setNameFilter(const QString
& nameFilter
)
484 m_proxyModel
->setFilterRegExp(nameFilter
);
486 if (isColumnViewActive()) {
487 // adjusting the directory lister is not enough in the case of the
488 // column view, as each column has its own directory lister internally...
489 m_columnView
->setNameFilter(nameFilter
);
493 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
495 foreach (const KFileItem
&item
, m_dirLister
->items()) {
504 void DolphinView::setUrl(const KUrl
& url
)
506 // remember current item candidate (see restoreCurrentItem())
507 m_currentItemUrl
= url
;
508 updateView(url
, KUrl());
511 void DolphinView::changeSelection(const KFileItemList
& selection
)
514 if (selection
.isEmpty()) {
517 const KUrl
& baseUrl
= url();
519 QItemSelection new_selection
;
520 foreach(const KFileItem
& item
, selection
) {
521 url
= item
.url().upUrl();
522 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
523 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
524 new_selection
.select(index
, index
);
527 itemView()->selectionModel()->select(new_selection
,
528 QItemSelectionModel::ClearAndSelect
529 | QItemSelectionModel::Current
);
532 void DolphinView::renameSelectedItems()
534 const KFileItemList items
= selectedItems();
535 const int itemCount
= items
.count();
541 // More than one item has been selected for renaming. Open
542 // a rename dialog and rename all items afterwards.
543 RenameDialog
dialog(this, items
);
544 if (dialog
.exec() == QDialog::Rejected
) {
548 const QString newName
= dialog
.newName();
549 if (newName
.isEmpty()) {
550 emit
errorMessage(dialog
.errorString());
552 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
553 // as one operation instead of n rename operations like it is done now...
554 Q_ASSERT(newName
.contains('#'));
556 // iterate through all selected items and rename them...
558 foreach (const KFileItem
&item
, items
) {
559 const KUrl
& oldUrl
= item
.url();
561 number
.setNum(index
++);
563 QString name
= newName
;
564 name
.replace('#', number
);
566 if (oldUrl
.fileName() != name
) {
567 KUrl newUrl
= oldUrl
;
568 newUrl
.setFileName(name
);
569 KonqOperations::rename(this, oldUrl
, newUrl
);
570 emit
doingOperation(KIO::FileUndoManager::Rename
);
574 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
575 Q_ASSERT(itemCount
== 1);
577 if (isColumnViewActive()) {
578 m_columnView
->editItem(items
.first());
580 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
581 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
582 itemView()->edit(proxyIndex
);
585 Q_ASSERT(itemCount
== 1);
587 RenameDialog
dialog(this, items
);
588 if (dialog
.exec() == QDialog::Rejected
) {
592 const QString
& newName
= dialog
.newName();
593 if (newName
.isEmpty()) {
594 emit
errorMessage(dialog
.errorString());
596 const KUrl
& oldUrl
= items
.first().url();
597 KUrl newUrl
= oldUrl
;
598 newUrl
.setFileName(newName
);
599 KonqOperations::rename(this, oldUrl
, newUrl
);
600 emit
doingOperation(KIO::FileUndoManager::Rename
);
605 void DolphinView::trashSelectedItems()
607 emit
doingOperation(KIO::FileUndoManager::Trash
);
608 const KUrl::List list
= simplifiedSelectedUrls();
609 KonqOperations::del(this, KonqOperations::TRASH
, list
);
612 void DolphinView::deleteSelectedItems()
614 const KUrl::List list
= simplifiedSelectedUrls();
615 const bool del
= KonqOperations::askDeleteConfirmation(list
,
617 KonqOperations::DEFAULT_CONFIRMATION
,
621 KIO::Job
* job
= KIO::del(list
);
622 connect(job
, SIGNAL(result(KJob
*)),
623 this, SLOT(slotDeleteFileFinished(KJob
*)));
627 void DolphinView::cutSelectedItems()
629 QMimeData
* mimeData
= new QMimeData();
630 const KUrl::List kdeUrls
= simplifiedSelectedUrls();
631 const KUrl::List mostLocalUrls
;
632 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
633 QApplication::clipboard()->setMimeData(mimeData
);
636 void DolphinView::copySelectedItems()
638 QMimeData
* mimeData
= new QMimeData();
639 const KUrl::List kdeUrls
= selectedUrls();
640 const KUrl::List mostLocalUrls
;
641 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
642 QApplication::clipboard()->setMimeData(mimeData
);
645 void DolphinView::paste()
650 void DolphinView::pasteIntoFolder()
652 const KFileItemList items
= selectedItems();
653 if ((items
.count() == 1) && items
.first().isDir()) {
654 pasteToUrl(items
.first().url());
658 void DolphinView::setShowPreview(bool show
)
660 if (m_showPreview
== show
) {
664 const KUrl viewPropsUrl
= viewPropertiesUrl();
665 ViewProperties
props(viewPropsUrl
);
666 props
.setShowPreview(show
);
668 m_showPreview
= show
;
669 m_iconManager
->setShowPreview(show
);
671 const int oldZoomLevel
= m_controller
->zoomLevel();
672 emit
showPreviewChanged();
674 // Enabling or disabling the preview might change the icon size of the view.
675 // As the view does not emit a signal when the icon size has been changed,
676 // the used zoom level of the controller must be adjusted manually:
677 updateZoomLevel(oldZoomLevel
);
679 loadDirectory(viewPropsUrl
);
682 void DolphinView::setShowHiddenFiles(bool show
)
684 if (m_dirLister
->showingDotFiles() == show
) {
688 const KUrl viewPropsUrl
= viewPropertiesUrl();
689 ViewProperties
props(viewPropsUrl
);
690 props
.setShowHiddenFiles(show
);
692 m_dirLister
->setShowingDotFiles(show
);
693 emit
showHiddenFilesChanged();
695 loadDirectory(viewPropsUrl
);
698 void DolphinView::setCategorizedSorting(bool categorized
)
700 if (categorized
== categorizedSorting()) {
704 // setCategorizedSorting(true) may only get invoked
705 // if the view supports categorized sorting
706 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
708 ViewProperties
props(viewPropertiesUrl());
709 props
.setCategorizedSorting(categorized
);
712 m_storedCategorizedSorting
= categorized
;
713 m_proxyModel
->setCategorizedModel(categorized
);
715 emit
categorizedSortingChanged();
718 void DolphinView::toggleSortOrder()
720 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
721 Qt::DescendingOrder
:
726 void DolphinView::toggleAdditionalInfo(QAction
* action
)
728 const KFileItemDelegate::Information info
=
729 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
731 KFileItemDelegate::InformationList list
= additionalInfo();
733 const bool show
= action
->isChecked();
735 const int index
= list
.indexOf(info
);
736 const bool containsInfo
= (index
>= 0);
737 if (show
&& !containsInfo
) {
739 setAdditionalInfo(list
);
740 } else if (!show
&& containsInfo
) {
741 list
.removeAt(index
);
742 setAdditionalInfo(list
);
743 Q_ASSERT(list
.indexOf(info
) < 0);
747 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
749 QWidget::mouseReleaseEvent(event
);
753 void DolphinView::wheelEvent(QWheelEvent
* event
)
755 if (event
->modifiers() & Qt::ControlModifier
) {
756 const int delta
= event
->delta();
757 const int level
= zoomLevel();
759 setZoomLevel(level
+ 1);
760 } else if (delta
< 0) {
761 setZoomLevel(level
- 1);
767 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
769 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
770 m_controller
->requestActivation();
773 return QWidget::eventFilter(watched
, event
);
776 void DolphinView::activate()
781 void DolphinView::triggerItem(const KFileItem
& item
)
783 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
784 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
785 // items are selected by the user, hence don't trigger the
786 // item specified by 'index'
790 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
791 if (item
.isNull() || m_isContextMenuOpen
) {
795 if (m_toolTipManager
!= 0) {
796 m_toolTipManager
->hideTip();
798 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
801 void DolphinView::emitSelectionChangedSignal()
803 emit
selectionChanged(DolphinView::selectedItems());
806 void DolphinView::openContextMenu(const QPoint
& pos
)
809 if (isColumnViewActive()) {
810 item
= m_columnView
->itemAt(pos
);
812 const QModelIndex index
= itemView()->indexAt(pos
);
813 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
814 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
815 item
= m_dolphinModel
->itemForIndex(dolphinModelIndex
);
819 if (m_toolTipManager
!= 0) {
820 m_toolTipManager
->hideTip();
823 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
824 emit
requestContextMenu(item
, url());
825 m_isContextMenuOpen
= false;
828 void DolphinView::dropUrls(const KUrl::List
& urls
,
829 const KUrl
& destPath
,
830 const KFileItem
& destItem
)
832 Q_ASSERT(!urls
.isEmpty());
833 const KUrl destination
= !destItem
.isNull() && destItem
.isDir() ?
834 destItem
.url() : destPath
;
835 const KUrl sourceDir
= KUrl(urls
.first().directory());
836 if (sourceDir
!= destination
) {
837 DolphinDropController
dropController(this);
838 // forward doingOperation signal up to the mainwindow
839 connect(&dropController
, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)),
840 this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)));
841 dropController
.dropUrls(urls
, destination
);
845 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
847 ViewProperties
props(viewPropertiesUrl());
848 props
.setSorting(sorting
);
850 m_proxyModel
->setSorting(sorting
);
852 emit
sortingChanged(sorting
);
855 void DolphinView::updateSortOrder(Qt::SortOrder order
)
857 ViewProperties
props(viewPropertiesUrl());
858 props
.setSortOrder(order
);
860 m_proxyModel
->setSortOrder(order
);
862 emit
sortOrderChanged(order
);
865 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
867 ViewProperties
props(viewPropertiesUrl());
868 props
.setAdditionalInfo(info
);
871 m_fileItemDelegate
->setShowInformation(info
);
873 emit
additionalInfoChanged();
876 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
878 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
879 (m_mode
== DolphinView::IconsView
);
881 QAction
* showSizeInfo
= collection
->action("show_size_info");
882 QAction
* showDateInfo
= collection
->action("show_date_info");
883 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
884 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
885 QAction
* showGroupInfo
= collection
->action("show_group_info");
886 QAction
* showMimeInfo
= collection
->action("show_mime_info");
888 showSizeInfo
->setChecked(false);
889 showDateInfo
->setChecked(false);
890 showPermissionsInfo
->setChecked(false);
891 showOwnerInfo
->setChecked(false);
892 showGroupInfo
->setChecked(false);
893 showMimeInfo
->setChecked(false);
895 showSizeInfo
->setEnabled(enable
);
896 showDateInfo
->setEnabled(enable
);
897 showPermissionsInfo
->setEnabled(enable
);
898 showOwnerInfo
->setEnabled(enable
);
899 showGroupInfo
->setEnabled(enable
);
900 showMimeInfo
->setEnabled(enable
);
902 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
904 case KFileItemDelegate::Size
:
905 showSizeInfo
->setChecked(true);
907 case KFileItemDelegate::ModificationTime
:
908 showDateInfo
->setChecked(true);
910 case KFileItemDelegate::Permissions
:
911 showPermissionsInfo
->setChecked(true);
913 case KFileItemDelegate::Owner
:
914 showOwnerInfo
->setChecked(true);
916 case KFileItemDelegate::OwnerAndGroup
:
917 showGroupInfo
->setChecked(true);
919 case KFileItemDelegate::FriendlyMimeType
:
920 showMimeInfo
->setChecked(true);
928 QPair
<bool, QString
> DolphinView::pasteInfo() const
930 QPair
<bool, QString
> ret
;
931 QClipboard
* clipboard
= QApplication::clipboard();
932 const QMimeData
* mimeData
= clipboard
->mimeData();
934 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
935 if (!urls
.isEmpty()) {
936 // disable the paste action if no writing is supported
937 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url());
938 ret
.first
= KonqFileItemCapabilities(KFileItemList() << item
).supportsWriting();
940 if (urls
.count() == 1) {
941 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
942 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
943 i18nc("@action:inmenu", "Paste One File");
946 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
950 ret
.second
= i18nc("@action:inmenu", "Paste");
956 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
958 m_tabsForFiles
= tabsForFiles
;
961 bool DolphinView::isTabsForFilesEnabled() const
963 return m_tabsForFiles
;
966 void DolphinView::emitContentsMoved()
968 // only emit the contents moved signal if:
969 // - no directory loading is ongoing (this would reset the contents position
971 // - if the Column View is active: the column view does an automatic
972 // positioning during the loading operation, which must be remembered
973 if (!m_loadingDirectory
|| isColumnViewActive()) {
974 const QPoint
pos(contentsPosition());
975 emit
contentsMoved(pos
.x(), pos
.y());
979 void DolphinView::showHoverInformation(const KFileItem
& item
)
981 emit
requestItemInfo(item
);
984 void DolphinView::clearHoverInformation()
986 emit
requestItemInfo(KFileItem());
989 void DolphinView::slotDeleteFileFinished(KJob
* job
)
991 if (job
->error() == 0) {
992 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
994 emit
errorMessage(job
->errorString());
998 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1000 if (oldUrl
== m_controller
->url()) {
1001 m_controller
->setUrl(newUrl
);
1005 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1007 emit
requestUrlChange(url
);
1008 m_controller
->setUrl(url
);
1011 void DolphinView::restoreCurrentItem()
1013 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
1014 if (dirIndex
.isValid()) {
1015 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
1016 QAbstractItemView
* view
= itemView();
1017 const bool clearSelection
= !hasSelection();
1018 view
->setCurrentIndex(proxyIndex
);
1019 if (clearSelection
) {
1020 view
->clearSelection();
1025 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1027 if (!url
.isValid()) {
1028 const QString
location(url
.pathOrUrl());
1029 if (location
.isEmpty()) {
1030 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1032 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1037 m_loadingDirectory
= true;
1039 m_dirLister
->stop();
1040 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1042 if (isColumnViewActive()) {
1043 // adjusting the directory lister is not enough in the case of the
1044 // column view, as each column has its own directory lister internally...
1046 m_columnView
->reload();
1048 m_columnView
->showColumn(url
);
1053 KUrl
DolphinView::viewPropertiesUrl() const
1055 if (isColumnViewActive()) {
1056 return m_columnView
->rootUrl();
1062 void DolphinView::applyViewProperties(const KUrl
& url
)
1064 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1065 // The column view is active, hence don't apply the view properties
1066 // of sub directories (represented by columns) to the view. The
1067 // view always represents the properties of the first column.
1071 const ViewProperties
props(url
);
1073 const Mode mode
= props
.viewMode();
1074 if (m_mode
!= mode
) {
1079 if (itemView() == 0) {
1082 Q_ASSERT(itemView() != 0);
1083 Q_ASSERT(m_fileItemDelegate
!= 0);
1085 const bool showHiddenFiles
= props
.showHiddenFiles();
1086 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1087 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1088 emit
showHiddenFilesChanged();
1091 m_storedCategorizedSorting
= props
.categorizedSorting();
1092 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1093 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1094 m_proxyModel
->setCategorizedModel(categorized
);
1095 emit
categorizedSortingChanged();
1098 const DolphinView::Sorting sorting
= props
.sorting();
1099 if (sorting
!= m_proxyModel
->sorting()) {
1100 m_proxyModel
->setSorting(sorting
);
1101 emit
sortingChanged(sorting
);
1104 const Qt::SortOrder sortOrder
= props
.sortOrder();
1105 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1106 m_proxyModel
->setSortOrder(sortOrder
);
1107 emit
sortOrderChanged(sortOrder
);
1110 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1111 if (info
!= m_fileItemDelegate
->showInformation()) {
1112 m_fileItemDelegate
->setShowInformation(info
);
1113 emit
additionalInfoChanged();
1116 const bool showPreview
= props
.showPreview();
1117 if (showPreview
!= m_showPreview
) {
1118 m_showPreview
= showPreview
;
1119 m_iconManager
->setShowPreview(showPreview
);
1121 const int oldZoomLevel
= m_controller
->zoomLevel();
1122 emit
showPreviewChanged();
1124 // Enabling or disabling the preview might change the icon size of the view.
1125 // As the view does not emit a signal when the icon size has been changed,
1126 // the used zoom level of the controller must be adjusted manually:
1127 updateZoomLevel(oldZoomLevel
);
1131 void DolphinView::createView()
1134 Q_ASSERT(m_iconsView
== 0);
1135 Q_ASSERT(m_detailsView
== 0);
1136 Q_ASSERT(m_columnView
== 0);
1138 QAbstractItemView
* view
= 0;
1141 m_iconsView
= new DolphinIconsView(this, m_controller
);
1147 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1148 view
= m_detailsView
;
1152 m_columnView
= new DolphinColumnView(this, m_controller
);
1153 view
= m_columnView
;
1157 Q_ASSERT(view
!= 0);
1158 view
->installEventFilter(this);
1160 if (m_mode
!= ColumnView
) {
1161 // Give the view the ability to auto-expand its directories on hovering
1162 // (the column view takes care about this itself). If the details view
1163 // uses expandable folders, the auto-expanding should be used always.
1164 DolphinSettings
& settings
= DolphinSettings::instance();
1165 const bool enabled
= settings
.generalSettings()->autoExpandFolders() ||
1166 ((m_detailsView
!= 0) && settings
.detailsModeSettings()->expandableFolders());
1168 FolderExpander
* folderExpander
= new FolderExpander(view
, m_proxyModel
);
1169 folderExpander
->setEnabled(enabled
);
1170 connect(folderExpander
, SIGNAL(enterDir(const QModelIndex
&)),
1171 m_controller
, SLOT(triggerItem(const QModelIndex
&)));
1174 m_controller
->setItemView(view
);
1176 m_fileItemDelegate
= new KFileItemDelegate(view
);
1177 view
->setItemDelegate(m_fileItemDelegate
);
1179 view
->setModel(m_proxyModel
);
1180 if (m_selectionModel
!= 0) {
1181 view
->setSelectionModel(m_selectionModel
);
1183 m_selectionModel
= view
->selectionModel();
1186 // reparent the selection model, as it should not be deleted
1187 // when deleting the model
1188 m_selectionModel
->setParent(this);
1190 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1192 m_iconManager
= new IconManager(view
, m_proxyModel
);
1193 m_iconManager
->setShowPreview(m_showPreview
);
1195 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1196 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1199 m_topLayout
->insertWidget(1, view
);
1201 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1202 this, SLOT(emitSelectionChangedSignal()));
1203 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1204 this, SLOT(emitContentsMoved()));
1205 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1206 this, SLOT(emitContentsMoved()));
1209 void DolphinView::deleteView()
1211 QAbstractItemView
* view
= itemView();
1213 // It's important to set the keyboard focus to the parent
1214 // before deleting the view: Otherwise when having a split
1215 // view the other view will get the focus and will request
1216 // an activation (see DolphinView::eventFilter()).
1219 m_topLayout
->removeWidget(view
);
1221 view
->deleteLater();
1226 m_fileItemDelegate
= 0;
1228 m_toolTipManager
= 0;
1232 QAbstractItemView
* DolphinView::itemView() const
1234 if (m_detailsView
!= 0) {
1235 return m_detailsView
;
1236 } else if (m_columnView
!= 0) {
1237 return m_columnView
;
1243 bool DolphinView::isCutItem(const KFileItem
& item
) const
1245 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1246 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1248 const KUrl
& itemUrl
= item
.url();
1249 KUrl::List::const_iterator it
= cutUrls
.begin();
1250 const KUrl::List::const_iterator end
= cutUrls
.end();
1252 if (*it
== itemUrl
) {
1261 void DolphinView::pasteToUrl(const KUrl
& url
)
1263 QClipboard
* clipboard
= QApplication::clipboard();
1264 const QMimeData
* mimeData
= clipboard
->mimeData();
1266 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1267 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1268 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1269 emit
doingOperation(KIO::FileUndoManager::Move
);
1272 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1273 emit
doingOperation(KIO::FileUndoManager::Copy
);
1277 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1279 const int newZoomLevel
= DolphinController::zoomLevelForIconSize(itemView()->iconSize());
1280 if (oldZoomLevel
!= newZoomLevel
) {
1281 m_controller
->setZoomLevel(newZoomLevel
);
1282 emit
zoomLevelChanged(newZoomLevel
);
1286 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1288 KUrl::List list
= selectedUrls();
1289 if ((m_detailsView
!= 0) && m_detailsView
->itemsExpandable()) {
1290 list
= KonqOperations::simplifiedUrlList(list
);
1295 #include "dolphinview.moc"