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
);
540 void DolphinView::activate()
545 void DolphinView::triggerItem(const KFileItem
& item
)
547 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
548 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
549 // items are selected by the user, hence don't trigger the
550 // item specified by 'index'
558 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
561 void DolphinView::emitSelectionChangedSignal()
563 emit
selectionChanged(DolphinView::selectedItems());
566 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
568 if (!url
.isValid()) {
569 const QString
location(url
.pathOrUrl());
570 if (location
.isEmpty()) {
571 emit
errorMessage(i18nc("@info:status", "The location is empty."));
573 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
578 m_loadingDirectory
= true;
581 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
583 if (isColumnViewActive()) {
584 // adjusting the directory lister is not enough in the case of the
585 // column view, as each column has its own directory lister internally...
587 m_columnView
->reload();
589 m_columnView
->showColumn(url
);
594 KUrl
DolphinView::viewPropertiesUrl() const
596 if (isColumnViewActive()) {
597 return m_dirLister
->url();
603 void DolphinView::applyViewProperties(const KUrl
& url
)
605 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
606 // The column view is active, hence don't apply the view properties
607 // of sub directories (represented by columns) to the view. The
608 // view always represents the properties of the first column.
612 const ViewProperties
props(url
);
614 const Mode mode
= props
.viewMode();
615 if (m_mode
!= mode
) {
620 if (itemView() == 0) {
623 Q_ASSERT(itemView() != 0);
624 Q_ASSERT(m_fileItemDelegate
!= 0);
626 const bool showHiddenFiles
= props
.showHiddenFiles();
627 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
628 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
629 emit
showHiddenFilesChanged();
632 m_storedCategorizedSorting
= props
.categorizedSorting();
633 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
634 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
635 m_proxyModel
->setCategorizedModel(categorized
);
636 emit
categorizedSortingChanged();
639 const DolphinView::Sorting sorting
= props
.sorting();
640 if (sorting
!= m_proxyModel
->sorting()) {
641 m_proxyModel
->setSorting(sorting
);
642 emit
sortingChanged(sorting
);
645 const Qt::SortOrder sortOrder
= props
.sortOrder();
646 if (sortOrder
!= m_proxyModel
->sortOrder()) {
647 m_proxyModel
->setSortOrder(sortOrder
);
648 emit
sortOrderChanged(sortOrder
);
651 KFileItemDelegate::InformationList info
= props
.additionalInfo();
652 if (info
!= m_fileItemDelegate
->showInformation()) {
653 m_fileItemDelegate
->setShowInformation(info
);
654 emit
additionalInfoChanged();
657 const bool showPreview
= props
.showPreview();
658 if (showPreview
!= m_showPreview
) {
659 m_showPreview
= showPreview
;
660 m_iconManager
->setShowPreview(showPreview
);
661 emit
showPreviewChanged();
665 void DolphinView::changeSelection(const KFileItemList
& selection
)
668 if (selection
.isEmpty()) {
671 const KUrl
& baseUrl
= url();
673 QItemSelection new_selection
;
674 foreach(const KFileItem
& item
, selection
) {
675 url
= item
.url().upUrl();
676 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
677 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
678 new_selection
.select(index
, index
);
681 itemView()->selectionModel()->select(new_selection
,
682 QItemSelectionModel::ClearAndSelect
683 | QItemSelectionModel::Current
);
686 void DolphinView::openContextMenu(const QPoint
& pos
)
690 const QModelIndex index
= itemView()->indexAt(pos
);
691 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
692 item
= fileItem(index
);
695 emit
requestContextMenu(item
, url());
698 void DolphinView::dropUrls(const KUrl::List
& urls
,
699 const KUrl
& destPath
,
700 const KFileItem
& destItem
)
702 Q_ASSERT(!urls
.isEmpty());
703 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
704 destItem
.url() : destPath
;
705 const KUrl sourceDir
= KUrl(urls
.first().directory());
706 if (sourceDir
!= destination
) {
707 dropUrls(urls
, destination
);
711 void DolphinView::dropUrls(const KUrl::List
& urls
,
712 const KUrl
& destination
)
714 DolphinDropController
dropController(this);
715 // forward doingOperation signal up to the mainwindow
716 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
717 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
718 dropController
.dropUrls(urls
, destination
);
721 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
723 ViewProperties
props(viewPropertiesUrl());
724 props
.setSorting(sorting
);
726 m_proxyModel
->setSorting(sorting
);
728 emit
sortingChanged(sorting
);
731 void DolphinView::updateSortOrder(Qt::SortOrder order
)
733 ViewProperties
props(viewPropertiesUrl());
734 props
.setSortOrder(order
);
736 m_proxyModel
->setSortOrder(order
);
738 emit
sortOrderChanged(order
);
741 void DolphinView::toggleSortOrder()
743 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
744 Qt::DescendingOrder
:
749 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
751 ViewProperties
props(viewPropertiesUrl());
752 props
.setAdditionalInfo(info
);
755 m_fileItemDelegate
->setShowInformation(info
);
757 emit
additionalInfoChanged();
760 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
762 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
763 (m_mode
== DolphinView::IconsView
);
765 QAction
* showSizeInfo
= collection
->action("show_size_info");
766 QAction
* showDateInfo
= collection
->action("show_date_info");
767 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
768 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
769 QAction
* showGroupInfo
= collection
->action("show_group_info");
770 QAction
* showMimeInfo
= collection
->action("show_mime_info");
772 showSizeInfo
->setChecked(false);
773 showDateInfo
->setChecked(false);
774 showPermissionsInfo
->setChecked(false);
775 showOwnerInfo
->setChecked(false);
776 showGroupInfo
->setChecked(false);
777 showMimeInfo
->setChecked(false);
779 showSizeInfo
->setEnabled(enable
);
780 showDateInfo
->setEnabled(enable
);
781 showPermissionsInfo
->setEnabled(enable
);
782 showOwnerInfo
->setEnabled(enable
);
783 showGroupInfo
->setEnabled(enable
);
784 showMimeInfo
->setEnabled(enable
);
786 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
788 case KFileItemDelegate::Size
:
789 showSizeInfo
->setChecked(true);
791 case KFileItemDelegate::ModificationTime
:
792 showDateInfo
->setChecked(true);
794 case KFileItemDelegate::Permissions
:
795 showPermissionsInfo
->setChecked(true);
797 case KFileItemDelegate::Owner
:
798 showOwnerInfo
->setChecked(true);
800 case KFileItemDelegate::OwnerAndGroup
:
801 showGroupInfo
->setChecked(true);
803 case KFileItemDelegate::FriendlyMimeType
:
804 showMimeInfo
->setChecked(true);
812 void DolphinView::toggleAdditionalInfo(QAction
* action
)
814 const KFileItemDelegate::Information info
=
815 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
817 KFileItemDelegate::InformationList list
= additionalInfo();
819 const bool show
= action
->isChecked();
821 const int index
= list
.indexOf(info
);
822 const bool containsInfo
= (index
>= 0);
823 if (show
&& !containsInfo
) {
825 setAdditionalInfo(list
);
826 } else if (!show
&& containsInfo
) {
827 list
.removeAt(index
);
828 setAdditionalInfo(list
);
829 Q_ASSERT(list
.indexOf(info
) < 0);
833 void DolphinView::emitContentsMoved()
835 // only emit the contents moved signal if:
836 // - no directory loading is ongoing (this would reset the contents position
838 // - if the Column View is active: the column view does an automatic
839 // positioning during the loading operation, which must be remembered
840 if (!m_loadingDirectory
|| isColumnViewActive()) {
841 const QPoint
pos(contentsPosition());
842 emit
contentsMoved(pos
.x(), pos
.y());
846 void DolphinView::showHoverInformation(const KFileItem
& item
)
848 if (hasSelection() || !m_active
) {
852 emit
requestItemInfo(item
);
855 void DolphinView::clearHoverInformation()
858 emit
requestItemInfo(KFileItem());
862 void DolphinView::createView()
865 Q_ASSERT(m_iconsView
== 0);
866 Q_ASSERT(m_detailsView
== 0);
867 Q_ASSERT(m_columnView
== 0);
869 QAbstractItemView
* view
= 0;
872 m_iconsView
= new DolphinIconsView(this, m_controller
);
878 m_detailsView
= new DolphinDetailsView(this, m_controller
);
879 view
= m_detailsView
;
883 m_columnView
= new DolphinColumnView(this, m_controller
);
890 m_fileItemDelegate
= new KFileItemDelegate(view
);
891 view
->setItemDelegate(m_fileItemDelegate
);
893 view
->setModel(m_proxyModel
);
894 if (m_selectionModel
!= 0) {
895 view
->setSelectionModel(m_selectionModel
);
897 m_selectionModel
= view
->selectionModel();
900 // reparent the selection model, as it should not be deleted
901 // when deleting the model
902 m_selectionModel
->setParent(this);
904 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
906 new KMimeTypeResolver(view
, m_dolphinModel
);
907 m_iconManager
= new IconManager(view
, m_proxyModel
);
908 m_iconManager
->setShowPreview(m_showPreview
);
910 m_topLayout
->insertWidget(1, view
);
912 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
913 this, SLOT(emitSelectionChangedSignal()));
914 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
915 this, SLOT(emitContentsMoved()));
916 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
917 this, SLOT(emitContentsMoved()));
920 void DolphinView::deleteView()
922 QAbstractItemView
* view
= itemView();
924 m_topLayout
->removeWidget(view
);
931 m_fileItemDelegate
= 0;
936 QAbstractItemView
* DolphinView::itemView() const
938 if (m_detailsView
!= 0) {
939 return m_detailsView
;
940 } else if (m_columnView
!= 0) {
947 bool DolphinView::isCutItem(const KFileItem
& item
) const
949 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
950 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
952 const KUrl
& itemUrl
= item
.url();
953 KUrl::List::const_iterator it
= cutUrls
.begin();
954 const KUrl::List::const_iterator end
= cutUrls
.end();
956 if (*it
== itemUrl
) {
965 KToggleAction
* DolphinView::iconsModeAction(KActionCollection
* actionCollection
)
967 KToggleAction
* iconsView
= actionCollection
->add
<KToggleAction
>("icons");
968 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
969 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
970 iconsView
->setIcon(KIcon("view-list-icons"));
971 iconsView
->setData(QVariant::fromValue(IconsView
));
975 KToggleAction
* DolphinView::detailsModeAction(KActionCollection
* actionCollection
)
977 KToggleAction
* detailsView
= actionCollection
->add
<KToggleAction
>("details");
978 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
979 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
980 detailsView
->setIcon(KIcon("view-list-details"));
981 detailsView
->setData(QVariant::fromValue(DetailsView
));
985 KToggleAction
* DolphinView::columnsModeAction(KActionCollection
* actionCollection
)
987 KToggleAction
* columnView
= actionCollection
->add
<KToggleAction
>("columns");
988 columnView
->setText(i18nc("@action:inmenu View Mode", "Columns"));
989 columnView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
990 columnView
->setIcon(KIcon("view-file-columns"));
991 columnView
->setData(QVariant::fromValue(ColumnView
));
995 QString
DolphinView::currentViewModeActionName() const
998 case DolphinView::IconsView
:
1000 case DolphinView::DetailsView
:
1002 case DolphinView::ColumnView
:
1005 return QString(); // can't happen
1008 void DolphinView::renameSelectedItems()
1010 const KFileItemList items
= selectedItems();
1011 if (items
.count() > 1) {
1012 // More than one item has been selected for renaming. Open
1013 // a rename dialog and rename all items afterwards.
1014 RenameDialog
dialog(this, items
);
1015 if (dialog
.exec() == QDialog::Rejected
) {
1019 const QString newName
= dialog
.newName();
1020 if (newName
.isEmpty()) {
1021 emit
errorMessage(dialog
.errorString());
1023 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
1024 // as one operation instead of n rename operations like it is done now...
1025 Q_ASSERT(newName
.contains('#'));
1027 // iterate through all selected items and rename them...
1029 foreach (KFileItem item
, items
) {
1030 const KUrl
& oldUrl
= item
.url();
1032 number
.setNum(index
++);
1034 QString name
= newName
;
1035 name
.replace('#', number
);
1037 if (oldUrl
.fileName() != name
) {
1038 KUrl newUrl
= oldUrl
;
1039 newUrl
.setFileName(name
);
1040 KonqOperations::rename(this, oldUrl
, newUrl
);
1041 emit
doingOperation(KonqFileUndoManager::RENAME
);
1046 // Only one item has been selected for renaming. Use the custom
1047 // renaming mechanism from the views.
1048 Q_ASSERT(items
.count() == 1);
1050 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
1051 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
1052 // is a benefit for the user at all -> let's wait for some input first...
1053 RenameDialog
dialog(this, items
);
1054 if (dialog
.exec() == QDialog::Rejected
) {
1058 const QString
& newName
= dialog
.newName();
1059 if (newName
.isEmpty()) {
1060 emit
errorMessage(dialog
.errorString());
1062 const KUrl
& oldUrl
= items
.first().url();
1063 KUrl newUrl
= oldUrl
;
1064 newUrl
.setFileName(newName
);
1065 KonqOperations::rename(this, oldUrl
, newUrl
);
1066 emit
doingOperation(KonqFileUndoManager::RENAME
);
1071 void DolphinView::trashSelectedItems()
1073 emit
doingOperation(KonqFileUndoManager::TRASH
);
1074 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
1077 void DolphinView::deleteSelectedItems()
1079 const KUrl::List list
= selectedUrls();
1080 const bool del
= KonqOperations::askDeleteConfirmation(list
,
1081 KonqOperations::DEL
,
1082 KonqOperations::DEFAULT_CONFIRMATION
,
1086 KIO::Job
* job
= KIO::del(list
);
1087 connect(job
, SIGNAL(result(KJob
*)),
1088 this, SLOT(slotDeleteFileFinished(KJob
*)));
1092 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1094 if (job
->error() == 0) {
1095 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1097 emit
errorMessage(job
->errorString());
1101 void DolphinView::cutSelectedItems()
1103 QMimeData
* mimeData
= new QMimeData();
1104 const KUrl::List kdeUrls
= selectedUrls();
1105 const KUrl::List mostLocalUrls
;
1106 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
1107 QApplication::clipboard()->setMimeData(mimeData
);
1110 void DolphinView::copySelectedItems()
1112 QMimeData
* mimeData
= new QMimeData();
1113 const KUrl::List kdeUrls
= selectedUrls();
1114 const KUrl::List mostLocalUrls
;
1115 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
1116 QApplication::clipboard()->setMimeData(mimeData
);
1119 void DolphinView::paste()
1121 QClipboard
* clipboard
= QApplication::clipboard();
1122 const QMimeData
* mimeData
= clipboard
->mimeData();
1124 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1126 // per default the pasting is done into the current Url of the view
1127 KUrl
destUrl(url());
1129 // check whether the pasting should be done into a selected directory
1130 const KUrl::List selectedUrls
= this->selectedUrls();
1131 if (selectedUrls
.count() == 1) {
1132 const KFileItem
fileItem(S_IFDIR
,
1134 selectedUrls
.first(),
1136 if (fileItem
.isDir()) {
1137 // only one item is selected which is a directory, hence paste
1138 // into this directory
1139 destUrl
= selectedUrls
.first();
1143 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1144 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, destUrl
);
1145 emit
doingOperation(KonqFileUndoManager::MOVE
);
1148 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, destUrl
);
1149 emit
doingOperation(KonqFileUndoManager::COPY
);
1153 QPair
<bool, QString
> DolphinView::pasteInfo() const
1155 QPair
<bool, QString
> ret
;
1156 QClipboard
* clipboard
= QApplication::clipboard();
1157 const QMimeData
* mimeData
= clipboard
->mimeData();
1159 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1160 if (!urls
.isEmpty()) {
1162 ret
.second
= i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls
.count());
1165 ret
.second
= i18nc("@action:inmenu", "Paste");
1169 const KFileItemList items
= selectedItems();
1170 const uint count
= items
.count();
1172 // pasting should not be allowed when more than one file
1175 } else if (count
== 1) {
1176 // Only one file is selected. Pasting is only allowed if this
1177 // file is a directory.
1178 ret
.first
= items
.first().isDir();
1184 #include "dolphinview.moc"