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_operations.h>
45 #include <konqmimedata.h>
46 #include <ktoggleaction.h>
49 #include "dolphindropcontroller.h"
50 #include "dolphinmodel.h"
51 #include "dolphincolumnview.h"
52 #include "dolphincontroller.h"
53 #include "dolphinsortfilterproxymodel.h"
54 #include "dolphindetailsview.h"
55 #include "dolphiniconsview.h"
56 #include "dolphinsettings.h"
57 #include "dolphin_generalsettings.h"
58 #include "iconmanager.h"
59 #include "renamedialog.h"
60 #include "viewproperties.h"
62 DolphinView::DolphinView(QWidget
* parent
,
64 KDirLister
* dirLister
,
65 DolphinModel
* dolphinModel
,
66 DolphinSortFilterProxyModel
* proxyModel
) :
70 m_loadingDirectory(false),
71 m_storedCategorizedSorting(false),
72 m_mode(DolphinView::IconsView
),
78 m_fileItemDelegate(0),
80 m_dolphinModel(dolphinModel
),
81 m_dirLister(dirLister
),
82 m_proxyModel(proxyModel
),
85 setFocusPolicy(Qt::StrongFocus
);
86 m_topLayout
= new QVBoxLayout(this);
87 m_topLayout
->setSpacing(0);
88 m_topLayout
->setMargin(0);
90 m_controller
= new DolphinController(this);
91 m_controller
->setUrl(url
);
93 // Receiver of the DolphinView signal 'urlChanged()' don't need
94 // to care whether the internal controller changed the URL already or whether
95 // the controller just requested an URL change and will be updated later.
96 // In both cases the URL has been changed:
97 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
98 this, SIGNAL(urlChanged(const KUrl
&)));
99 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
100 this, SIGNAL(urlChanged(const KUrl
&)));
102 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
103 this, SLOT(openContextMenu(const QPoint
&)));
104 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
105 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
106 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
107 this, SLOT(updateSorting(DolphinView::Sorting
)));
108 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
109 this, SLOT(updateSortOrder(Qt::SortOrder
)));
110 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
111 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
112 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
113 this, SLOT(triggerItem(const KFileItem
&)));
114 connect(m_controller
, SIGNAL(activated()),
115 this, SLOT(activate()));
116 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
117 this, SLOT(showHoverInformation(const KFileItem
&)));
118 connect(m_controller
, SIGNAL(viewportEntered()),
119 this, SLOT(clearHoverInformation()));
121 applyViewProperties(url
);
122 m_topLayout
->addWidget(itemView());
125 DolphinView::~DolphinView()
129 const KUrl
& DolphinView::url() const
131 return m_controller
->url();
134 KUrl
DolphinView::rootUrl() const
136 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
139 void DolphinView::setActive(bool active
)
141 if (active
== m_active
) {
146 m_selectionModel
->clearSelection();
148 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
150 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
151 // bypasses the problem when having a split view and changing the active view to
152 // update the some URL dependent states. A nicer approach should be no big deal...
153 emit
urlChanged(url());
154 emit
selectionChanged(selectedItems());
159 QWidget
* viewport
= itemView()->viewport();
161 palette
.setColor(viewport
->backgroundRole(), color
);
162 viewport
->setPalette(palette
);
170 m_controller
->indicateActivationChange(active
);
173 bool DolphinView::isActive() const
178 void DolphinView::setMode(Mode mode
)
180 if (mode
== m_mode
) {
181 return; // the wished mode is already set
188 const KUrl viewPropsUrl
= viewPropertiesUrl();
189 ViewProperties
props(viewPropsUrl
);
190 props
.setViewMode(m_mode
);
193 // the file item delegate has been recreated, apply the current
194 // additional information manually
195 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
196 m_fileItemDelegate
->setShowInformation(infoList
);
197 emit
additionalInfoChanged();
199 // Not all view modes support categorized sorting. Adjust the sorting model
200 // if changing the view mode results in a change of the categorized sorting
202 m_storedCategorizedSorting
= props
.categorizedSorting();
203 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
204 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
205 m_proxyModel
->setCategorizedModel(categorized
);
206 emit
categorizedSortingChanged();
212 DolphinView::Mode
DolphinView::mode() const
217 bool DolphinView::showPreview() const
219 return m_showPreview
;
222 bool DolphinView::showHiddenFiles() const
224 return m_dirLister
->showingDotFiles();
227 bool DolphinView::categorizedSorting() const
229 // If all view modes would support categorized sorting, returning
230 // m_proxyModel->isCategorizedModel() would be the way to go. As
231 // currently only the icons view supports caterized sorting, we remember
232 // the stored view properties state in m_storedCategorizedSorting and
233 // return this state. The application takes care to disable the corresponding
234 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
235 // that this setting is not applied to the current view mode.
236 return m_storedCategorizedSorting
;
239 bool DolphinView::supportsCategorizedSorting() const
241 return m_iconsView
!= 0;
244 void DolphinView::selectAll()
246 QAbstractItemView
* view
= itemView();
247 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
248 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
249 // selection instead of selecting all items. This is bypassed for KDE 4.0
250 // by invoking clearSelection() first.
251 view
->clearSelection();
255 void DolphinView::invertSelection()
257 if (isColumnViewActive()) {
258 // QAbstractItemView does not offer a virtual method invertSelection()
259 // as counterpart to QAbstractItemView::selectAll(). This makes it
260 // necessary to delegate the inverting of the selection to the
261 // column view, as only the selection of the active column should
263 m_columnView
->invertSelection();
265 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
266 const QAbstractItemModel
* itemModel
= selectionModel
->model();
268 const QModelIndex topLeft
= itemModel
->index(0, 0);
269 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
270 itemModel
->columnCount() - 1);
272 const QItemSelection
selection(topLeft
, bottomRight
);
273 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
277 bool DolphinView::hasSelection() const
279 return itemView()->selectionModel()->hasSelection();
282 void DolphinView::clearSelection()
284 itemView()->selectionModel()->clear();
287 KFileItemList
DolphinView::selectedItems() const
289 const QAbstractItemView
* view
= itemView();
291 // Our view has a selection, we will map them back to the DolphinModel
292 // and then fill the KFileItemList.
293 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
295 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
296 KFileItemList itemList
;
298 const QModelIndexList indexList
= selection
.indexes();
299 foreach (QModelIndex index
, indexList
) {
300 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
301 if (!item
.isNull()) {
302 itemList
.append(item
);
309 KUrl::List
DolphinView::selectedUrls() const
312 const KFileItemList list
= selectedItems();
313 foreach (KFileItem item
, list
) {
314 urls
.append(item
.url());
319 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
321 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
322 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
325 void DolphinView::setContentsPosition(int x
, int y
)
327 QAbstractItemView
* view
= itemView();
329 // the ColumnView takes care itself for the horizontal scrolling
330 if (!isColumnViewActive()) {
331 view
->horizontalScrollBar()->setValue(x
);
333 view
->verticalScrollBar()->setValue(y
);
335 m_loadingDirectory
= false;
338 QPoint
DolphinView::contentsPosition() const
340 const int x
= itemView()->horizontalScrollBar()->value();
341 const int y
= itemView()->verticalScrollBar()->value();
345 void DolphinView::zoomIn()
347 m_controller
->triggerZoomIn();
348 m_iconManager
->updatePreviews();
351 void DolphinView::zoomOut()
353 m_controller
->triggerZoomOut();
354 m_iconManager
->updatePreviews();
357 bool DolphinView::isZoomInPossible() const
359 return m_controller
->isZoomInPossible();
362 bool DolphinView::isZoomOutPossible() const
364 return m_controller
->isZoomOutPossible();
367 void DolphinView::setSorting(Sorting sorting
)
369 if (sorting
!= this->sorting()) {
370 updateSorting(sorting
);
374 DolphinView::Sorting
DolphinView::sorting() const
376 return m_proxyModel
->sorting();
379 void DolphinView::setSortOrder(Qt::SortOrder order
)
381 if (sortOrder() != order
) {
382 updateSortOrder(order
);
386 Qt::SortOrder
DolphinView::sortOrder() const
388 return m_proxyModel
->sortOrder();
391 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
393 const KUrl viewPropsUrl
= viewPropertiesUrl();
394 ViewProperties
props(viewPropsUrl
);
395 props
.setAdditionalInfo(info
);
396 m_fileItemDelegate
->setShowInformation(info
);
398 emit
additionalInfoChanged();
400 if (itemView() != m_detailsView
) {
401 // the details view requires no reloading of the directory, as it maps
402 // the file item delegate info to its columns internally
403 loadDirectory(viewPropsUrl
);
407 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
409 return m_fileItemDelegate
->showInformation();
412 void DolphinView::reload()
415 loadDirectory(url(), true);
418 void DolphinView::refresh()
420 const bool oldActivationState
= m_active
;
424 applyViewProperties(m_controller
->url());
427 setActive(oldActivationState
);
430 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
432 if (m_controller
->url() == url
) {
436 m_controller
->setUrl(url
); // emits urlChanged, which we forward
438 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
439 applyViewProperties(rootUrl
);
440 loadDirectory(rootUrl
);
441 if (itemView() == m_columnView
) {
442 m_columnView
->setRootUrl(rootUrl
);
443 m_columnView
->showColumn(url
);
446 applyViewProperties(url
);
450 emit
startedPathLoading(url
);
453 void DolphinView::setNameFilter(const QString
& nameFilter
)
455 m_proxyModel
->setFilterRegExp(nameFilter
);
457 if (isColumnViewActive()) {
458 // adjusting the directory lister is not enough in the case of the
459 // column view, as each column has its own directory lister internally...
460 m_columnView
->setNameFilter(nameFilter
);
464 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
466 foreach (KFileItem item
, m_dirLister
->items()) {
475 void DolphinView::setUrl(const KUrl
& url
)
477 updateView(url
, KUrl());
480 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
482 QWidget::mouseReleaseEvent(event
);
486 void DolphinView::wheelEvent(QWheelEvent
* event
)
488 if (event
->modifiers() & Qt::ControlModifier
) {
489 const int delta
= event
->delta();
490 if ((delta
> 0) && isZoomInPossible()) {
492 } else if ((delta
< 0) && isZoomOutPossible()) {
499 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
501 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
502 m_controller
->requestActivation();
505 return QWidget::eventFilter(watched
, event
);
508 void DolphinView::activate()
513 void DolphinView::triggerItem(const KFileItem
& item
)
515 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
516 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
517 // items are selected by the user, hence don't trigger the
518 // item specified by 'index'
526 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
529 void DolphinView::emitSelectionChangedSignal()
531 emit
selectionChanged(DolphinView::selectedItems());
534 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
536 if (!url
.isValid()) {
537 const QString
location(url
.pathOrUrl());
538 if (location
.isEmpty()) {
539 emit
errorMessage(i18nc("@info:status", "The location is empty."));
541 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
546 m_loadingDirectory
= true;
549 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
551 if (isColumnViewActive()) {
552 // adjusting the directory lister is not enough in the case of the
553 // column view, as each column has its own directory lister internally...
555 m_columnView
->reload();
557 m_columnView
->showColumn(url
);
562 KUrl
DolphinView::viewPropertiesUrl() const
564 if (isColumnViewActive()) {
565 return m_columnView
->rootUrl();
571 void DolphinView::applyViewProperties(const KUrl
& url
)
573 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
574 // The column view is active, hence don't apply the view properties
575 // of sub directories (represented by columns) to the view. The
576 // view always represents the properties of the first column.
580 const ViewProperties
props(url
);
582 const Mode mode
= props
.viewMode();
583 if (m_mode
!= mode
) {
588 if (itemView() == 0) {
591 Q_ASSERT(itemView() != 0);
592 Q_ASSERT(m_fileItemDelegate
!= 0);
594 const bool showHiddenFiles
= props
.showHiddenFiles();
595 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
596 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
597 emit
showHiddenFilesChanged();
600 m_storedCategorizedSorting
= props
.categorizedSorting();
601 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
602 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
603 m_proxyModel
->setCategorizedModel(categorized
);
604 emit
categorizedSortingChanged();
607 const DolphinView::Sorting sorting
= props
.sorting();
608 if (sorting
!= m_proxyModel
->sorting()) {
609 m_proxyModel
->setSorting(sorting
);
610 emit
sortingChanged(sorting
);
613 const Qt::SortOrder sortOrder
= props
.sortOrder();
614 if (sortOrder
!= m_proxyModel
->sortOrder()) {
615 m_proxyModel
->setSortOrder(sortOrder
);
616 emit
sortOrderChanged(sortOrder
);
619 KFileItemDelegate::InformationList info
= props
.additionalInfo();
620 if (info
!= m_fileItemDelegate
->showInformation()) {
621 m_fileItemDelegate
->setShowInformation(info
);
622 emit
additionalInfoChanged();
625 const bool showPreview
= props
.showPreview();
626 if (showPreview
!= m_showPreview
) {
627 m_showPreview
= showPreview
;
628 m_iconManager
->setShowPreview(showPreview
);
629 emit
showPreviewChanged();
633 void DolphinView::changeSelection(const KFileItemList
& selection
)
636 if (selection
.isEmpty()) {
639 const KUrl
& baseUrl
= url();
641 QItemSelection new_selection
;
642 foreach(const KFileItem
& item
, selection
) {
643 url
= item
.url().upUrl();
644 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
645 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
646 new_selection
.select(index
, index
);
649 itemView()->selectionModel()->select(new_selection
,
650 QItemSelectionModel::ClearAndSelect
651 | QItemSelectionModel::Current
);
654 void DolphinView::openContextMenu(const QPoint
& pos
)
658 const QModelIndex index
= itemView()->indexAt(pos
);
659 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
660 item
= fileItem(index
);
663 emit
requestContextMenu(item
, url());
666 void DolphinView::dropUrls(const KUrl::List
& urls
,
667 const KUrl
& destPath
,
668 const KFileItem
& destItem
)
670 Q_ASSERT(!urls
.isEmpty());
671 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
672 destItem
.url() : destPath
;
673 const KUrl sourceDir
= KUrl(urls
.first().directory());
674 if (sourceDir
!= destination
) {
675 dropUrls(urls
, destination
);
679 void DolphinView::dropUrls(const KUrl::List
& urls
,
680 const KUrl
& destination
)
682 DolphinDropController
dropController(this);
683 // forward doingOperation signal up to the mainwindow
684 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
685 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
686 dropController
.dropUrls(urls
, destination
);
689 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
691 ViewProperties
props(viewPropertiesUrl());
692 props
.setSorting(sorting
);
694 m_proxyModel
->setSorting(sorting
);
696 emit
sortingChanged(sorting
);
699 void DolphinView::updateSortOrder(Qt::SortOrder order
)
701 ViewProperties
props(viewPropertiesUrl());
702 props
.setSortOrder(order
);
704 m_proxyModel
->setSortOrder(order
);
706 emit
sortOrderChanged(order
);
709 void DolphinView::toggleSortOrder()
711 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
712 Qt::DescendingOrder
:
717 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
719 ViewProperties
props(viewPropertiesUrl());
720 props
.setAdditionalInfo(info
);
723 m_fileItemDelegate
->setShowInformation(info
);
725 emit
additionalInfoChanged();
728 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
730 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
731 (m_mode
== DolphinView::IconsView
);
733 QAction
* showSizeInfo
= collection
->action("show_size_info");
734 QAction
* showDateInfo
= collection
->action("show_date_info");
735 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
736 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
737 QAction
* showGroupInfo
= collection
->action("show_group_info");
738 QAction
* showMimeInfo
= collection
->action("show_mime_info");
740 showSizeInfo
->setChecked(false);
741 showDateInfo
->setChecked(false);
742 showPermissionsInfo
->setChecked(false);
743 showOwnerInfo
->setChecked(false);
744 showGroupInfo
->setChecked(false);
745 showMimeInfo
->setChecked(false);
747 showSizeInfo
->setEnabled(enable
);
748 showDateInfo
->setEnabled(enable
);
749 showPermissionsInfo
->setEnabled(enable
);
750 showOwnerInfo
->setEnabled(enable
);
751 showGroupInfo
->setEnabled(enable
);
752 showMimeInfo
->setEnabled(enable
);
754 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
756 case KFileItemDelegate::Size
:
757 showSizeInfo
->setChecked(true);
759 case KFileItemDelegate::ModificationTime
:
760 showDateInfo
->setChecked(true);
762 case KFileItemDelegate::Permissions
:
763 showPermissionsInfo
->setChecked(true);
765 case KFileItemDelegate::Owner
:
766 showOwnerInfo
->setChecked(true);
768 case KFileItemDelegate::OwnerAndGroup
:
769 showGroupInfo
->setChecked(true);
771 case KFileItemDelegate::FriendlyMimeType
:
772 showMimeInfo
->setChecked(true);
780 void DolphinView::toggleAdditionalInfo(QAction
* action
)
782 const KFileItemDelegate::Information info
=
783 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
785 KFileItemDelegate::InformationList list
= additionalInfo();
787 const bool show
= action
->isChecked();
789 const int index
= list
.indexOf(info
);
790 const bool containsInfo
= (index
>= 0);
791 if (show
&& !containsInfo
) {
793 setAdditionalInfo(list
);
794 } else if (!show
&& containsInfo
) {
795 list
.removeAt(index
);
796 setAdditionalInfo(list
);
797 Q_ASSERT(list
.indexOf(info
) < 0);
801 void DolphinView::emitContentsMoved()
803 // only emit the contents moved signal if:
804 // - no directory loading is ongoing (this would reset the contents position
806 // - if the Column View is active: the column view does an automatic
807 // positioning during the loading operation, which must be remembered
808 if (!m_loadingDirectory
|| isColumnViewActive()) {
809 const QPoint
pos(contentsPosition());
810 emit
contentsMoved(pos
.x(), pos
.y());
814 void DolphinView::showHoverInformation(const KFileItem
& item
)
816 emit
requestItemInfo(item
);
819 void DolphinView::clearHoverInformation()
821 emit
requestItemInfo(KFileItem());
824 void DolphinView::createView()
827 Q_ASSERT(m_iconsView
== 0);
828 Q_ASSERT(m_detailsView
== 0);
829 Q_ASSERT(m_columnView
== 0);
831 QAbstractItemView
* view
= 0;
834 m_iconsView
= new DolphinIconsView(this, m_controller
);
840 m_detailsView
= new DolphinDetailsView(this, m_controller
);
841 view
= m_detailsView
;
845 m_columnView
= new DolphinColumnView(this, m_controller
);
851 view
->installEventFilter(this);
853 m_controller
->setItemView(view
);
855 m_fileItemDelegate
= new KFileItemDelegate(view
);
856 view
->setItemDelegate(m_fileItemDelegate
);
858 view
->setModel(m_proxyModel
);
859 if (m_selectionModel
!= 0) {
860 view
->setSelectionModel(m_selectionModel
);
862 m_selectionModel
= view
->selectionModel();
865 // reparent the selection model, as it should not be deleted
866 // when deleting the model
867 m_selectionModel
->setParent(this);
869 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
871 new KMimeTypeResolver(view
, m_dolphinModel
);
872 m_iconManager
= new IconManager(view
, m_proxyModel
);
873 m_iconManager
->setShowPreview(m_showPreview
);
875 m_topLayout
->insertWidget(1, view
);
877 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
878 this, SLOT(emitSelectionChangedSignal()));
879 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
880 this, SLOT(emitContentsMoved()));
881 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
882 this, SLOT(emitContentsMoved()));
885 void DolphinView::deleteView()
887 QAbstractItemView
* view
= itemView();
889 m_topLayout
->removeWidget(view
);
896 m_fileItemDelegate
= 0;
901 QAbstractItemView
* DolphinView::itemView() const
903 if (m_detailsView
!= 0) {
904 return m_detailsView
;
905 } else if (m_columnView
!= 0) {
912 bool DolphinView::isCutItem(const KFileItem
& item
) const
914 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
915 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
917 const KUrl
& itemUrl
= item
.url();
918 KUrl::List::const_iterator it
= cutUrls
.begin();
919 const KUrl::List::const_iterator end
= cutUrls
.end();
921 if (*it
== itemUrl
) {
930 void DolphinView::renameSelectedItems()
932 const KFileItemList items
= selectedItems();
933 if (items
.count() > 1) {
934 // More than one item has been selected for renaming. Open
935 // a rename dialog and rename all items afterwards.
936 RenameDialog
dialog(this, items
);
937 if (dialog
.exec() == QDialog::Rejected
) {
941 const QString newName
= dialog
.newName();
942 if (newName
.isEmpty()) {
943 emit
errorMessage(dialog
.errorString());
945 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
946 // as one operation instead of n rename operations like it is done now...
947 Q_ASSERT(newName
.contains('#'));
949 // iterate through all selected items and rename them...
951 foreach (KFileItem item
, items
) {
952 const KUrl
& oldUrl
= item
.url();
954 number
.setNum(index
++);
956 QString name
= newName
;
957 name
.replace('#', number
);
959 if (oldUrl
.fileName() != name
) {
960 KUrl newUrl
= oldUrl
;
961 newUrl
.setFileName(name
);
962 KonqOperations::rename(this, oldUrl
, newUrl
);
963 emit
doingOperation(KonqFileUndoManager::RENAME
);
967 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
968 Q_ASSERT(items
.count() == 1);
970 if (isColumnViewActive()) {
971 m_columnView
->editItem(items
.first());
973 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
974 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
975 itemView()->edit(proxyIndex
);
978 Q_ASSERT(items
.count() == 1);
980 RenameDialog
dialog(this, items
);
981 if (dialog
.exec() == QDialog::Rejected
) {
985 const QString
& newName
= dialog
.newName();
986 if (newName
.isEmpty()) {
987 emit
errorMessage(dialog
.errorString());
989 const KUrl
& oldUrl
= items
.first().url();
990 KUrl newUrl
= oldUrl
;
991 newUrl
.setFileName(newName
);
992 KonqOperations::rename(this, oldUrl
, newUrl
);
993 emit
doingOperation(KonqFileUndoManager::RENAME
);
998 void DolphinView::trashSelectedItems()
1000 emit
doingOperation(KonqFileUndoManager::TRASH
);
1001 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
1004 void DolphinView::deleteSelectedItems()
1006 const KUrl::List list
= selectedUrls();
1007 const bool del
= KonqOperations::askDeleteConfirmation(list
,
1008 KonqOperations::DEL
,
1009 KonqOperations::DEFAULT_CONFIRMATION
,
1013 KIO::Job
* job
= KIO::del(list
);
1014 connect(job
, SIGNAL(result(KJob
*)),
1015 this, SLOT(slotDeleteFileFinished(KJob
*)));
1019 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1021 if (job
->error() == 0) {
1022 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1024 emit
errorMessage(job
->errorString());
1028 void DolphinView::cutSelectedItems()
1030 QMimeData
* mimeData
= new QMimeData();
1031 const KUrl::List kdeUrls
= selectedUrls();
1032 const KUrl::List mostLocalUrls
;
1033 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
1034 QApplication::clipboard()->setMimeData(mimeData
);
1037 void DolphinView::copySelectedItems()
1039 QMimeData
* mimeData
= new QMimeData();
1040 const KUrl::List kdeUrls
= selectedUrls();
1041 const KUrl::List mostLocalUrls
;
1042 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
1043 QApplication::clipboard()->setMimeData(mimeData
);
1046 void DolphinView::paste()
1048 QClipboard
* clipboard
= QApplication::clipboard();
1049 const QMimeData
* mimeData
= clipboard
->mimeData();
1051 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1052 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1053 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url());
1054 emit
doingOperation(KonqFileUndoManager::MOVE
);
1057 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url());
1058 emit
doingOperation(KonqFileUndoManager::COPY
);
1062 void DolphinView::setShowPreview(bool show
)
1064 if (m_showPreview
== show
) {
1068 const KUrl viewPropsUrl
= viewPropertiesUrl();
1069 ViewProperties
props(viewPropsUrl
);
1070 props
.setShowPreview(show
);
1072 m_showPreview
= show
;
1073 m_iconManager
->setShowPreview(show
);
1074 emit
showPreviewChanged();
1076 loadDirectory(viewPropsUrl
);
1079 void DolphinView::setShowHiddenFiles(bool show
)
1081 if (m_dirLister
->showingDotFiles() == show
) {
1085 const KUrl viewPropsUrl
= viewPropertiesUrl();
1086 ViewProperties
props(viewPropsUrl
);
1087 props
.setShowHiddenFiles(show
);
1089 m_dirLister
->setShowingDotFiles(show
);
1090 emit
showHiddenFilesChanged();
1092 loadDirectory(viewPropsUrl
);
1095 void DolphinView::setCategorizedSorting(bool categorized
)
1097 if (categorized
== categorizedSorting()) {
1101 // setCategorizedSorting(true) may only get invoked
1102 // if the view supports categorized sorting
1103 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
1105 ViewProperties
props(viewPropertiesUrl());
1106 props
.setCategorizedSorting(categorized
);
1109 m_storedCategorizedSorting
= categorized
;
1110 m_proxyModel
->setCategorizedModel(categorized
);
1112 emit
categorizedSortingChanged();
1115 QPair
<bool, QString
> DolphinView::pasteInfo() const
1117 QPair
<bool, QString
> ret
;
1118 QClipboard
* clipboard
= QApplication::clipboard();
1119 const QMimeData
* mimeData
= clipboard
->mimeData();
1121 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1122 if (!urls
.isEmpty()) {
1124 if (urls
.count() == 1) {
1125 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
1126 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
1127 i18nc("@action:inmenu", "Paste One File");
1130 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
1134 ret
.second
= i18nc("@action:inmenu", "Paste");
1140 #include "dolphinview.moc"