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 <kmimetyperesolver.h>
43 #include <konq_operations.h>
44 #include <konqmimedata.h>
45 #include <ktoggleaction.h>
48 #include "dolphindropcontroller.h"
49 #include "dolphinmodel.h"
50 #include "dolphincolumnview.h"
51 #include "dolphincontroller.h"
52 #include "dolphinsortfilterproxymodel.h"
53 #include "dolphindetailsview.h"
54 #include "dolphiniconsview.h"
55 #include "dolphinsettings.h"
56 #include "dolphin_generalsettings.h"
57 #include "iconmanager.h"
58 #include "renamedialog.h"
59 #include "viewproperties.h"
61 DolphinView::DolphinView(QWidget
* parent
,
63 KDirLister
* dirLister
,
64 DolphinModel
* dolphinModel
,
65 DolphinSortFilterProxyModel
* proxyModel
) :
69 m_loadingDirectory(false),
70 m_storedCategorizedSorting(false),
71 m_mode(DolphinView::IconsView
),
77 m_fileItemDelegate(0),
79 m_dolphinModel(dolphinModel
),
80 m_dirLister(dirLister
),
81 m_proxyModel(proxyModel
),
84 setFocusPolicy(Qt::StrongFocus
);
85 m_topLayout
= new QVBoxLayout(this);
86 m_topLayout
->setSpacing(0);
87 m_topLayout
->setMargin(0);
89 connect(m_dirLister
, SIGNAL(completed()),
90 this, SLOT(updateCutItems()));
92 m_controller
= new DolphinController(this);
93 m_controller
->setUrl(url
);
95 // Receiver of the DolphinView signal 'urlChanged()' don't need
96 // to care whether the internal controller changed the URL already or whether
97 // the controller just requested an URL change and will be updated later.
98 // In both cases the URL has been changed:
99 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
100 this, SIGNAL(urlChanged(const KUrl
&)));
101 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
102 this, SIGNAL(urlChanged(const KUrl
&)));
104 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
105 this, SLOT(openContextMenu(const QPoint
&)));
106 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
107 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
108 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
109 this, SLOT(updateSorting(DolphinView::Sorting
)));
110 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
111 this, SLOT(updateSortOrder(Qt::SortOrder
)));
112 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
113 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
114 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
115 this, SLOT(triggerItem(const KFileItem
&)));
116 connect(m_controller
, SIGNAL(activated()),
117 this, SLOT(activate()));
118 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
119 this, SLOT(showHoverInformation(const KFileItem
&)));
120 connect(m_controller
, SIGNAL(viewportEntered()),
121 this, SLOT(clearHoverInformation()));
123 applyViewProperties(url
);
124 m_topLayout
->addWidget(itemView());
127 DolphinView::~DolphinView()
131 const KUrl
& DolphinView::url() const
133 return m_controller
->url();
136 KUrl
DolphinView::rootUrl() const
138 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
141 void DolphinView::setActive(bool active
)
143 if (active
== m_active
) {
148 m_selectionModel
->clearSelection();
150 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
152 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
153 // bypasses the problem when having a split view and changing the active view to
154 // update the some URL dependent states. A nicer approach should be no big deal...
155 emit
urlChanged(url());
156 emit
selectionChanged(selectedItems());
161 QWidget
* viewport
= itemView()->viewport();
163 palette
.setColor(viewport
->backgroundRole(), color
);
164 viewport
->setPalette(palette
);
172 m_controller
->indicateActivationChange(active
);
175 bool DolphinView::isActive() const
180 void DolphinView::setMode(Mode mode
)
182 if (mode
== m_mode
) {
183 return; // the wished mode is already set
190 const KUrl viewPropsUrl
= viewPropertiesUrl();
191 ViewProperties
props(viewPropsUrl
);
192 props
.setViewMode(m_mode
);
195 // the file item delegate has been recreated, apply the current
196 // additional information manually
197 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
198 m_fileItemDelegate
->setShowInformation(infoList
);
199 emit
additionalInfoChanged();
201 // Not all view modes support categorized sorting. Adjust the sorting model
202 // if changing the view mode results in a change of the categorized sorting
204 m_storedCategorizedSorting
= props
.categorizedSorting();
205 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
206 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
207 m_proxyModel
->setCategorizedModel(categorized
);
208 emit
categorizedSortingChanged();
214 DolphinView::Mode
DolphinView::mode() const
219 void DolphinView::setShowPreview(bool show
)
221 if (m_showPreview
== show
) {
225 const KUrl viewPropsUrl
= viewPropertiesUrl();
226 ViewProperties
props(viewPropsUrl
);
227 props
.setShowPreview(show
);
229 m_showPreview
= show
;
230 m_iconManager
->setShowPreview(show
);
231 emit
showPreviewChanged();
233 loadDirectory(viewPropsUrl
, true);
236 bool DolphinView::showPreview() const
238 return m_showPreview
;
241 void DolphinView::setShowHiddenFiles(bool show
)
243 if (m_dirLister
->showingDotFiles() == show
) {
247 const KUrl viewPropsUrl
= viewPropertiesUrl();
248 ViewProperties
props(viewPropsUrl
);
249 props
.setShowHiddenFiles(show
);
251 m_dirLister
->setShowingDotFiles(show
);
252 emit
showHiddenFilesChanged();
254 loadDirectory(viewPropsUrl
, true);
257 bool DolphinView::showHiddenFiles() const
259 return m_dirLister
->showingDotFiles();
262 void DolphinView::setCategorizedSorting(bool categorized
)
264 if (categorized
== categorizedSorting()) {
268 // setCategorizedSorting(true) may only get invoked
269 // if the view supports categorized sorting
270 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
272 ViewProperties
props(viewPropertiesUrl());
273 props
.setCategorizedSorting(categorized
);
276 m_storedCategorizedSorting
= categorized
;
277 m_proxyModel
->setCategorizedModel(categorized
);
279 emit
categorizedSortingChanged();
282 bool DolphinView::categorizedSorting() const
284 // If all view modes would support categorized sorting, returning
285 // m_proxyModel->isCategorizedModel() would be the way to go. As
286 // currently only the icons view supports caterized sorting, we remember
287 // the stored view properties state in m_storedCategorizedSorting and
288 // return this state. The application takes care to disable the corresponding
289 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
290 // that this setting is not applied to the current view mode.
291 return m_storedCategorizedSorting
;
294 bool DolphinView::supportsCategorizedSorting() const
296 return m_iconsView
!= 0;
299 void DolphinView::selectAll()
301 QAbstractItemView
* view
= itemView();
302 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
303 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
304 // selection instead of selecting all items. This is bypassed for KDE 4.0
305 // by invoking clearSelection() first.
306 view
->clearSelection();
310 void DolphinView::invertSelection()
312 if (isColumnViewActive()) {
313 // QAbstractItemView does not offer a virtual method invertSelection()
314 // as counterpart to QAbstractItemView::selectAll(). This makes it
315 // necessary to delegate the inverting of the selection to the
316 // column view, as only the selection of the active column should
318 m_columnView
->invertSelection();
320 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
321 const QAbstractItemModel
* itemModel
= selectionModel
->model();
323 const QModelIndex topLeft
= itemModel
->index(0, 0);
324 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
325 itemModel
->columnCount() - 1);
327 const QItemSelection
selection(topLeft
, bottomRight
);
328 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
332 bool DolphinView::hasSelection() const
334 return itemView()->selectionModel()->hasSelection();
337 void DolphinView::clearSelection()
339 itemView()->selectionModel()->clear();
342 KFileItemList
DolphinView::selectedItems() const
344 const QAbstractItemView
* view
= itemView();
346 // Our view has a selection, we will map them back to the DolphinModel
347 // and then fill the KFileItemList.
348 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
350 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
351 KFileItemList itemList
;
353 const QModelIndexList indexList
= selection
.indexes();
354 foreach (QModelIndex index
, indexList
) {
355 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
356 if (!item
.isNull()) {
357 itemList
.append(item
);
364 KUrl::List
DolphinView::selectedUrls() const
367 const KFileItemList list
= selectedItems();
368 foreach (KFileItem item
, list
) {
369 urls
.append(item
.url());
374 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
376 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
377 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
380 void DolphinView::setContentsPosition(int x
, int y
)
382 QAbstractItemView
* view
= itemView();
384 // the ColumnView takes care itself for the horizontal scrolling
385 if (!isColumnViewActive()) {
386 view
->horizontalScrollBar()->setValue(x
);
388 view
->verticalScrollBar()->setValue(y
);
390 m_loadingDirectory
= false;
393 QPoint
DolphinView::contentsPosition() const
395 const int x
= itemView()->horizontalScrollBar()->value();
396 const int y
= itemView()->verticalScrollBar()->value();
400 void DolphinView::zoomIn()
402 m_controller
->triggerZoomIn();
406 void DolphinView::zoomOut()
408 m_controller
->triggerZoomOut();
412 bool DolphinView::isZoomInPossible() const
414 return m_controller
->isZoomInPossible();
417 bool DolphinView::isZoomOutPossible() const
419 return m_controller
->isZoomOutPossible();
422 void DolphinView::setSorting(Sorting sorting
)
424 if (sorting
!= this->sorting()) {
425 updateSorting(sorting
);
429 DolphinView::Sorting
DolphinView::sorting() const
431 return m_proxyModel
->sorting();
434 void DolphinView::setSortOrder(Qt::SortOrder order
)
436 if (sortOrder() != order
) {
437 updateSortOrder(order
);
441 Qt::SortOrder
DolphinView::sortOrder() const
443 return m_proxyModel
->sortOrder();
446 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
448 const KUrl viewPropsUrl
= viewPropertiesUrl();
449 ViewProperties
props(viewPropsUrl
);
450 props
.setAdditionalInfo(info
);
451 m_fileItemDelegate
->setShowInformation(info
);
453 emit
additionalInfoChanged();
455 if (itemView() != m_detailsView
) {
456 // the details view requires no reloading of the directory, as it maps
457 // the file item delegate info to its columns internally
458 loadDirectory(viewPropsUrl
, true);
462 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
464 return m_fileItemDelegate
->showInformation();
467 void DolphinView::reload()
470 loadDirectory(url(), true);
473 void DolphinView::refresh()
475 const bool oldActivationState
= m_active
;
479 applyViewProperties(m_controller
->url());
482 setActive(oldActivationState
);
485 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
487 if (m_controller
->url() == url
) {
491 m_controller
->setUrl(url
); // emits urlChanged, which we forward
493 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
494 applyViewProperties(rootUrl
);
495 loadDirectory(rootUrl
);
496 if (itemView() == m_columnView
) {
497 m_columnView
->setRootUrl(rootUrl
);
498 m_columnView
->showColumn(url
);
501 applyViewProperties(url
);
505 emit
startedPathLoading(url
);
508 void DolphinView::setNameFilter(const QString
& nameFilter
)
510 m_proxyModel
->setFilterRegExp(nameFilter
);
512 if (isColumnViewActive()) {
513 // adjusting the directory lister is not enough in the case of the
514 // column view, as each column has its own directory lister internally...
515 m_columnView
->setNameFilter(nameFilter
);
519 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
521 foreach (KFileItem item
, m_dirLister
->items()) {
530 void DolphinView::setUrl(const KUrl
& url
)
532 updateView(url
, KUrl());
535 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
537 QWidget::mouseReleaseEvent(event
);
541 void DolphinView::wheelEvent(QWheelEvent
* event
)
543 if ((event
->modifiers() & Qt::ControlModifier
) == Qt::ControlModifier
) {
544 int d
= event
->delta();
545 if (d
> 0 && isZoomInPossible()) {
547 } else if (d
< 0 && isZoomOutPossible()) {
554 void DolphinView::activate()
559 void DolphinView::triggerItem(const KFileItem
& item
)
561 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
562 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
563 // items are selected by the user, hence don't trigger the
564 // item specified by 'index'
572 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
575 void DolphinView::emitSelectionChangedSignal()
577 emit
selectionChanged(DolphinView::selectedItems());
580 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
582 if (!url
.isValid()) {
583 const QString
location(url
.pathOrUrl());
584 if (location
.isEmpty()) {
585 emit
errorMessage(i18nc("@info:status", "The location is empty."));
587 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
592 m_loadingDirectory
= true;
595 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
597 if (isColumnViewActive()) {
598 // adjusting the directory lister is not enough in the case of the
599 // column view, as each column has its own directory lister internally...
601 m_columnView
->reload();
603 m_columnView
->showColumn(url
);
608 KUrl
DolphinView::viewPropertiesUrl() const
610 if (isColumnViewActive()) {
611 return m_columnView
->rootUrl();
617 void DolphinView::applyViewProperties(const KUrl
& url
)
619 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
620 // The column view is active, hence don't apply the view properties
621 // of sub directories (represented by columns) to the view. The
622 // view always represents the properties of the first column.
626 const ViewProperties
props(url
);
628 const Mode mode
= props
.viewMode();
629 if (m_mode
!= mode
) {
634 if (itemView() == 0) {
637 Q_ASSERT(itemView() != 0);
638 Q_ASSERT(m_fileItemDelegate
!= 0);
640 const bool showHiddenFiles
= props
.showHiddenFiles();
641 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
642 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
643 emit
showHiddenFilesChanged();
646 m_storedCategorizedSorting
= props
.categorizedSorting();
647 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
648 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
649 m_proxyModel
->setCategorizedModel(categorized
);
650 emit
categorizedSortingChanged();
653 const DolphinView::Sorting sorting
= props
.sorting();
654 if (sorting
!= m_proxyModel
->sorting()) {
655 m_proxyModel
->setSorting(sorting
);
656 emit
sortingChanged(sorting
);
659 const Qt::SortOrder sortOrder
= props
.sortOrder();
660 if (sortOrder
!= m_proxyModel
->sortOrder()) {
661 m_proxyModel
->setSortOrder(sortOrder
);
662 emit
sortOrderChanged(sortOrder
);
665 KFileItemDelegate::InformationList info
= props
.additionalInfo();
666 if (info
!= m_fileItemDelegate
->showInformation()) {
667 m_fileItemDelegate
->setShowInformation(info
);
668 emit
additionalInfoChanged();
671 const bool showPreview
= props
.showPreview();
672 if (showPreview
!= m_showPreview
) {
673 m_showPreview
= showPreview
;
674 m_iconManager
->setShowPreview(showPreview
);
675 emit
showPreviewChanged();
679 void DolphinView::changeSelection(const KFileItemList
& selection
)
682 if (selection
.isEmpty()) {
685 const KUrl
& baseUrl
= url();
687 QItemSelection new_selection
;
688 foreach(const KFileItem
& item
, selection
) {
689 url
= item
.url().upUrl();
690 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
691 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
692 new_selection
.select(index
, index
);
695 itemView()->selectionModel()->select(new_selection
,
696 QItemSelectionModel::ClearAndSelect
697 | QItemSelectionModel::Current
);
700 void DolphinView::openContextMenu(const QPoint
& pos
)
704 const QModelIndex index
= itemView()->indexAt(pos
);
705 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
706 item
= fileItem(index
);
709 emit
requestContextMenu(item
, url());
712 void DolphinView::dropUrls(const KUrl::List
& urls
,
713 const KUrl
& destPath
,
714 const KFileItem
& destItem
)
716 Q_ASSERT(!urls
.isEmpty());
717 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
718 destItem
.url() : destPath
;
719 const KUrl sourceDir
= KUrl(urls
.first().directory());
720 if (sourceDir
!= destination
) {
721 dropUrls(urls
, destination
);
725 void DolphinView::dropUrls(const KUrl::List
& urls
,
726 const KUrl
& destination
)
728 DolphinDropController
dropController(this);
729 // forward doingOperation signal up to the mainwindow
730 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
731 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
732 dropController
.dropUrls(urls
, destination
);
735 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
737 ViewProperties
props(viewPropertiesUrl());
738 props
.setSorting(sorting
);
740 m_proxyModel
->setSorting(sorting
);
742 emit
sortingChanged(sorting
);
745 void DolphinView::updateSortOrder(Qt::SortOrder order
)
747 ViewProperties
props(viewPropertiesUrl());
748 props
.setSortOrder(order
);
750 m_proxyModel
->setSortOrder(order
);
752 emit
sortOrderChanged(order
);
755 void DolphinView::toggleSortOrder()
757 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
758 Qt::DescendingOrder
:
763 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
765 ViewProperties
props(viewPropertiesUrl());
766 props
.setAdditionalInfo(info
);
769 m_fileItemDelegate
->setShowInformation(info
);
771 emit
additionalInfoChanged();
774 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
776 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
777 (m_mode
== DolphinView::IconsView
);
779 QAction
* showSizeInfo
= collection
->action("show_size_info");
780 QAction
* showDateInfo
= collection
->action("show_date_info");
781 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
782 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
783 QAction
* showGroupInfo
= collection
->action("show_group_info");
784 QAction
* showMimeInfo
= collection
->action("show_mime_info");
786 showSizeInfo
->setChecked(false);
787 showDateInfo
->setChecked(false);
788 showPermissionsInfo
->setChecked(false);
789 showOwnerInfo
->setChecked(false);
790 showGroupInfo
->setChecked(false);
791 showMimeInfo
->setChecked(false);
793 showSizeInfo
->setEnabled(enable
);
794 showDateInfo
->setEnabled(enable
);
795 showPermissionsInfo
->setEnabled(enable
);
796 showOwnerInfo
->setEnabled(enable
);
797 showGroupInfo
->setEnabled(enable
);
798 showMimeInfo
->setEnabled(enable
);
800 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
802 case KFileItemDelegate::Size
:
803 showSizeInfo
->setChecked(true);
805 case KFileItemDelegate::ModificationTime
:
806 showDateInfo
->setChecked(true);
808 case KFileItemDelegate::Permissions
:
809 showPermissionsInfo
->setChecked(true);
811 case KFileItemDelegate::Owner
:
812 showOwnerInfo
->setChecked(true);
814 case KFileItemDelegate::OwnerAndGroup
:
815 showGroupInfo
->setChecked(true);
817 case KFileItemDelegate::FriendlyMimeType
:
818 showMimeInfo
->setChecked(true);
826 void DolphinView::toggleAdditionalInfo(QAction
* action
)
828 const KFileItemDelegate::Information info
=
829 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
831 KFileItemDelegate::InformationList list
= additionalInfo();
833 const bool show
= action
->isChecked();
835 const int index
= list
.indexOf(info
);
836 const bool containsInfo
= (index
>= 0);
837 if (show
&& !containsInfo
) {
839 setAdditionalInfo(list
);
840 } else if (!show
&& containsInfo
) {
841 list
.removeAt(index
);
842 setAdditionalInfo(list
);
843 Q_ASSERT(list
.indexOf(info
) < 0);
847 void DolphinView::emitContentsMoved()
849 // only emit the contents moved signal if:
850 // - no directory loading is ongoing (this would reset the contents position
852 // - if the Column View is active: the column view does an automatic
853 // positioning during the loading operation, which must be remembered
854 if (!m_loadingDirectory
|| isColumnViewActive()) {
855 const QPoint
pos(contentsPosition());
856 emit
contentsMoved(pos
.x(), pos
.y());
860 void DolphinView::showHoverInformation(const KFileItem
& item
)
862 if (hasSelection() || !m_active
) {
866 emit
requestItemInfo(item
);
869 void DolphinView::clearHoverInformation()
872 emit
requestItemInfo(KFileItem());
876 void DolphinView::createView()
879 Q_ASSERT(m_iconsView
== 0);
880 Q_ASSERT(m_detailsView
== 0);
881 Q_ASSERT(m_columnView
== 0);
883 QAbstractItemView
* view
= 0;
886 m_iconsView
= new DolphinIconsView(this, m_controller
);
892 m_detailsView
= new DolphinDetailsView(this, m_controller
);
893 view
= m_detailsView
;
897 m_columnView
= new DolphinColumnView(this, m_controller
);
904 m_fileItemDelegate
= new KFileItemDelegate(view
);
905 view
->setItemDelegate(m_fileItemDelegate
);
907 view
->setModel(m_proxyModel
);
908 if (m_selectionModel
!= 0) {
909 view
->setSelectionModel(m_selectionModel
);
911 m_selectionModel
= view
->selectionModel();
914 // reparent the selection model, as it should not be deleted
915 // when deleting the model
916 m_selectionModel
->setParent(this);
918 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
920 new KMimeTypeResolver(view
, m_dolphinModel
);
921 m_iconManager
= new IconManager(view
, m_proxyModel
);
922 m_iconManager
->setShowPreview(m_showPreview
);
924 m_topLayout
->insertWidget(1, view
);
926 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
927 this, SLOT(emitSelectionChangedSignal()));
928 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
929 this, SLOT(emitContentsMoved()));
930 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
931 this, SLOT(emitContentsMoved()));
934 void DolphinView::deleteView()
936 QAbstractItemView
* view
= itemView();
938 m_topLayout
->removeWidget(view
);
945 m_fileItemDelegate
= 0;
950 QAbstractItemView
* DolphinView::itemView() const
952 if (m_detailsView
!= 0) {
953 return m_detailsView
;
954 } else if (m_columnView
!= 0) {
961 bool DolphinView::isCutItem(const KFileItem
& item
) const
963 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
964 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
966 const KUrl
& itemUrl
= item
.url();
967 KUrl::List::const_iterator it
= cutUrls
.begin();
968 const KUrl::List::const_iterator end
= cutUrls
.end();
970 if (*it
== itemUrl
) {
979 void DolphinView::renameSelectedItems()
981 const KFileItemList items
= selectedItems();
982 if (items
.count() > 1) {
983 // More than one item has been selected for renaming. Open
984 // a rename dialog and rename all items afterwards.
985 RenameDialog
dialog(this, items
);
986 if (dialog
.exec() == QDialog::Rejected
) {
990 const QString newName
= dialog
.newName();
991 if (newName
.isEmpty()) {
992 emit
errorMessage(dialog
.errorString());
994 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
995 // as one operation instead of n rename operations like it is done now...
996 Q_ASSERT(newName
.contains('#'));
998 // iterate through all selected items and rename them...
1000 foreach (KFileItem item
, items
) {
1001 const KUrl
& oldUrl
= item
.url();
1003 number
.setNum(index
++);
1005 QString name
= newName
;
1006 name
.replace('#', number
);
1008 if (oldUrl
.fileName() != name
) {
1009 KUrl newUrl
= oldUrl
;
1010 newUrl
.setFileName(name
);
1011 KonqOperations::rename(this, oldUrl
, newUrl
);
1012 emit
doingOperation(KonqFileUndoManager::RENAME
);
1017 // Only one item has been selected for renaming. Use the custom
1018 // renaming mechanism from the views.
1019 Q_ASSERT(items
.count() == 1);
1021 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
1022 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
1023 // is a benefit for the user at all -> let's wait for some input first...
1024 RenameDialog
dialog(this, items
);
1025 if (dialog
.exec() == QDialog::Rejected
) {
1029 const QString
& newName
= dialog
.newName();
1030 if (newName
.isEmpty()) {
1031 emit
errorMessage(dialog
.errorString());
1033 const KUrl
& oldUrl
= items
.first().url();
1034 KUrl newUrl
= oldUrl
;
1035 newUrl
.setFileName(newName
);
1036 KonqOperations::rename(this, oldUrl
, newUrl
);
1037 emit
doingOperation(KonqFileUndoManager::RENAME
);
1042 void DolphinView::trashSelectedItems()
1044 emit
doingOperation(KonqFileUndoManager::TRASH
);
1045 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
1048 void DolphinView::deleteSelectedItems()
1050 const KUrl::List list
= selectedUrls();
1051 const bool del
= KonqOperations::askDeleteConfirmation(list
,
1052 KonqOperations::DEL
,
1053 KonqOperations::DEFAULT_CONFIRMATION
,
1057 KIO::Job
* job
= KIO::del(list
);
1058 connect(job
, SIGNAL(result(KJob
*)),
1059 this, SLOT(slotDeleteFileFinished(KJob
*)));
1063 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1065 if (job
->error() == 0) {
1066 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1068 emit
errorMessage(job
->errorString());
1072 void DolphinView::cutSelectedItems()
1074 QMimeData
* mimeData
= new QMimeData();
1075 const KUrl::List kdeUrls
= selectedUrls();
1076 const KUrl::List mostLocalUrls
;
1077 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
1078 QApplication::clipboard()->setMimeData(mimeData
);
1081 void DolphinView::copySelectedItems()
1083 QMimeData
* mimeData
= new QMimeData();
1084 const KUrl::List kdeUrls
= selectedUrls();
1085 const KUrl::List mostLocalUrls
;
1086 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
1087 QApplication::clipboard()->setMimeData(mimeData
);
1090 void DolphinView::paste()
1092 QClipboard
* clipboard
= QApplication::clipboard();
1093 const QMimeData
* mimeData
= clipboard
->mimeData();
1095 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1097 // per default the pasting is done into the current Url of the view
1098 KUrl
destUrl(url());
1100 // check whether the pasting should be done into a selected directory
1101 const KUrl::List selectedUrls
= this->selectedUrls();
1102 if (selectedUrls
.count() == 1) {
1103 const KFileItem
fileItem(S_IFDIR
,
1105 selectedUrls
.first(),
1107 if (fileItem
.isDir()) {
1108 // only one item is selected which is a directory, hence paste
1109 // into this directory
1110 destUrl
= selectedUrls
.first();
1114 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1115 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, destUrl
);
1116 emit
doingOperation(KonqFileUndoManager::MOVE
);
1119 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, destUrl
);
1120 emit
doingOperation(KonqFileUndoManager::COPY
);
1124 QPair
<bool, QString
> DolphinView::pasteInfo() const
1126 QPair
<bool, QString
> ret
;
1127 QClipboard
* clipboard
= QApplication::clipboard();
1128 const QMimeData
* mimeData
= clipboard
->mimeData();
1130 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1131 if (!urls
.isEmpty()) {
1133 ret
.second
= i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls
.count());
1136 ret
.second
= i18nc("@action:inmenu", "Paste");
1140 const KFileItemList items
= selectedItems();
1141 const uint count
= items
.count();
1143 // pasting should not be allowed when more than one file
1146 } else if (count
== 1) {
1147 // Only one file is selected. Pasting is only allowed if this
1148 // file is a directory.
1149 ret
.first
= items
.first().isDir();
1155 #include "dolphinview.moc"