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
188 if (isColumnViewActive()) {
189 // When changing the mode in the column view, it makes sense
190 // to go back to the root URL of the column view automatically.
191 // Otherwise there it would not be possible to turn off the column view
192 // without focusing the first column.
193 const KUrl root
= rootUrl();
195 m_controller
->setUrl(root
);
200 const KUrl viewPropsUrl
= viewPropertiesUrl();
201 ViewProperties
props(viewPropsUrl
);
202 props
.setViewMode(m_mode
);
205 // the file item delegate has been recreated, apply the current
206 // additional information manually
207 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
208 m_fileItemDelegate
->setShowInformation(infoList
);
209 emit
additionalInfoChanged(infoList
);
211 // Not all view modes support categorized sorting. Adjust the sorting model
212 // if changing the view mode results in a change of the categorized sorting
214 m_storedCategorizedSorting
= props
.categorizedSorting();
215 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
216 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
217 m_proxyModel
->setCategorizedModel(categorized
);
218 emit
categorizedSortingChanged();
224 DolphinView::Mode
DolphinView::mode() const
229 void DolphinView::setShowPreview(bool show
)
231 if (m_showPreview
== show
) {
235 const KUrl viewPropsUrl
= viewPropertiesUrl();
236 ViewProperties
props(viewPropsUrl
);
237 props
.setShowPreview(show
);
239 m_showPreview
= show
;
240 m_iconManager
->setShowPreview(show
);
241 emit
showPreviewChanged();
243 loadDirectory(viewPropsUrl
, true);
246 bool DolphinView::showPreview() const
248 return m_showPreview
;
251 void DolphinView::setShowHiddenFiles(bool show
)
253 if (m_dirLister
->showingDotFiles() == show
) {
257 const KUrl viewPropsUrl
= viewPropertiesUrl();
258 ViewProperties
props(viewPropsUrl
);
259 props
.setShowHiddenFiles(show
);
261 m_dirLister
->setShowingDotFiles(show
);
262 emit
showHiddenFilesChanged();
264 loadDirectory(viewPropsUrl
, true);
267 bool DolphinView::showHiddenFiles() const
269 return m_dirLister
->showingDotFiles();
272 void DolphinView::setCategorizedSorting(bool categorized
)
274 if (categorized
== categorizedSorting()) {
278 // setCategorizedSorting(true) may only get invoked
279 // if the view supports categorized sorting
280 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
282 ViewProperties
props(viewPropertiesUrl());
283 props
.setCategorizedSorting(categorized
);
286 m_storedCategorizedSorting
= categorized
;
287 m_proxyModel
->setCategorizedModel(categorized
);
289 emit
categorizedSortingChanged();
292 bool DolphinView::categorizedSorting() const
294 // If all view modes would support categorized sorting, returning
295 // m_proxyModel->isCategorizedModel() would be the way to go. As
296 // currently only the icons view supports caterized sorting, we remember
297 // the stored view properties state in m_storedCategorizedSorting and
298 // return this state. The application takes care to disable the corresponding
299 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
300 // that this setting is not applied to the current view mode.
301 return m_storedCategorizedSorting
;
304 bool DolphinView::supportsCategorizedSorting() const
306 return m_iconsView
!= 0;
309 void DolphinView::selectAll()
311 QAbstractItemView
* view
= itemView();
312 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
313 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
314 // selection instead of selecting all items. This is bypassed for KDE 4.0
315 // by invoking clearSelection() first.
316 view
->clearSelection();
320 void DolphinView::invertSelection()
322 if (isColumnViewActive()) {
323 // QAbstractItemView does not offer a virtual method invertSelection()
324 // as counterpart to QAbstractItemView::selectAll(). This makes it
325 // necessary to delegate the inverting of the selection to the
326 // column view, as only the selection of the active column should
328 m_columnView
->invertSelection();
330 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
331 const QAbstractItemModel
* itemModel
= selectionModel
->model();
333 const QModelIndex topLeft
= itemModel
->index(0, 0);
334 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
335 itemModel
->columnCount() - 1);
337 const QItemSelection
selection(topLeft
, bottomRight
);
338 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
342 bool DolphinView::hasSelection() const
344 return itemView()->selectionModel()->hasSelection();
347 void DolphinView::clearSelection()
349 itemView()->selectionModel()->clear();
352 KFileItemList
DolphinView::selectedItems() const
354 const QAbstractItemView
* view
= itemView();
356 // Our view has a selection, we will map them back to the DolphinModel
357 // and then fill the KFileItemList.
358 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
360 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
361 KFileItemList itemList
;
363 const QModelIndexList indexList
= selection
.indexes();
364 foreach (QModelIndex index
, indexList
) {
365 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
366 if (!item
.isNull()) {
367 itemList
.append(item
);
374 KUrl::List
DolphinView::selectedUrls() const
377 const KFileItemList list
= selectedItems();
378 foreach (KFileItem item
, list
) {
379 urls
.append(item
.url());
384 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
386 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
387 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
390 void DolphinView::setContentsPosition(int x
, int y
)
392 QAbstractItemView
* view
= itemView();
394 // the ColumnView takes care itself for the horizontal scrolling
395 if (!isColumnViewActive()) {
396 view
->horizontalScrollBar()->setValue(x
);
398 view
->verticalScrollBar()->setValue(y
);
400 m_loadingDirectory
= false;
403 QPoint
DolphinView::contentsPosition() const
405 const int x
= itemView()->horizontalScrollBar()->value();
406 const int y
= itemView()->verticalScrollBar()->value();
410 void DolphinView::zoomIn()
412 m_controller
->triggerZoomIn();
415 void DolphinView::zoomOut()
417 m_controller
->triggerZoomOut();
420 bool DolphinView::isZoomInPossible() const
422 return m_controller
->isZoomInPossible();
425 bool DolphinView::isZoomOutPossible() const
427 return m_controller
->isZoomOutPossible();
430 void DolphinView::setSorting(Sorting sorting
)
432 if (sorting
!= this->sorting()) {
433 updateSorting(sorting
);
437 DolphinView::Sorting
DolphinView::sorting() const
439 return m_proxyModel
->sorting();
442 void DolphinView::setSortOrder(Qt::SortOrder order
)
444 if (sortOrder() != order
) {
445 updateSortOrder(order
);
449 Qt::SortOrder
DolphinView::sortOrder() const
451 return m_proxyModel
->sortOrder();
454 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
456 const KUrl viewPropsUrl
= viewPropertiesUrl();
457 ViewProperties
props(viewPropsUrl
);
458 props
.setAdditionalInfo(info
);
459 m_fileItemDelegate
->setShowInformation(info
);
461 emit
additionalInfoChanged(info
);
463 if (itemView() != m_detailsView
) {
464 // the details view requires no reloading of the directory, as it maps
465 // the file item delegate info to its columns internally
466 loadDirectory(viewPropsUrl
, true);
470 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
472 return m_fileItemDelegate
->showInformation();
475 void DolphinView::reload()
478 loadDirectory(url(), true);
481 void DolphinView::refresh()
483 const bool oldActivationState
= m_active
;
487 applyViewProperties(m_controller
->url());
490 setActive(oldActivationState
);
493 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
495 if (m_controller
->url() == url
) {
499 m_controller
->setUrl(url
); // emits urlChanged, which we forward
501 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
502 applyViewProperties(rootUrl
);
503 loadDirectory(rootUrl
);
504 if (itemView() == m_columnView
) {
505 m_columnView
->setRootUrl(rootUrl
);
506 m_columnView
->showColumn(url
);
509 applyViewProperties(url
);
513 emit
startedPathLoading(url
);
516 void DolphinView::setNameFilter(const QString
& nameFilter
)
518 m_proxyModel
->setFilterRegExp(nameFilter
);
520 if (isColumnViewActive()) {
521 // adjusting the directory lister is not enough in the case of the
522 // column view, as each column has its own directory lister internally...
523 m_columnView
->setNameFilter(nameFilter
);
527 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
529 foreach (KFileItem item
, m_dirLister
->items()) {
538 void DolphinView::setUrl(const KUrl
& url
)
540 updateView(url
, KUrl());
543 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
545 QWidget::mouseReleaseEvent(event
);
548 void DolphinView::activate()
553 void DolphinView::triggerItem(const KFileItem
& item
)
555 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
556 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
557 // items are selected by the user, hence don't trigger the
558 // item specified by 'index'
566 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
569 void DolphinView::emitSelectionChangedSignal()
571 emit
selectionChanged(DolphinView::selectedItems());
574 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
576 if (!url
.isValid()) {
577 const QString
location(url
.pathOrUrl());
578 if (location
.isEmpty()) {
579 emit
errorMessage(i18nc("@info:status", "The location is empty."));
581 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
586 m_loadingDirectory
= true;
589 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
591 if (isColumnViewActive()) {
592 // adjusting the directory lister is not enough in the case of the
593 // column view, as each column has its own directory lister internally...
595 m_columnView
->reload();
597 m_columnView
->showColumn(url
);
602 KUrl
DolphinView::viewPropertiesUrl() const
604 if (isColumnViewActive()) {
605 return m_dirLister
->url();
611 void DolphinView::applyViewProperties(const KUrl
& url
)
613 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
614 // The column view is active, hence don't apply the view properties
615 // of sub directories (represented by columns) to the view. The
616 // view always represents the properties of the first column.
620 const ViewProperties
props(url
);
622 const Mode mode
= props
.viewMode();
623 if (m_mode
!= mode
) {
628 if (itemView() == 0) {
631 Q_ASSERT(itemView() != 0);
632 Q_ASSERT(m_fileItemDelegate
!= 0);
634 const bool showHiddenFiles
= props
.showHiddenFiles();
635 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
636 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
637 emit
showHiddenFilesChanged();
640 m_storedCategorizedSorting
= props
.categorizedSorting();
641 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
642 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
643 m_proxyModel
->setCategorizedModel(categorized
);
644 emit
categorizedSortingChanged();
647 const DolphinView::Sorting sorting
= props
.sorting();
648 if (sorting
!= m_proxyModel
->sorting()) {
649 m_proxyModel
->setSorting(sorting
);
650 emit
sortingChanged(sorting
);
653 const Qt::SortOrder sortOrder
= props
.sortOrder();
654 if (sortOrder
!= m_proxyModel
->sortOrder()) {
655 m_proxyModel
->setSortOrder(sortOrder
);
656 emit
sortOrderChanged(sortOrder
);
659 KFileItemDelegate::InformationList info
= props
.additionalInfo();
660 if (info
!= m_fileItemDelegate
->showInformation()) {
661 m_fileItemDelegate
->setShowInformation(info
);
662 emit
additionalInfoChanged(info
);
665 const bool showPreview
= props
.showPreview();
666 if (showPreview
!= m_showPreview
) {
667 m_showPreview
= showPreview
;
668 m_iconManager
->setShowPreview(showPreview
);
669 emit
showPreviewChanged();
673 void DolphinView::changeSelection(const KFileItemList
& selection
)
676 if (selection
.isEmpty()) {
679 const KUrl
& baseUrl
= url();
681 QItemSelection new_selection
;
682 foreach(const KFileItem
& item
, selection
) {
683 url
= item
.url().upUrl();
684 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
685 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
686 new_selection
.select(index
, index
);
689 itemView()->selectionModel()->select(new_selection
,
690 QItemSelectionModel::ClearAndSelect
691 | QItemSelectionModel::Current
);
694 void DolphinView::openContextMenu(const QPoint
& pos
)
698 const QModelIndex index
= itemView()->indexAt(pos
);
699 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
700 item
= fileItem(index
);
703 emit
requestContextMenu(item
, url());
706 void DolphinView::dropUrls(const KUrl::List
& urls
,
707 const KUrl
& destPath
,
708 const KFileItem
& destItem
)
710 Q_ASSERT(!urls
.isEmpty());
711 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
712 destItem
.url() : destPath
;
713 const KUrl sourceDir
= KUrl(urls
.first().directory());
714 if (sourceDir
!= destination
) {
715 dropUrls(urls
, destination
);
719 void DolphinView::dropUrls(const KUrl::List
& urls
,
720 const KUrl
& destination
)
722 DolphinDropController
dropController(this);
723 // forward doingOperation signal up to the mainwindow
724 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
725 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
726 dropController
.dropUrls(urls
, destination
);
729 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
731 ViewProperties
props(viewPropertiesUrl());
732 props
.setSorting(sorting
);
734 m_proxyModel
->setSorting(sorting
);
736 emit
sortingChanged(sorting
);
739 void DolphinView::updateSortOrder(Qt::SortOrder order
)
741 ViewProperties
props(viewPropertiesUrl());
742 props
.setSortOrder(order
);
744 m_proxyModel
->setSortOrder(order
);
746 emit
sortOrderChanged(order
);
749 void DolphinView::toggleSortOrder()
751 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
752 Qt::DescendingOrder
:
757 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
759 ViewProperties
props(viewPropertiesUrl());
760 props
.setAdditionalInfo(info
);
763 m_fileItemDelegate
->setShowInformation(info
);
765 emit
additionalInfoChanged(info
);
769 void DolphinView::emitContentsMoved()
771 // only emit the contents moved signal if:
772 // - no directory loading is ongoing (this would reset the contents position
774 // - if the Column View is active: the column view does an automatic
775 // positioning during the loading operation, which must be remembered
776 if (!m_loadingDirectory
|| isColumnViewActive()) {
777 const QPoint
pos(contentsPosition());
778 emit
contentsMoved(pos
.x(), pos
.y());
782 void DolphinView::showHoverInformation(const KFileItem
& item
)
784 if (hasSelection() || !m_active
) {
788 emit
requestItemInfo(item
);
791 void DolphinView::clearHoverInformation()
794 emit
requestItemInfo(KFileItem());
798 void DolphinView::createView()
801 Q_ASSERT(m_iconsView
== 0);
802 Q_ASSERT(m_detailsView
== 0);
803 Q_ASSERT(m_columnView
== 0);
805 QAbstractItemView
* view
= 0;
808 m_iconsView
= new DolphinIconsView(this, m_controller
);
814 m_detailsView
= new DolphinDetailsView(this, m_controller
);
815 view
= m_detailsView
;
819 m_columnView
= new DolphinColumnView(this, m_controller
);
826 m_fileItemDelegate
= new KFileItemDelegate(view
);
827 view
->setItemDelegate(m_fileItemDelegate
);
829 view
->setModel(m_proxyModel
);
830 if (m_selectionModel
!= 0) {
831 view
->setSelectionModel(m_selectionModel
);
833 m_selectionModel
= view
->selectionModel();
836 // reparent the selection model, as it should not be deleted
837 // when deleting the model
838 m_selectionModel
->setParent(this);
840 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
842 new KMimeTypeResolver(view
, m_dolphinModel
);
843 m_iconManager
= new IconManager(view
, m_proxyModel
);
844 m_iconManager
->setShowPreview(m_showPreview
);
846 m_topLayout
->insertWidget(1, view
);
848 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
849 this, SLOT(emitSelectionChangedSignal()));
850 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
851 this, SLOT(emitContentsMoved()));
852 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
853 this, SLOT(emitContentsMoved()));
856 void DolphinView::deleteView()
858 QAbstractItemView
* view
= itemView();
860 m_topLayout
->removeWidget(view
);
867 m_fileItemDelegate
= 0;
872 QAbstractItemView
* DolphinView::itemView() const
874 if (m_detailsView
!= 0) {
875 return m_detailsView
;
876 } else if (m_columnView
!= 0) {
883 bool DolphinView::isCutItem(const KFileItem
& item
) const
885 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
886 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
888 const KUrl
& itemUrl
= item
.url();
889 KUrl::List::const_iterator it
= cutUrls
.begin();
890 const KUrl::List::const_iterator end
= cutUrls
.end();
892 if (*it
== itemUrl
) {
901 KToggleAction
* DolphinView::iconsModeAction(KActionCollection
* actionCollection
)
903 KToggleAction
* iconsView
= actionCollection
->add
<KToggleAction
>("icons");
904 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
905 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
906 iconsView
->setIcon(KIcon("view-list-icons"));
907 iconsView
->setData(QVariant::fromValue(IconsView
));
911 KToggleAction
* DolphinView::detailsModeAction(KActionCollection
* actionCollection
)
913 KToggleAction
* detailsView
= actionCollection
->add
<KToggleAction
>("details");
914 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
915 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
916 detailsView
->setIcon(KIcon("view-list-details"));
917 detailsView
->setData(QVariant::fromValue(DetailsView
));
921 KToggleAction
* DolphinView::columnsModeAction(KActionCollection
* actionCollection
)
923 KToggleAction
* columnView
= actionCollection
->add
<KToggleAction
>("columns");
924 columnView
->setText(i18nc("@action:inmenu View Mode", "Columns"));
925 columnView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
926 columnView
->setIcon(KIcon("view-file-columns"));
927 columnView
->setData(QVariant::fromValue(ColumnView
));
931 QString
DolphinView::currentViewModeActionName() const
934 case DolphinView::IconsView
:
936 case DolphinView::DetailsView
:
938 case DolphinView::ColumnView
:
941 return QString(); // can't happen
944 void DolphinView::renameSelectedItems()
946 const KFileItemList items
= selectedItems();
947 if (items
.count() > 1) {
948 // More than one item has been selected for renaming. Open
949 // a rename dialog and rename all items afterwards.
950 RenameDialog
dialog(this, items
);
951 if (dialog
.exec() == QDialog::Rejected
) {
955 const QString newName
= dialog
.newName();
956 if (newName
.isEmpty()) {
957 emit
errorMessage(dialog
.errorString());
959 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
960 // as one operation instead of n rename operations like it is done now...
961 Q_ASSERT(newName
.contains('#'));
963 // iterate through all selected items and rename them...
965 foreach (KFileItem item
, items
) {
966 const KUrl
& oldUrl
= item
.url();
968 number
.setNum(index
++);
970 QString name
= newName
;
971 name
.replace('#', number
);
973 if (oldUrl
.fileName() != name
) {
974 KUrl newUrl
= oldUrl
;
975 newUrl
.setFileName(name
);
976 KonqOperations::rename(this, oldUrl
, newUrl
);
977 emit
doingOperation(KonqFileUndoManager::RENAME
);
982 // Only one item has been selected for renaming. Use the custom
983 // renaming mechanism from the views.
984 Q_ASSERT(items
.count() == 1);
986 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
987 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
988 // is a benefit for the user at all -> let's wait for some input first...
989 RenameDialog
dialog(this, items
);
990 if (dialog
.exec() == QDialog::Rejected
) {
994 const QString
& newName
= dialog
.newName();
995 if (newName
.isEmpty()) {
996 emit
errorMessage(dialog
.errorString());
998 const KUrl
& oldUrl
= items
.first().url();
999 KUrl newUrl
= oldUrl
;
1000 newUrl
.setFileName(newName
);
1001 KonqOperations::rename(this, oldUrl
, newUrl
);
1002 emit
doingOperation(KonqFileUndoManager::RENAME
);
1007 void DolphinView::trashSelectedItems()
1009 emit
doingOperation(KonqFileUndoManager::TRASH
);
1010 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
1013 void DolphinView::deleteSelectedItems()
1015 const KUrl::List list
= selectedUrls();
1016 const bool del
= KonqOperations::askDeleteConfirmation(list
,
1017 KonqOperations::DEL
,
1018 KonqOperations::DEFAULT_CONFIRMATION
,
1022 KIO::Job
* job
= KIO::del(list
);
1023 connect(job
, SIGNAL(result(KJob
*)),
1024 this, SLOT(slotDeleteFileFinished(KJob
*)));
1028 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1030 if (job
->error() == 0) {
1031 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1033 emit
errorMessage(job
->errorString());
1037 void DolphinView::cutSelectedItems()
1039 QMimeData
* mimeData
= new QMimeData();
1040 const KUrl::List kdeUrls
= selectedUrls();
1041 const KUrl::List mostLocalUrls
;
1042 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
1043 QApplication::clipboard()->setMimeData(mimeData
);
1046 void DolphinView::copySelectedItems()
1048 QMimeData
* mimeData
= new QMimeData();
1049 const KUrl::List kdeUrls
= selectedUrls();
1050 const KUrl::List mostLocalUrls
;
1051 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
1052 QApplication::clipboard()->setMimeData(mimeData
);
1055 void DolphinView::paste()
1057 QClipboard
* clipboard
= QApplication::clipboard();
1058 const QMimeData
* mimeData
= clipboard
->mimeData();
1060 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1062 // per default the pasting is done into the current Url of the view
1063 KUrl
destUrl(url());
1065 // check whether the pasting should be done into a selected directory
1066 const KUrl::List selectedUrls
= this->selectedUrls();
1067 if (selectedUrls
.count() == 1) {
1068 const KFileItem
fileItem(S_IFDIR
,
1070 selectedUrls
.first(),
1072 if (fileItem
.isDir()) {
1073 // only one item is selected which is a directory, hence paste
1074 // into this directory
1075 destUrl
= selectedUrls
.first();
1079 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1080 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, destUrl
);
1081 emit
doingOperation(KonqFileUndoManager::MOVE
);
1084 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, destUrl
);
1085 emit
doingOperation(KonqFileUndoManager::COPY
);
1089 QPair
<bool, QString
> DolphinView::pasteInfo() const
1091 QPair
<bool, QString
> ret
;
1092 QClipboard
* clipboard
= QApplication::clipboard();
1093 const QMimeData
* mimeData
= clipboard
->mimeData();
1095 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1096 if (!urls
.isEmpty()) {
1098 ret
.second
= i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls
.count());
1101 ret
.second
= i18nc("@action:inmenu", "Paste");
1105 const KFileItemList items
= selectedItems();
1106 const uint count
= items
.count();
1108 // pasting should not be allowed when more than one file
1111 } else if (count
== 1) {
1112 // Only one file is selected. Pasting is only allowed if this
1113 // file is a directory.
1114 ret
.first
= items
.first().isDir();
1120 KAction
* DolphinView::createRenameAction(KActionCollection
* collection
)
1122 KAction
* rename
= collection
->addAction("rename");
1123 rename
->setText(i18nc("@action:inmenu File", "Rename..."));
1124 rename
->setShortcut(Qt::Key_F2
);
1128 KAction
* DolphinView::createMoveToTrashAction(KActionCollection
* collection
)
1130 KAction
* moveToTrash
= collection
->addAction("move_to_trash");
1131 moveToTrash
->setText(i18nc("@action:inmenu File", "Move to Trash"));
1132 moveToTrash
->setIcon(KIcon("user-trash"));
1133 moveToTrash
->setShortcut(QKeySequence::Delete
);
1137 KAction
* DolphinView::createDeleteAction(KActionCollection
* collection
)
1139 KAction
* deleteAction
= collection
->addAction("delete");
1140 deleteAction
->setIcon(KIcon("edit-delete"));
1141 deleteAction
->setText(i18nc("@action:inmenu File", "Delete"));
1142 deleteAction
->setShortcut(Qt::SHIFT
| Qt::Key_Delete
);
1143 return deleteAction
;
1146 KAction
* DolphinView::createNewDirAction(KActionCollection
* collection
)
1148 // This action doesn't appear in the GUI, it's for the shortcut only.
1149 // KNewMenu takes care of the GUI stuff.
1150 KAction
* newDirAction
= collection
->addAction("create_dir");
1151 newDirAction
->setText(i18n("Create Folder..."));
1152 newDirAction
->setShortcut(Qt::Key_F10
);
1153 return newDirAction
;
1156 KAction
* DolphinView::createSortDescendingAction(KActionCollection
* collection
)
1158 KToggleAction
* sortDescending
= collection
->add
<KToggleAction
>("descending");
1159 sortDescending
->setText(i18nc("@action:inmenu Sort", "Descending"));
1160 return sortDescending
;
1163 #include "dolphinview.moc"