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 void DolphinView::setShowPreview(bool show
)
219 if (m_showPreview
== show
) {
223 const KUrl viewPropsUrl
= viewPropertiesUrl();
224 ViewProperties
props(viewPropsUrl
);
225 props
.setShowPreview(show
);
227 m_showPreview
= show
;
228 m_iconManager
->setShowPreview(show
);
229 emit
showPreviewChanged();
231 loadDirectory(viewPropsUrl
);
234 bool DolphinView::showPreview() const
236 return m_showPreview
;
239 void DolphinView::setShowHiddenFiles(bool show
)
241 if (m_dirLister
->showingDotFiles() == show
) {
245 const KUrl viewPropsUrl
= viewPropertiesUrl();
246 ViewProperties
props(viewPropsUrl
);
247 props
.setShowHiddenFiles(show
);
249 m_dirLister
->setShowingDotFiles(show
);
250 emit
showHiddenFilesChanged();
252 loadDirectory(viewPropsUrl
);
255 bool DolphinView::showHiddenFiles() const
257 return m_dirLister
->showingDotFiles();
260 void DolphinView::setCategorizedSorting(bool categorized
)
262 if (categorized
== categorizedSorting()) {
266 // setCategorizedSorting(true) may only get invoked
267 // if the view supports categorized sorting
268 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
270 ViewProperties
props(viewPropertiesUrl());
271 props
.setCategorizedSorting(categorized
);
274 m_storedCategorizedSorting
= categorized
;
275 m_proxyModel
->setCategorizedModel(categorized
);
277 emit
categorizedSortingChanged();
280 bool DolphinView::categorizedSorting() const
282 // If all view modes would support categorized sorting, returning
283 // m_proxyModel->isCategorizedModel() would be the way to go. As
284 // currently only the icons view supports caterized sorting, we remember
285 // the stored view properties state in m_storedCategorizedSorting and
286 // return this state. The application takes care to disable the corresponding
287 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
288 // that this setting is not applied to the current view mode.
289 return m_storedCategorizedSorting
;
292 bool DolphinView::supportsCategorizedSorting() const
294 return m_iconsView
!= 0;
297 void DolphinView::selectAll()
299 QAbstractItemView
* view
= itemView();
300 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
301 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
302 // selection instead of selecting all items. This is bypassed for KDE 4.0
303 // by invoking clearSelection() first.
304 view
->clearSelection();
308 void DolphinView::invertSelection()
310 if (isColumnViewActive()) {
311 // QAbstractItemView does not offer a virtual method invertSelection()
312 // as counterpart to QAbstractItemView::selectAll(). This makes it
313 // necessary to delegate the inverting of the selection to the
314 // column view, as only the selection of the active column should
316 m_columnView
->invertSelection();
318 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
319 const QAbstractItemModel
* itemModel
= selectionModel
->model();
321 const QModelIndex topLeft
= itemModel
->index(0, 0);
322 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
323 itemModel
->columnCount() - 1);
325 const QItemSelection
selection(topLeft
, bottomRight
);
326 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
330 bool DolphinView::hasSelection() const
332 return itemView()->selectionModel()->hasSelection();
335 void DolphinView::clearSelection()
337 itemView()->selectionModel()->clear();
340 KFileItemList
DolphinView::selectedItems() const
342 const QAbstractItemView
* view
= itemView();
344 // Our view has a selection, we will map them back to the DolphinModel
345 // and then fill the KFileItemList.
346 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
348 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
349 KFileItemList itemList
;
351 const QModelIndexList indexList
= selection
.indexes();
352 foreach (QModelIndex index
, indexList
) {
353 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
354 if (!item
.isNull()) {
355 itemList
.append(item
);
362 KUrl::List
DolphinView::selectedUrls() const
365 const KFileItemList list
= selectedItems();
366 foreach (KFileItem item
, list
) {
367 urls
.append(item
.url());
372 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
374 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
375 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
378 void DolphinView::setContentsPosition(int x
, int y
)
380 QAbstractItemView
* view
= itemView();
382 // the ColumnView takes care itself for the horizontal scrolling
383 if (!isColumnViewActive()) {
384 view
->horizontalScrollBar()->setValue(x
);
386 view
->verticalScrollBar()->setValue(y
);
388 m_loadingDirectory
= false;
391 QPoint
DolphinView::contentsPosition() const
393 const int x
= itemView()->horizontalScrollBar()->value();
394 const int y
= itemView()->verticalScrollBar()->value();
398 void DolphinView::zoomIn()
400 m_controller
->triggerZoomIn();
401 m_iconManager
->updatePreviews();
404 void DolphinView::zoomOut()
406 m_controller
->triggerZoomOut();
407 m_iconManager
->updatePreviews();
410 bool DolphinView::isZoomInPossible() const
412 return m_controller
->isZoomInPossible();
415 bool DolphinView::isZoomOutPossible() const
417 return m_controller
->isZoomOutPossible();
420 void DolphinView::setSorting(Sorting sorting
)
422 if (sorting
!= this->sorting()) {
423 updateSorting(sorting
);
427 DolphinView::Sorting
DolphinView::sorting() const
429 return m_proxyModel
->sorting();
432 void DolphinView::setSortOrder(Qt::SortOrder order
)
434 if (sortOrder() != order
) {
435 updateSortOrder(order
);
439 Qt::SortOrder
DolphinView::sortOrder() const
441 return m_proxyModel
->sortOrder();
444 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
446 const KUrl viewPropsUrl
= viewPropertiesUrl();
447 ViewProperties
props(viewPropsUrl
);
448 props
.setAdditionalInfo(info
);
449 m_fileItemDelegate
->setShowInformation(info
);
451 emit
additionalInfoChanged();
453 if (itemView() != m_detailsView
) {
454 // the details view requires no reloading of the directory, as it maps
455 // the file item delegate info to its columns internally
456 loadDirectory(viewPropsUrl
);
460 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
462 return m_fileItemDelegate
->showInformation();
465 void DolphinView::reload()
468 loadDirectory(url(), true);
471 void DolphinView::refresh()
473 const bool oldActivationState
= m_active
;
477 applyViewProperties(m_controller
->url());
480 setActive(oldActivationState
);
483 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
485 if (m_controller
->url() == url
) {
489 m_controller
->setUrl(url
); // emits urlChanged, which we forward
491 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
492 applyViewProperties(rootUrl
);
493 loadDirectory(rootUrl
);
494 if (itemView() == m_columnView
) {
495 m_columnView
->setRootUrl(rootUrl
);
496 m_columnView
->showColumn(url
);
499 applyViewProperties(url
);
503 emit
startedPathLoading(url
);
506 void DolphinView::setNameFilter(const QString
& nameFilter
)
508 m_proxyModel
->setFilterRegExp(nameFilter
);
510 if (isColumnViewActive()) {
511 // adjusting the directory lister is not enough in the case of the
512 // column view, as each column has its own directory lister internally...
513 m_columnView
->setNameFilter(nameFilter
);
517 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
519 foreach (KFileItem item
, m_dirLister
->items()) {
528 void DolphinView::setUrl(const KUrl
& url
)
530 updateView(url
, KUrl());
533 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
535 QWidget::mouseReleaseEvent(event
);
539 void DolphinView::wheelEvent(QWheelEvent
* event
)
541 if (event
->modifiers() & Qt::ControlModifier
) {
542 const int delta
= event
->delta();
543 if ((delta
> 0) && isZoomInPossible()) {
545 } else if ((delta
< 0) && isZoomOutPossible()) {
552 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
554 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
555 m_controller
->requestActivation();
558 return QWidget::eventFilter(watched
, event
);
561 void DolphinView::activate()
566 void DolphinView::triggerItem(const KFileItem
& item
)
568 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
569 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
570 // items are selected by the user, hence don't trigger the
571 // item specified by 'index'
579 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
582 void DolphinView::emitSelectionChangedSignal()
584 emit
selectionChanged(DolphinView::selectedItems());
587 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
589 if (!url
.isValid()) {
590 const QString
location(url
.pathOrUrl());
591 if (location
.isEmpty()) {
592 emit
errorMessage(i18nc("@info:status", "The location is empty."));
594 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
599 m_loadingDirectory
= true;
602 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
604 if (isColumnViewActive()) {
605 // adjusting the directory lister is not enough in the case of the
606 // column view, as each column has its own directory lister internally...
608 m_columnView
->reload();
610 m_columnView
->showColumn(url
);
615 KUrl
DolphinView::viewPropertiesUrl() const
617 if (isColumnViewActive()) {
618 return m_columnView
->rootUrl();
624 void DolphinView::applyViewProperties(const KUrl
& url
)
626 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
627 // The column view is active, hence don't apply the view properties
628 // of sub directories (represented by columns) to the view. The
629 // view always represents the properties of the first column.
633 const ViewProperties
props(url
);
635 const Mode mode
= props
.viewMode();
636 if (m_mode
!= mode
) {
641 if (itemView() == 0) {
644 Q_ASSERT(itemView() != 0);
645 Q_ASSERT(m_fileItemDelegate
!= 0);
647 const bool showHiddenFiles
= props
.showHiddenFiles();
648 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
649 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
650 emit
showHiddenFilesChanged();
653 m_storedCategorizedSorting
= props
.categorizedSorting();
654 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
655 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
656 m_proxyModel
->setCategorizedModel(categorized
);
657 emit
categorizedSortingChanged();
660 const DolphinView::Sorting sorting
= props
.sorting();
661 if (sorting
!= m_proxyModel
->sorting()) {
662 m_proxyModel
->setSorting(sorting
);
663 emit
sortingChanged(sorting
);
666 const Qt::SortOrder sortOrder
= props
.sortOrder();
667 if (sortOrder
!= m_proxyModel
->sortOrder()) {
668 m_proxyModel
->setSortOrder(sortOrder
);
669 emit
sortOrderChanged(sortOrder
);
672 KFileItemDelegate::InformationList info
= props
.additionalInfo();
673 if (info
!= m_fileItemDelegate
->showInformation()) {
674 m_fileItemDelegate
->setShowInformation(info
);
675 emit
additionalInfoChanged();
678 const bool showPreview
= props
.showPreview();
679 if (showPreview
!= m_showPreview
) {
680 m_showPreview
= showPreview
;
681 m_iconManager
->setShowPreview(showPreview
);
682 emit
showPreviewChanged();
686 void DolphinView::changeSelection(const KFileItemList
& selection
)
689 if (selection
.isEmpty()) {
692 const KUrl
& baseUrl
= url();
694 QItemSelection new_selection
;
695 foreach(const KFileItem
& item
, selection
) {
696 url
= item
.url().upUrl();
697 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
698 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
699 new_selection
.select(index
, index
);
702 itemView()->selectionModel()->select(new_selection
,
703 QItemSelectionModel::ClearAndSelect
704 | QItemSelectionModel::Current
);
707 void DolphinView::openContextMenu(const QPoint
& pos
)
711 const QModelIndex index
= itemView()->indexAt(pos
);
712 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
713 item
= fileItem(index
);
716 emit
requestContextMenu(item
, url());
719 void DolphinView::dropUrls(const KUrl::List
& urls
,
720 const KUrl
& destPath
,
721 const KFileItem
& destItem
)
723 Q_ASSERT(!urls
.isEmpty());
724 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
725 destItem
.url() : destPath
;
726 const KUrl sourceDir
= KUrl(urls
.first().directory());
727 if (sourceDir
!= destination
) {
728 dropUrls(urls
, destination
);
732 void DolphinView::dropUrls(const KUrl::List
& urls
,
733 const KUrl
& destination
)
735 DolphinDropController
dropController(this);
736 // forward doingOperation signal up to the mainwindow
737 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
738 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
739 dropController
.dropUrls(urls
, destination
);
742 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
744 ViewProperties
props(viewPropertiesUrl());
745 props
.setSorting(sorting
);
747 m_proxyModel
->setSorting(sorting
);
749 emit
sortingChanged(sorting
);
752 void DolphinView::updateSortOrder(Qt::SortOrder order
)
754 ViewProperties
props(viewPropertiesUrl());
755 props
.setSortOrder(order
);
757 m_proxyModel
->setSortOrder(order
);
759 emit
sortOrderChanged(order
);
762 void DolphinView::toggleSortOrder()
764 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
765 Qt::DescendingOrder
:
770 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
772 ViewProperties
props(viewPropertiesUrl());
773 props
.setAdditionalInfo(info
);
776 m_fileItemDelegate
->setShowInformation(info
);
778 emit
additionalInfoChanged();
781 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
783 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
784 (m_mode
== DolphinView::IconsView
);
786 QAction
* showSizeInfo
= collection
->action("show_size_info");
787 QAction
* showDateInfo
= collection
->action("show_date_info");
788 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
789 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
790 QAction
* showGroupInfo
= collection
->action("show_group_info");
791 QAction
* showMimeInfo
= collection
->action("show_mime_info");
793 showSizeInfo
->setChecked(false);
794 showDateInfo
->setChecked(false);
795 showPermissionsInfo
->setChecked(false);
796 showOwnerInfo
->setChecked(false);
797 showGroupInfo
->setChecked(false);
798 showMimeInfo
->setChecked(false);
800 showSizeInfo
->setEnabled(enable
);
801 showDateInfo
->setEnabled(enable
);
802 showPermissionsInfo
->setEnabled(enable
);
803 showOwnerInfo
->setEnabled(enable
);
804 showGroupInfo
->setEnabled(enable
);
805 showMimeInfo
->setEnabled(enable
);
807 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
809 case KFileItemDelegate::Size
:
810 showSizeInfo
->setChecked(true);
812 case KFileItemDelegate::ModificationTime
:
813 showDateInfo
->setChecked(true);
815 case KFileItemDelegate::Permissions
:
816 showPermissionsInfo
->setChecked(true);
818 case KFileItemDelegate::Owner
:
819 showOwnerInfo
->setChecked(true);
821 case KFileItemDelegate::OwnerAndGroup
:
822 showGroupInfo
->setChecked(true);
824 case KFileItemDelegate::FriendlyMimeType
:
825 showMimeInfo
->setChecked(true);
833 void DolphinView::toggleAdditionalInfo(QAction
* action
)
835 const KFileItemDelegate::Information info
=
836 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
838 KFileItemDelegate::InformationList list
= additionalInfo();
840 const bool show
= action
->isChecked();
842 const int index
= list
.indexOf(info
);
843 const bool containsInfo
= (index
>= 0);
844 if (show
&& !containsInfo
) {
846 setAdditionalInfo(list
);
847 } else if (!show
&& containsInfo
) {
848 list
.removeAt(index
);
849 setAdditionalInfo(list
);
850 Q_ASSERT(list
.indexOf(info
) < 0);
854 void DolphinView::emitContentsMoved()
856 // only emit the contents moved signal if:
857 // - no directory loading is ongoing (this would reset the contents position
859 // - if the Column View is active: the column view does an automatic
860 // positioning during the loading operation, which must be remembered
861 if (!m_loadingDirectory
|| isColumnViewActive()) {
862 const QPoint
pos(contentsPosition());
863 emit
contentsMoved(pos
.x(), pos
.y());
867 void DolphinView::showHoverInformation(const KFileItem
& item
)
869 if (hasSelection() || !m_active
) {
873 emit
requestItemInfo(item
);
876 void DolphinView::clearHoverInformation()
879 emit
requestItemInfo(KFileItem());
883 void DolphinView::createView()
886 Q_ASSERT(m_iconsView
== 0);
887 Q_ASSERT(m_detailsView
== 0);
888 Q_ASSERT(m_columnView
== 0);
890 QAbstractItemView
* view
= 0;
893 m_iconsView
= new DolphinIconsView(this, m_controller
);
899 m_detailsView
= new DolphinDetailsView(this, m_controller
);
900 view
= m_detailsView
;
904 m_columnView
= new DolphinColumnView(this, m_controller
);
910 view
->installEventFilter(this);
912 m_controller
->setItemView(view
);
914 m_fileItemDelegate
= new KFileItemDelegate(view
);
915 view
->setItemDelegate(m_fileItemDelegate
);
917 view
->setModel(m_proxyModel
);
918 if (m_selectionModel
!= 0) {
919 view
->setSelectionModel(m_selectionModel
);
921 m_selectionModel
= view
->selectionModel();
924 // reparent the selection model, as it should not be deleted
925 // when deleting the model
926 m_selectionModel
->setParent(this);
928 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
930 new KMimeTypeResolver(view
, m_dolphinModel
);
931 m_iconManager
= new IconManager(view
, m_proxyModel
);
932 m_iconManager
->setShowPreview(m_showPreview
);
934 m_topLayout
->insertWidget(1, view
);
936 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
937 this, SLOT(emitSelectionChangedSignal()));
938 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
939 this, SLOT(emitContentsMoved()));
940 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
941 this, SLOT(emitContentsMoved()));
944 void DolphinView::deleteView()
946 QAbstractItemView
* view
= itemView();
948 m_topLayout
->removeWidget(view
);
955 m_fileItemDelegate
= 0;
960 QAbstractItemView
* DolphinView::itemView() const
962 if (m_detailsView
!= 0) {
963 return m_detailsView
;
964 } else if (m_columnView
!= 0) {
971 bool DolphinView::isCutItem(const KFileItem
& item
) const
973 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
974 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
976 const KUrl
& itemUrl
= item
.url();
977 KUrl::List::const_iterator it
= cutUrls
.begin();
978 const KUrl::List::const_iterator end
= cutUrls
.end();
980 if (*it
== itemUrl
) {
989 void DolphinView::renameSelectedItems()
991 const KFileItemList items
= selectedItems();
992 if (items
.count() > 1) {
993 // More than one item has been selected for renaming. Open
994 // a rename dialog and rename all items afterwards.
995 RenameDialog
dialog(this, items
);
996 if (dialog
.exec() == QDialog::Rejected
) {
1000 const QString newName
= dialog
.newName();
1001 if (newName
.isEmpty()) {
1002 emit
errorMessage(dialog
.errorString());
1004 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
1005 // as one operation instead of n rename operations like it is done now...
1006 Q_ASSERT(newName
.contains('#'));
1008 // iterate through all selected items and rename them...
1010 foreach (KFileItem item
, items
) {
1011 const KUrl
& oldUrl
= item
.url();
1013 number
.setNum(index
++);
1015 QString name
= newName
;
1016 name
.replace('#', number
);
1018 if (oldUrl
.fileName() != name
) {
1019 KUrl newUrl
= oldUrl
;
1020 newUrl
.setFileName(name
);
1021 KonqOperations::rename(this, oldUrl
, newUrl
);
1022 emit
doingOperation(KonqFileUndoManager::RENAME
);
1027 // Only one item has been selected for renaming. Use the custom
1028 // renaming mechanism from the views.
1029 Q_ASSERT(items
.count() == 1);
1031 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
1032 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
1033 // is a benefit for the user at all -> let's wait for some input first...
1034 RenameDialog
dialog(this, items
);
1035 if (dialog
.exec() == QDialog::Rejected
) {
1039 const QString
& newName
= dialog
.newName();
1040 if (newName
.isEmpty()) {
1041 emit
errorMessage(dialog
.errorString());
1043 const KUrl
& oldUrl
= items
.first().url();
1044 KUrl newUrl
= oldUrl
;
1045 newUrl
.setFileName(newName
);
1046 KonqOperations::rename(this, oldUrl
, newUrl
);
1047 emit
doingOperation(KonqFileUndoManager::RENAME
);
1052 void DolphinView::trashSelectedItems()
1054 emit
doingOperation(KonqFileUndoManager::TRASH
);
1055 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
1058 void DolphinView::deleteSelectedItems()
1060 const KUrl::List list
= selectedUrls();
1061 const bool del
= KonqOperations::askDeleteConfirmation(list
,
1062 KonqOperations::DEL
,
1063 KonqOperations::DEFAULT_CONFIRMATION
,
1067 KIO::Job
* job
= KIO::del(list
);
1068 connect(job
, SIGNAL(result(KJob
*)),
1069 this, SLOT(slotDeleteFileFinished(KJob
*)));
1073 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1075 if (job
->error() == 0) {
1076 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1078 emit
errorMessage(job
->errorString());
1082 void DolphinView::cutSelectedItems()
1084 QMimeData
* mimeData
= new QMimeData();
1085 const KUrl::List kdeUrls
= selectedUrls();
1086 const KUrl::List mostLocalUrls
;
1087 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
1088 QApplication::clipboard()->setMimeData(mimeData
);
1091 void DolphinView::copySelectedItems()
1093 QMimeData
* mimeData
= new QMimeData();
1094 const KUrl::List kdeUrls
= selectedUrls();
1095 const KUrl::List mostLocalUrls
;
1096 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
1097 QApplication::clipboard()->setMimeData(mimeData
);
1100 void DolphinView::paste()
1102 QClipboard
* clipboard
= QApplication::clipboard();
1103 const QMimeData
* mimeData
= clipboard
->mimeData();
1105 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1107 // per default the pasting is done into the current URL of the view
1108 KUrl destUrl
= url();
1110 // check whether the pasting should be done into a selected directory
1111 const KUrl::List selectedUrls
= this->selectedUrls();
1112 if (selectedUrls
.count() == 1) {
1113 const KFileItem
fileItem(S_IFDIR
,
1115 selectedUrls
.first(),
1117 if (fileItem
.isDir()) {
1118 // only one item is selected which is a directory, hence paste
1119 // into this directory
1120 destUrl
= selectedUrls
.first();
1121 if (sourceUrls
.contains(destUrl
)) {
1122 const QString text
= i18nc("@info", "The folder <filename>%1</filename> is pasted into itself. Is this intended?", fileItem
.name());
1123 int result
= KMessageBox::questionYesNo(window(),
1125 i18nc("@title:window", "Paste into Folder"),
1126 KGuiItem(i18nc("@label", "Paste"), "dialog-ok"),
1127 KGuiItem(i18nc("@label", "Cancel"), "dialog-cancel"));
1128 if (result
== KMessageBox::No
) {
1135 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1136 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, destUrl
);
1137 emit
doingOperation(KonqFileUndoManager::MOVE
);
1140 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, destUrl
);
1141 emit
doingOperation(KonqFileUndoManager::COPY
);
1145 QPair
<bool, QString
> DolphinView::pasteInfo() const
1147 QPair
<bool, QString
> ret
;
1148 QClipboard
* clipboard
= QApplication::clipboard();
1149 const QMimeData
* mimeData
= clipboard
->mimeData();
1151 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1152 if (!urls
.isEmpty()) {
1154 if (urls
.count() == 1) {
1155 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
1156 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
1157 i18nc("@action:inmenu", "Paste One File");
1160 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
1164 ret
.second
= i18nc("@action:inmenu", "Paste");
1168 const KFileItemList items
= selectedItems();
1169 const uint count
= items
.count();
1171 // pasting should not be allowed when more than one file
1174 } else if (count
== 1) {
1175 // Only one file is selected. Pasting is only allowed if this
1176 // file is a directory.
1177 ret
.first
= items
.first().isDir();
1183 #include "dolphinview.moc"