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 m_controller
= new DolphinController(this);
90 m_controller
->setUrl(url
);
92 // Receiver of the DolphinView signal 'urlChanged()' don't need
93 // to care whether the internal controller changed the URL already or whether
94 // the controller just requested an URL change and will be updated later.
95 // In both cases the URL has been changed:
96 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
97 this, SIGNAL(urlChanged(const KUrl
&)));
98 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
99 this, SIGNAL(urlChanged(const KUrl
&)));
101 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
102 this, SLOT(openContextMenu(const QPoint
&)));
103 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
104 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
105 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
106 this, SLOT(updateSorting(DolphinView::Sorting
)));
107 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
108 this, SLOT(updateSortOrder(Qt::SortOrder
)));
109 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
110 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
111 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
112 this, SLOT(triggerItem(const KFileItem
&)));
113 connect(m_controller
, SIGNAL(activated()),
114 this, SLOT(activate()));
115 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
116 this, SLOT(showHoverInformation(const KFileItem
&)));
117 connect(m_controller
, SIGNAL(viewportEntered()),
118 this, SLOT(clearHoverInformation()));
120 applyViewProperties(url
);
121 m_topLayout
->addWidget(itemView());
124 DolphinView::~DolphinView()
128 const KUrl
& DolphinView::url() const
130 return m_controller
->url();
133 KUrl
DolphinView::rootUrl() const
135 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
138 void DolphinView::setActive(bool active
)
140 if (active
== m_active
) {
145 m_selectionModel
->clearSelection();
147 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
149 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
150 // bypasses the problem when having a split view and changing the active view to
151 // update the some URL dependent states. A nicer approach should be no big deal...
152 emit
urlChanged(url());
153 emit
selectionChanged(selectedItems());
158 QWidget
* viewport
= itemView()->viewport();
160 palette
.setColor(viewport
->backgroundRole(), color
);
161 viewport
->setPalette(palette
);
169 m_controller
->indicateActivationChange(active
);
172 bool DolphinView::isActive() const
177 void DolphinView::setMode(Mode mode
)
179 if (mode
== m_mode
) {
180 return; // the wished mode is already set
187 const KUrl viewPropsUrl
= viewPropertiesUrl();
188 ViewProperties
props(viewPropsUrl
);
189 props
.setViewMode(m_mode
);
192 // the file item delegate has been recreated, apply the current
193 // additional information manually
194 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
195 m_fileItemDelegate
->setShowInformation(infoList
);
196 emit
additionalInfoChanged();
198 // Not all view modes support categorized sorting. Adjust the sorting model
199 // if changing the view mode results in a change of the categorized sorting
201 m_storedCategorizedSorting
= props
.categorizedSorting();
202 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
203 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
204 m_proxyModel
->setCategorizedModel(categorized
);
205 emit
categorizedSortingChanged();
211 DolphinView::Mode
DolphinView::mode() const
216 void DolphinView::setShowPreview(bool show
)
218 if (m_showPreview
== show
) {
222 const KUrl viewPropsUrl
= viewPropertiesUrl();
223 ViewProperties
props(viewPropsUrl
);
224 props
.setShowPreview(show
);
226 m_showPreview
= show
;
227 m_iconManager
->setShowPreview(show
);
228 emit
showPreviewChanged();
230 loadDirectory(viewPropsUrl
, true);
233 bool DolphinView::showPreview() const
235 return m_showPreview
;
238 void DolphinView::setShowHiddenFiles(bool show
)
240 if (m_dirLister
->showingDotFiles() == show
) {
244 const KUrl viewPropsUrl
= viewPropertiesUrl();
245 ViewProperties
props(viewPropsUrl
);
246 props
.setShowHiddenFiles(show
);
248 m_dirLister
->setShowingDotFiles(show
);
249 emit
showHiddenFilesChanged();
251 loadDirectory(viewPropsUrl
, true);
254 bool DolphinView::showHiddenFiles() const
256 return m_dirLister
->showingDotFiles();
259 void DolphinView::setCategorizedSorting(bool categorized
)
261 if (categorized
== categorizedSorting()) {
265 // setCategorizedSorting(true) may only get invoked
266 // if the view supports categorized sorting
267 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
269 ViewProperties
props(viewPropertiesUrl());
270 props
.setCategorizedSorting(categorized
);
273 m_storedCategorizedSorting
= categorized
;
274 m_proxyModel
->setCategorizedModel(categorized
);
276 emit
categorizedSortingChanged();
279 bool DolphinView::categorizedSorting() const
281 // If all view modes would support categorized sorting, returning
282 // m_proxyModel->isCategorizedModel() would be the way to go. As
283 // currently only the icons view supports caterized sorting, we remember
284 // the stored view properties state in m_storedCategorizedSorting and
285 // return this state. The application takes care to disable the corresponding
286 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
287 // that this setting is not applied to the current view mode.
288 return m_storedCategorizedSorting
;
291 bool DolphinView::supportsCategorizedSorting() const
293 return m_iconsView
!= 0;
296 void DolphinView::selectAll()
298 QAbstractItemView
* view
= itemView();
299 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
300 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
301 // selection instead of selecting all items. This is bypassed for KDE 4.0
302 // by invoking clearSelection() first.
303 view
->clearSelection();
307 void DolphinView::invertSelection()
309 if (isColumnViewActive()) {
310 // QAbstractItemView does not offer a virtual method invertSelection()
311 // as counterpart to QAbstractItemView::selectAll(). This makes it
312 // necessary to delegate the inverting of the selection to the
313 // column view, as only the selection of the active column should
315 m_columnView
->invertSelection();
317 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
318 const QAbstractItemModel
* itemModel
= selectionModel
->model();
320 const QModelIndex topLeft
= itemModel
->index(0, 0);
321 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
322 itemModel
->columnCount() - 1);
324 const QItemSelection
selection(topLeft
, bottomRight
);
325 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
329 bool DolphinView::hasSelection() const
331 return itemView()->selectionModel()->hasSelection();
334 void DolphinView::clearSelection()
336 itemView()->selectionModel()->clear();
339 KFileItemList
DolphinView::selectedItems() const
341 const QAbstractItemView
* view
= itemView();
343 // Our view has a selection, we will map them back to the DolphinModel
344 // and then fill the KFileItemList.
345 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
347 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
348 KFileItemList itemList
;
350 const QModelIndexList indexList
= selection
.indexes();
351 foreach (QModelIndex index
, indexList
) {
352 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
353 if (!item
.isNull()) {
354 itemList
.append(item
);
361 KUrl::List
DolphinView::selectedUrls() const
364 const KFileItemList list
= selectedItems();
365 foreach (KFileItem item
, list
) {
366 urls
.append(item
.url());
371 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
373 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
374 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
377 void DolphinView::setContentsPosition(int x
, int y
)
379 QAbstractItemView
* view
= itemView();
381 // the ColumnView takes care itself for the horizontal scrolling
382 if (!isColumnViewActive()) {
383 view
->horizontalScrollBar()->setValue(x
);
385 view
->verticalScrollBar()->setValue(y
);
387 m_loadingDirectory
= false;
390 QPoint
DolphinView::contentsPosition() const
392 const int x
= itemView()->horizontalScrollBar()->value();
393 const int y
= itemView()->verticalScrollBar()->value();
397 void DolphinView::zoomIn()
399 m_controller
->triggerZoomIn();
403 void DolphinView::zoomOut()
405 m_controller
->triggerZoomOut();
409 bool DolphinView::isZoomInPossible() const
411 return m_controller
->isZoomInPossible();
414 bool DolphinView::isZoomOutPossible() const
416 return m_controller
->isZoomOutPossible();
419 void DolphinView::setSorting(Sorting sorting
)
421 if (sorting
!= this->sorting()) {
422 updateSorting(sorting
);
426 DolphinView::Sorting
DolphinView::sorting() const
428 return m_proxyModel
->sorting();
431 void DolphinView::setSortOrder(Qt::SortOrder order
)
433 if (sortOrder() != order
) {
434 updateSortOrder(order
);
438 Qt::SortOrder
DolphinView::sortOrder() const
440 return m_proxyModel
->sortOrder();
443 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
445 const KUrl viewPropsUrl
= viewPropertiesUrl();
446 ViewProperties
props(viewPropsUrl
);
447 props
.setAdditionalInfo(info
);
448 m_fileItemDelegate
->setShowInformation(info
);
450 emit
additionalInfoChanged();
452 if (itemView() != m_detailsView
) {
453 // the details view requires no reloading of the directory, as it maps
454 // the file item delegate info to its columns internally
455 loadDirectory(viewPropsUrl
, true);
459 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
461 return m_fileItemDelegate
->showInformation();
464 void DolphinView::reload()
467 loadDirectory(url(), true);
470 void DolphinView::refresh()
472 const bool oldActivationState
= m_active
;
476 applyViewProperties(m_controller
->url());
479 setActive(oldActivationState
);
482 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
484 if (m_controller
->url() == url
) {
488 m_controller
->setUrl(url
); // emits urlChanged, which we forward
490 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
491 applyViewProperties(rootUrl
);
492 loadDirectory(rootUrl
);
493 if (itemView() == m_columnView
) {
494 m_columnView
->setRootUrl(rootUrl
);
495 m_columnView
->showColumn(url
);
498 applyViewProperties(url
);
502 emit
startedPathLoading(url
);
505 void DolphinView::setNameFilter(const QString
& nameFilter
)
507 m_proxyModel
->setFilterRegExp(nameFilter
);
509 if (isColumnViewActive()) {
510 // adjusting the directory lister is not enough in the case of the
511 // column view, as each column has its own directory lister internally...
512 m_columnView
->setNameFilter(nameFilter
);
516 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
518 foreach (KFileItem item
, m_dirLister
->items()) {
527 void DolphinView::setUrl(const KUrl
& url
)
529 updateView(url
, KUrl());
532 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
534 QWidget::mouseReleaseEvent(event
);
538 void DolphinView::wheelEvent(QWheelEvent
* event
)
540 if ((event
->modifiers() & Qt::ControlModifier
) == Qt::ControlModifier
) {
541 int d
= event
->delta();
542 if (d
> 0 && isZoomInPossible()) {
544 } else if (d
< 0 && isZoomOutPossible()) {
551 void DolphinView::activate()
556 void DolphinView::triggerItem(const KFileItem
& item
)
558 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
559 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
560 // items are selected by the user, hence don't trigger the
561 // item specified by 'index'
569 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
572 void DolphinView::emitSelectionChangedSignal()
574 emit
selectionChanged(DolphinView::selectedItems());
577 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
579 if (!url
.isValid()) {
580 const QString
location(url
.pathOrUrl());
581 if (location
.isEmpty()) {
582 emit
errorMessage(i18nc("@info:status", "The location is empty."));
584 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
589 m_loadingDirectory
= true;
592 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
594 if (isColumnViewActive()) {
595 // adjusting the directory lister is not enough in the case of the
596 // column view, as each column has its own directory lister internally...
598 m_columnView
->reload();
600 m_columnView
->showColumn(url
);
605 KUrl
DolphinView::viewPropertiesUrl() const
607 if (isColumnViewActive()) {
608 return m_columnView
->rootUrl();
614 void DolphinView::applyViewProperties(const KUrl
& url
)
616 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
617 // The column view is active, hence don't apply the view properties
618 // of sub directories (represented by columns) to the view. The
619 // view always represents the properties of the first column.
623 const ViewProperties
props(url
);
625 const Mode mode
= props
.viewMode();
626 if (m_mode
!= mode
) {
631 if (itemView() == 0) {
634 Q_ASSERT(itemView() != 0);
635 Q_ASSERT(m_fileItemDelegate
!= 0);
637 const bool showHiddenFiles
= props
.showHiddenFiles();
638 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
639 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
640 emit
showHiddenFilesChanged();
643 m_storedCategorizedSorting
= props
.categorizedSorting();
644 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
645 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
646 m_proxyModel
->setCategorizedModel(categorized
);
647 emit
categorizedSortingChanged();
650 const DolphinView::Sorting sorting
= props
.sorting();
651 if (sorting
!= m_proxyModel
->sorting()) {
652 m_proxyModel
->setSorting(sorting
);
653 emit
sortingChanged(sorting
);
656 const Qt::SortOrder sortOrder
= props
.sortOrder();
657 if (sortOrder
!= m_proxyModel
->sortOrder()) {
658 m_proxyModel
->setSortOrder(sortOrder
);
659 emit
sortOrderChanged(sortOrder
);
662 KFileItemDelegate::InformationList info
= props
.additionalInfo();
663 if (info
!= m_fileItemDelegate
->showInformation()) {
664 m_fileItemDelegate
->setShowInformation(info
);
665 emit
additionalInfoChanged();
668 const bool showPreview
= props
.showPreview();
669 if (showPreview
!= m_showPreview
) {
670 m_showPreview
= showPreview
;
671 m_iconManager
->setShowPreview(showPreview
);
672 emit
showPreviewChanged();
676 void DolphinView::changeSelection(const KFileItemList
& selection
)
679 if (selection
.isEmpty()) {
682 const KUrl
& baseUrl
= url();
684 QItemSelection new_selection
;
685 foreach(const KFileItem
& item
, selection
) {
686 url
= item
.url().upUrl();
687 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
688 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
689 new_selection
.select(index
, index
);
692 itemView()->selectionModel()->select(new_selection
,
693 QItemSelectionModel::ClearAndSelect
694 | QItemSelectionModel::Current
);
697 void DolphinView::openContextMenu(const QPoint
& pos
)
701 const QModelIndex index
= itemView()->indexAt(pos
);
702 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
703 item
= fileItem(index
);
706 emit
requestContextMenu(item
, url());
709 void DolphinView::dropUrls(const KUrl::List
& urls
,
710 const KUrl
& destPath
,
711 const KFileItem
& destItem
)
713 Q_ASSERT(!urls
.isEmpty());
714 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
715 destItem
.url() : destPath
;
716 const KUrl sourceDir
= KUrl(urls
.first().directory());
717 if (sourceDir
!= destination
) {
718 dropUrls(urls
, destination
);
722 void DolphinView::dropUrls(const KUrl::List
& urls
,
723 const KUrl
& destination
)
725 DolphinDropController
dropController(this);
726 // forward doingOperation signal up to the mainwindow
727 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
728 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
729 dropController
.dropUrls(urls
, destination
);
732 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
734 ViewProperties
props(viewPropertiesUrl());
735 props
.setSorting(sorting
);
737 m_proxyModel
->setSorting(sorting
);
739 emit
sortingChanged(sorting
);
742 void DolphinView::updateSortOrder(Qt::SortOrder order
)
744 ViewProperties
props(viewPropertiesUrl());
745 props
.setSortOrder(order
);
747 m_proxyModel
->setSortOrder(order
);
749 emit
sortOrderChanged(order
);
752 void DolphinView::toggleSortOrder()
754 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
755 Qt::DescendingOrder
:
760 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
762 ViewProperties
props(viewPropertiesUrl());
763 props
.setAdditionalInfo(info
);
766 m_fileItemDelegate
->setShowInformation(info
);
768 emit
additionalInfoChanged();
771 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
773 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
774 (m_mode
== DolphinView::IconsView
);
776 QAction
* showSizeInfo
= collection
->action("show_size_info");
777 QAction
* showDateInfo
= collection
->action("show_date_info");
778 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
779 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
780 QAction
* showGroupInfo
= collection
->action("show_group_info");
781 QAction
* showMimeInfo
= collection
->action("show_mime_info");
783 showSizeInfo
->setChecked(false);
784 showDateInfo
->setChecked(false);
785 showPermissionsInfo
->setChecked(false);
786 showOwnerInfo
->setChecked(false);
787 showGroupInfo
->setChecked(false);
788 showMimeInfo
->setChecked(false);
790 showSizeInfo
->setEnabled(enable
);
791 showDateInfo
->setEnabled(enable
);
792 showPermissionsInfo
->setEnabled(enable
);
793 showOwnerInfo
->setEnabled(enable
);
794 showGroupInfo
->setEnabled(enable
);
795 showMimeInfo
->setEnabled(enable
);
797 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
799 case KFileItemDelegate::Size
:
800 showSizeInfo
->setChecked(true);
802 case KFileItemDelegate::ModificationTime
:
803 showDateInfo
->setChecked(true);
805 case KFileItemDelegate::Permissions
:
806 showPermissionsInfo
->setChecked(true);
808 case KFileItemDelegate::Owner
:
809 showOwnerInfo
->setChecked(true);
811 case KFileItemDelegate::OwnerAndGroup
:
812 showGroupInfo
->setChecked(true);
814 case KFileItemDelegate::FriendlyMimeType
:
815 showMimeInfo
->setChecked(true);
823 void DolphinView::toggleAdditionalInfo(QAction
* action
)
825 const KFileItemDelegate::Information info
=
826 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
828 KFileItemDelegate::InformationList list
= additionalInfo();
830 const bool show
= action
->isChecked();
832 const int index
= list
.indexOf(info
);
833 const bool containsInfo
= (index
>= 0);
834 if (show
&& !containsInfo
) {
836 setAdditionalInfo(list
);
837 } else if (!show
&& containsInfo
) {
838 list
.removeAt(index
);
839 setAdditionalInfo(list
);
840 Q_ASSERT(list
.indexOf(info
) < 0);
844 void DolphinView::emitContentsMoved()
846 // only emit the contents moved signal if:
847 // - no directory loading is ongoing (this would reset the contents position
849 // - if the Column View is active: the column view does an automatic
850 // positioning during the loading operation, which must be remembered
851 if (!m_loadingDirectory
|| isColumnViewActive()) {
852 const QPoint
pos(contentsPosition());
853 emit
contentsMoved(pos
.x(), pos
.y());
857 void DolphinView::showHoverInformation(const KFileItem
& item
)
859 if (hasSelection() || !m_active
) {
863 emit
requestItemInfo(item
);
866 void DolphinView::clearHoverInformation()
869 emit
requestItemInfo(KFileItem());
873 void DolphinView::createView()
876 Q_ASSERT(m_iconsView
== 0);
877 Q_ASSERT(m_detailsView
== 0);
878 Q_ASSERT(m_columnView
== 0);
880 QAbstractItemView
* view
= 0;
883 m_iconsView
= new DolphinIconsView(this, m_controller
);
889 m_detailsView
= new DolphinDetailsView(this, m_controller
);
890 view
= m_detailsView
;
894 m_columnView
= new DolphinColumnView(this, m_controller
);
901 m_fileItemDelegate
= new KFileItemDelegate(view
);
902 view
->setItemDelegate(m_fileItemDelegate
);
904 view
->setModel(m_proxyModel
);
905 if (m_selectionModel
!= 0) {
906 view
->setSelectionModel(m_selectionModel
);
908 m_selectionModel
= view
->selectionModel();
911 // reparent the selection model, as it should not be deleted
912 // when deleting the model
913 m_selectionModel
->setParent(this);
915 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
917 new KMimeTypeResolver(view
, m_dolphinModel
);
918 m_iconManager
= new IconManager(view
, m_proxyModel
);
919 m_iconManager
->setShowPreview(m_showPreview
);
921 m_topLayout
->insertWidget(1, view
);
923 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
924 this, SLOT(emitSelectionChangedSignal()));
925 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
926 this, SLOT(emitContentsMoved()));
927 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
928 this, SLOT(emitContentsMoved()));
931 void DolphinView::deleteView()
933 QAbstractItemView
* view
= itemView();
935 m_topLayout
->removeWidget(view
);
942 m_fileItemDelegate
= 0;
947 QAbstractItemView
* DolphinView::itemView() const
949 if (m_detailsView
!= 0) {
950 return m_detailsView
;
951 } else if (m_columnView
!= 0) {
958 bool DolphinView::isCutItem(const KFileItem
& item
) const
960 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
961 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
963 const KUrl
& itemUrl
= item
.url();
964 KUrl::List::const_iterator it
= cutUrls
.begin();
965 const KUrl::List::const_iterator end
= cutUrls
.end();
967 if (*it
== itemUrl
) {
976 void DolphinView::renameSelectedItems()
978 const KFileItemList items
= selectedItems();
979 if (items
.count() > 1) {
980 // More than one item has been selected for renaming. Open
981 // a rename dialog and rename all items afterwards.
982 RenameDialog
dialog(this, items
);
983 if (dialog
.exec() == QDialog::Rejected
) {
987 const QString newName
= dialog
.newName();
988 if (newName
.isEmpty()) {
989 emit
errorMessage(dialog
.errorString());
991 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
992 // as one operation instead of n rename operations like it is done now...
993 Q_ASSERT(newName
.contains('#'));
995 // iterate through all selected items and rename them...
997 foreach (KFileItem item
, items
) {
998 const KUrl
& oldUrl
= item
.url();
1000 number
.setNum(index
++);
1002 QString name
= newName
;
1003 name
.replace('#', number
);
1005 if (oldUrl
.fileName() != name
) {
1006 KUrl newUrl
= oldUrl
;
1007 newUrl
.setFileName(name
);
1008 KonqOperations::rename(this, oldUrl
, newUrl
);
1009 emit
doingOperation(KonqFileUndoManager::RENAME
);
1014 // Only one item has been selected for renaming. Use the custom
1015 // renaming mechanism from the views.
1016 Q_ASSERT(items
.count() == 1);
1018 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
1019 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
1020 // is a benefit for the user at all -> let's wait for some input first...
1021 RenameDialog
dialog(this, items
);
1022 if (dialog
.exec() == QDialog::Rejected
) {
1026 const QString
& newName
= dialog
.newName();
1027 if (newName
.isEmpty()) {
1028 emit
errorMessage(dialog
.errorString());
1030 const KUrl
& oldUrl
= items
.first().url();
1031 KUrl newUrl
= oldUrl
;
1032 newUrl
.setFileName(newName
);
1033 KonqOperations::rename(this, oldUrl
, newUrl
);
1034 emit
doingOperation(KonqFileUndoManager::RENAME
);
1039 void DolphinView::trashSelectedItems()
1041 emit
doingOperation(KonqFileUndoManager::TRASH
);
1042 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
1045 void DolphinView::deleteSelectedItems()
1047 const KUrl::List list
= selectedUrls();
1048 const bool del
= KonqOperations::askDeleteConfirmation(list
,
1049 KonqOperations::DEL
,
1050 KonqOperations::DEFAULT_CONFIRMATION
,
1054 KIO::Job
* job
= KIO::del(list
);
1055 connect(job
, SIGNAL(result(KJob
*)),
1056 this, SLOT(slotDeleteFileFinished(KJob
*)));
1060 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1062 if (job
->error() == 0) {
1063 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1065 emit
errorMessage(job
->errorString());
1069 void DolphinView::cutSelectedItems()
1071 QMimeData
* mimeData
= new QMimeData();
1072 const KUrl::List kdeUrls
= selectedUrls();
1073 const KUrl::List mostLocalUrls
;
1074 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
1075 QApplication::clipboard()->setMimeData(mimeData
);
1078 void DolphinView::copySelectedItems()
1080 QMimeData
* mimeData
= new QMimeData();
1081 const KUrl::List kdeUrls
= selectedUrls();
1082 const KUrl::List mostLocalUrls
;
1083 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
1084 QApplication::clipboard()->setMimeData(mimeData
);
1087 void DolphinView::paste()
1089 QClipboard
* clipboard
= QApplication::clipboard();
1090 const QMimeData
* mimeData
= clipboard
->mimeData();
1092 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1094 // per default the pasting is done into the current Url of the view
1095 KUrl
destUrl(url());
1097 // check whether the pasting should be done into a selected directory
1098 const KUrl::List selectedUrls
= this->selectedUrls();
1099 if (selectedUrls
.count() == 1) {
1100 const KFileItem
fileItem(S_IFDIR
,
1102 selectedUrls
.first(),
1104 if (fileItem
.isDir()) {
1105 // only one item is selected which is a directory, hence paste
1106 // into this directory
1107 destUrl
= selectedUrls
.first();
1111 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1112 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, destUrl
);
1113 emit
doingOperation(KonqFileUndoManager::MOVE
);
1116 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, destUrl
);
1117 emit
doingOperation(KonqFileUndoManager::COPY
);
1121 QPair
<bool, QString
> DolphinView::pasteInfo() const
1123 QPair
<bool, QString
> ret
;
1124 QClipboard
* clipboard
= QApplication::clipboard();
1125 const QMimeData
* mimeData
= clipboard
->mimeData();
1127 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1128 if (!urls
.isEmpty()) {
1130 ret
.second
= i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls
.count());
1133 ret
.second
= i18nc("@action:inmenu", "Paste");
1137 const KFileItemList items
= selectedItems();
1138 const uint count
= items
.count();
1140 // pasting should not be allowed when more than one file
1143 } else if (count
== 1) {
1144 // Only one file is selected. Pasting is only allowed if this
1145 // file is a directory.
1146 ret
.first
= items
.first().isDir();
1152 #include "dolphinview.moc"