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"
22 #include <ktoggleaction.h>
23 #include <kactioncollection.h>
25 #include <QApplication>
28 #include <QItemSelection>
33 #include <kcolorscheme.h>
34 #include <kdirlister.h>
35 #include <kfileitemdelegate.h>
36 #include <kiconeffect.h>
38 #include <kio/deletejob.h>
39 #include <kio/netaccess.h>
40 #include <kio/previewjob.h>
43 #include <kmimetyperesolver.h>
44 #include <konq_operations.h>
45 #include <konqmimedata.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 m_iconManager
= new IconManager(this, m_dolphinModel
);
125 applyViewProperties(url
);
126 m_topLayout
->addWidget(itemView());
129 DolphinView::~DolphinView()
133 const KUrl
& DolphinView::url() const
135 return m_controller
->url();
138 KUrl
DolphinView::rootUrl() const
140 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
143 void DolphinView::setActive(bool active
)
145 if (active
== m_active
) {
150 m_selectionModel
->clearSelection();
152 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
154 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
155 // bypasses the problem when having a split view and changing the active view to
156 // update the some URL dependent states. A nicer approach should be no big deal...
157 emit
urlChanged(url());
158 emit
selectionChanged(selectedItems());
163 QWidget
* viewport
= itemView()->viewport();
165 palette
.setColor(viewport
->backgroundRole(), color
);
166 viewport
->setPalette(palette
);
174 m_controller
->indicateActivationChange(active
);
177 bool DolphinView::isActive() const
182 void DolphinView::setMode(Mode mode
)
184 if (mode
== m_mode
) {
185 return; // the wished mode is already set
190 if (isColumnViewActive()) {
191 // When changing the mode in the column view, it makes sense
192 // to go back to the root URL of the column view automatically.
193 // Otherwise there it would not be possible to turn off the column view
194 // without focusing the first column.
195 const KUrl root
= rootUrl();
197 m_controller
->setUrl(root
);
202 const KUrl viewPropsUrl
= viewPropertiesUrl();
203 ViewProperties
props(viewPropsUrl
);
204 props
.setViewMode(m_mode
);
207 // the file item delegate has been recreated, apply the current
208 // additional information manually
209 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
210 m_fileItemDelegate
->setShowInformation(infoList
);
211 emit
additionalInfoChanged(infoList
);
213 // Not all view modes support categorized sorting. Adjust the sorting model
214 // if changing the view mode results in a change of the categorized sorting
216 m_storedCategorizedSorting
= props
.categorizedSorting();
217 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
218 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
219 m_proxyModel
->setCategorizedModel(categorized
);
220 emit
categorizedSortingChanged();
226 DolphinView::Mode
DolphinView::mode() const
231 void DolphinView::setShowPreview(bool show
)
233 if (m_showPreview
== show
) {
237 const KUrl viewPropsUrl
= viewPropertiesUrl();
238 ViewProperties
props(viewPropsUrl
);
239 props
.setShowPreview(show
);
241 m_showPreview
= show
;
242 m_iconManager
->setShowPreview(show
);
243 emit
showPreviewChanged();
245 loadDirectory(viewPropsUrl
, true);
248 bool DolphinView::showPreview() const
250 return m_showPreview
;
253 void DolphinView::setShowHiddenFiles(bool show
)
255 if (m_dirLister
->showingDotFiles() == show
) {
259 const KUrl viewPropsUrl
= viewPropertiesUrl();
260 ViewProperties
props(viewPropsUrl
);
261 props
.setShowHiddenFiles(show
);
263 m_dirLister
->setShowingDotFiles(show
);
264 emit
showHiddenFilesChanged();
266 loadDirectory(viewPropsUrl
, true);
269 bool DolphinView::showHiddenFiles() const
271 return m_dirLister
->showingDotFiles();
274 void DolphinView::setCategorizedSorting(bool categorized
)
276 if (categorized
== categorizedSorting()) {
280 // setCategorizedSorting(true) may only get invoked
281 // if the view supports categorized sorting
282 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
284 ViewProperties
props(viewPropertiesUrl());
285 props
.setCategorizedSorting(categorized
);
288 m_storedCategorizedSorting
= categorized
;
289 m_proxyModel
->setCategorizedModel(categorized
);
291 emit
categorizedSortingChanged();
294 bool DolphinView::categorizedSorting() const
296 // If all view modes would support categorized sorting, returning
297 // m_proxyModel->isCategorizedModel() would be the way to go. As
298 // currently only the icons view supports caterized sorting, we remember
299 // the stored view properties state in m_storedCategorizedSorting and
300 // return this state. The application takes care to disable the corresponding
301 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
302 // that this setting is not applied to the current view mode.
303 return m_storedCategorizedSorting
;
306 bool DolphinView::supportsCategorizedSorting() const
308 return m_iconsView
!= 0;
311 void DolphinView::selectAll()
313 QAbstractItemView
* view
= itemView();
314 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
315 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
316 // selection instead of selecting all items. This is bypassed for KDE 4.0
317 // by invoking clearSelection() first.
318 view
->clearSelection();
322 void DolphinView::invertSelection()
324 if (isColumnViewActive()) {
325 // QAbstractItemView does not offer a virtual method invertSelection()
326 // as counterpart to QAbstractItemView::selectAll(). This makes it
327 // necessary to delegate the inverting of the selection to the
328 // column view, as only the selection of the active column should
330 m_columnView
->invertSelection();
332 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
333 const QAbstractItemModel
* itemModel
= selectionModel
->model();
335 const QModelIndex topLeft
= itemModel
->index(0, 0);
336 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
337 itemModel
->columnCount() - 1);
339 const QItemSelection
selection(topLeft
, bottomRight
);
340 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
344 bool DolphinView::hasSelection() const
346 return itemView()->selectionModel()->hasSelection();
349 void DolphinView::clearSelection()
351 itemView()->selectionModel()->clear();
354 KFileItemList
DolphinView::selectedItems() const
356 const QAbstractItemView
* view
= itemView();
358 // Our view has a selection, we will map them back to the DolphinModel
359 // and then fill the KFileItemList.
360 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
362 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
363 KFileItemList itemList
;
365 const QModelIndexList indexList
= selection
.indexes();
366 foreach (QModelIndex index
, indexList
) {
367 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
368 if (!item
.isNull()) {
369 itemList
.append(item
);
376 KUrl::List
DolphinView::selectedUrls() const
379 const KFileItemList list
= selectedItems();
380 foreach (KFileItem item
, list
) {
381 urls
.append(item
.url());
386 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
388 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
389 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
392 void DolphinView::setContentsPosition(int x
, int y
)
394 QAbstractItemView
* view
= itemView();
396 // the ColumnView takes care itself for the horizontal scrolling
397 if (!isColumnViewActive()) {
398 view
->horizontalScrollBar()->setValue(x
);
400 view
->verticalScrollBar()->setValue(y
);
402 m_loadingDirectory
= false;
405 QPoint
DolphinView::contentsPosition() const
407 const int x
= itemView()->horizontalScrollBar()->value();
408 const int y
= itemView()->verticalScrollBar()->value();
412 void DolphinView::zoomIn()
414 m_controller
->triggerZoomIn();
417 void DolphinView::zoomOut()
419 m_controller
->triggerZoomOut();
422 bool DolphinView::isZoomInPossible() const
424 return m_controller
->isZoomInPossible();
427 bool DolphinView::isZoomOutPossible() const
429 return m_controller
->isZoomOutPossible();
432 void DolphinView::setSorting(Sorting sorting
)
434 if (sorting
!= this->sorting()) {
435 updateSorting(sorting
);
439 DolphinView::Sorting
DolphinView::sorting() const
441 return m_proxyModel
->sorting();
444 void DolphinView::setSortOrder(Qt::SortOrder order
)
446 if (sortOrder() != order
) {
447 updateSortOrder(order
);
451 Qt::SortOrder
DolphinView::sortOrder() const
453 return m_proxyModel
->sortOrder();
456 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
458 const KUrl viewPropsUrl
= viewPropertiesUrl();
459 ViewProperties
props(viewPropsUrl
);
460 props
.setAdditionalInfo(info
);
461 m_fileItemDelegate
->setShowInformation(info
);
463 emit
additionalInfoChanged(info
);
465 if (itemView() != m_detailsView
) {
466 // the details view requires no reloading of the directory, as it maps
467 // the file item delegate info to its columns internally
468 loadDirectory(viewPropsUrl
, true);
472 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
474 return m_fileItemDelegate
->showInformation();
477 void DolphinView::reload()
480 loadDirectory(url(), true);
483 void DolphinView::refresh()
485 const bool oldActivationState
= m_active
;
489 applyViewProperties(m_controller
->url());
492 setActive(oldActivationState
);
495 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
497 if (m_controller
->url() == url
) {
501 m_controller
->setUrl(url
); // emits urlChanged, which we forward
503 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
504 applyViewProperties(rootUrl
);
505 loadDirectory(rootUrl
);
506 if (itemView() == m_columnView
) {
507 m_columnView
->setRootUrl(rootUrl
);
508 m_columnView
->showColumn(url
);
511 applyViewProperties(url
);
515 emit
startedPathLoading(url
);
518 void DolphinView::setNameFilter(const QString
& nameFilter
)
520 m_proxyModel
->setFilterRegExp(nameFilter
);
522 if (isColumnViewActive()) {
523 // adjusting the directory lister is not enough in the case of the
524 // column view, as each column has its own directory lister internally...
525 m_columnView
->setNameFilter(nameFilter
);
529 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
531 foreach (KFileItem item
, m_dirLister
->items()) {
540 void DolphinView::setUrl(const KUrl
& url
)
542 updateView(url
, KUrl());
545 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
547 QWidget::mouseReleaseEvent(event
);
550 void DolphinView::activate()
555 void DolphinView::triggerItem(const KFileItem
& item
)
557 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
558 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
559 // items are selected by the user, hence don't trigger the
560 // item specified by 'index'
568 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
571 void DolphinView::emitSelectionChangedSignal()
573 emit
selectionChanged(DolphinView::selectedItems());
576 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
578 if (!url
.isValid()) {
579 const QString
location(url
.pathOrUrl());
580 if (location
.isEmpty()) {
581 emit
errorMessage(i18nc("@info:status", "The location is empty."));
583 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
588 m_loadingDirectory
= true;
591 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
593 if (isColumnViewActive()) {
594 // adjusting the directory lister is not enough in the case of the
595 // column view, as each column has its own directory lister internally...
597 m_columnView
->reload();
599 m_columnView
->showColumn(url
);
604 KUrl
DolphinView::viewPropertiesUrl() const
606 if (isColumnViewActive()) {
607 return m_dirLister
->url();
613 void DolphinView::applyViewProperties(const KUrl
& url
)
615 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
616 // The column view is active, hence don't apply the view properties
617 // of sub directories (represented by columns) to the view. The
618 // view always represents the properties of the first column.
622 const ViewProperties
props(url
);
624 const Mode mode
= props
.viewMode();
625 if (m_mode
!= mode
) {
630 if (itemView() == 0) {
633 Q_ASSERT(itemView() != 0);
634 Q_ASSERT(m_fileItemDelegate
!= 0);
636 const bool showHiddenFiles
= props
.showHiddenFiles();
637 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
638 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
639 emit
showHiddenFilesChanged();
642 m_storedCategorizedSorting
= props
.categorizedSorting();
643 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
644 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
645 m_proxyModel
->setCategorizedModel(categorized
);
646 emit
categorizedSortingChanged();
649 const DolphinView::Sorting sorting
= props
.sorting();
650 if (sorting
!= m_proxyModel
->sorting()) {
651 m_proxyModel
->setSorting(sorting
);
652 emit
sortingChanged(sorting
);
655 const Qt::SortOrder sortOrder
= props
.sortOrder();
656 if (sortOrder
!= m_proxyModel
->sortOrder()) {
657 m_proxyModel
->setSortOrder(sortOrder
);
658 emit
sortOrderChanged(sortOrder
);
661 KFileItemDelegate::InformationList info
= props
.additionalInfo();
662 if (info
!= m_fileItemDelegate
->showInformation()) {
663 m_fileItemDelegate
->setShowInformation(info
);
664 emit
additionalInfoChanged(info
);
667 const bool showPreview
= props
.showPreview();
668 if (showPreview
!= m_showPreview
) {
669 m_showPreview
= showPreview
;
670 m_iconManager
->setShowPreview(showPreview
);
671 emit
showPreviewChanged();
675 void DolphinView::changeSelection(const KFileItemList
& selection
)
678 if (selection
.isEmpty()) {
681 const KUrl
& baseUrl
= url();
683 QItemSelection new_selection
;
684 foreach(const KFileItem
& item
, selection
) {
685 url
= item
.url().upUrl();
686 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
687 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
688 new_selection
.select(index
, index
);
691 itemView()->selectionModel()->select(new_selection
,
692 QItemSelectionModel::ClearAndSelect
693 | QItemSelectionModel::Current
);
696 void DolphinView::openContextMenu(const QPoint
& pos
)
700 const QModelIndex index
= itemView()->indexAt(pos
);
701 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
702 item
= fileItem(index
);
705 emit
requestContextMenu(item
, url());
708 void DolphinView::dropUrls(const KUrl::List
& urls
,
709 const KUrl
& destPath
,
710 const KFileItem
& destItem
)
712 Q_ASSERT(!urls
.isEmpty());
713 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
714 destItem
.url() : destPath
;
715 const KUrl sourceDir
= KUrl(urls
.first().directory());
716 if (sourceDir
!= destination
) {
717 dropUrls(urls
, destination
);
721 void DolphinView::dropUrls(const KUrl::List
& urls
,
722 const KUrl
& destination
)
724 DolphinDropController
dropController(this);
725 // forward doingOperation signal up to the mainwindow
726 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
727 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
728 dropController
.dropUrls(urls
, destination
);
731 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
733 ViewProperties
props(viewPropertiesUrl());
734 props
.setSorting(sorting
);
736 m_proxyModel
->setSorting(sorting
);
738 emit
sortingChanged(sorting
);
741 void DolphinView::updateSortOrder(Qt::SortOrder order
)
743 ViewProperties
props(viewPropertiesUrl());
744 props
.setSortOrder(order
);
746 m_proxyModel
->setSortOrder(order
);
748 emit
sortOrderChanged(order
);
751 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
753 ViewProperties
props(viewPropertiesUrl());
754 props
.setAdditionalInfo(info
);
757 m_fileItemDelegate
->setShowInformation(info
);
759 emit
additionalInfoChanged(info
);
763 void DolphinView::emitContentsMoved()
765 // only emit the contents moved signal if:
766 // - no directory loading is ongoing (this would reset the contents position
768 // - if the Column View is active: the column view does an automatic
769 // positioning during the loading operation, which must be remembered
770 if (!m_loadingDirectory
|| isColumnViewActive()) {
771 const QPoint
pos(contentsPosition());
772 emit
contentsMoved(pos
.x(), pos
.y());
776 void DolphinView::showHoverInformation(const KFileItem
& item
)
778 if (hasSelection() || !m_active
) {
782 emit
requestItemInfo(item
);
785 void DolphinView::clearHoverInformation()
788 emit
requestItemInfo(KFileItem());
792 void DolphinView::createView()
795 Q_ASSERT(m_iconsView
== 0);
796 Q_ASSERT(m_detailsView
== 0);
797 Q_ASSERT(m_columnView
== 0);
799 QAbstractItemView
* view
= 0;
802 m_iconsView
= new DolphinIconsView(this, m_controller
);
808 m_detailsView
= new DolphinDetailsView(this, m_controller
);
809 view
= m_detailsView
;
813 m_columnView
= new DolphinColumnView(this, m_controller
);
820 m_fileItemDelegate
= new KFileItemDelegate(view
);
821 view
->setItemDelegate(m_fileItemDelegate
);
823 view
->setModel(m_proxyModel
);
824 if (m_selectionModel
!= 0) {
825 view
->setSelectionModel(m_selectionModel
);
827 m_selectionModel
= view
->selectionModel();
830 // reparent the selection model, as it should not be deleted
831 // when deleting the model
832 m_selectionModel
->setParent(this);
834 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
836 new KMimeTypeResolver(view
, m_dolphinModel
);
837 m_topLayout
->insertWidget(1, view
);
839 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
840 this, SLOT(emitSelectionChangedSignal()));
841 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
842 this, SLOT(emitContentsMoved()));
843 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
844 this, SLOT(emitContentsMoved()));
847 void DolphinView::deleteView()
849 QAbstractItemView
* view
= itemView();
851 m_topLayout
->removeWidget(view
);
858 m_fileItemDelegate
= 0;
862 QAbstractItemView
* DolphinView::itemView() const
864 if (m_detailsView
!= 0) {
865 return m_detailsView
;
866 } else if (m_columnView
!= 0) {
873 bool DolphinView::isCutItem(const KFileItem
& item
) const
875 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
876 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
878 const KUrl
& itemUrl
= item
.url();
879 KUrl::List::const_iterator it
= cutUrls
.begin();
880 const KUrl::List::const_iterator end
= cutUrls
.end();
882 if (*it
== itemUrl
) {
891 KToggleAction
* DolphinView::iconsModeAction(KActionCollection
* actionCollection
)
893 KToggleAction
* iconsView
= actionCollection
->add
<KToggleAction
>("icons");
894 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
895 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
896 iconsView
->setIcon(KIcon("view-list-icons"));
897 iconsView
->setData(QVariant::fromValue(IconsView
));
901 KToggleAction
* DolphinView::detailsModeAction(KActionCollection
* actionCollection
)
903 KToggleAction
* detailsView
= actionCollection
->add
<KToggleAction
>("details");
904 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
905 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
906 detailsView
->setIcon(KIcon("view-list-details"));
907 detailsView
->setData(QVariant::fromValue(DetailsView
));
911 KToggleAction
* DolphinView::columnsModeAction(KActionCollection
* actionCollection
)
913 KToggleAction
* columnView
= actionCollection
->add
<KToggleAction
>("columns");
914 columnView
->setText(i18nc("@action:inmenu View Mode", "Columns"));
915 columnView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
916 columnView
->setIcon(KIcon("view-file-columns"));
917 columnView
->setData(QVariant::fromValue(ColumnView
));
921 QString
DolphinView::currentViewModeActionName() const
924 case DolphinView::IconsView
:
926 case DolphinView::DetailsView
:
928 case DolphinView::ColumnView
:
931 return QString(); // can't happen
934 void DolphinView::renameSelectedItems()
936 const KFileItemList items
= selectedItems();
937 if (items
.count() > 1) {
938 // More than one item has been selected for renaming. Open
939 // a rename dialog and rename all items afterwards.
940 RenameDialog
dialog(this, items
);
941 if (dialog
.exec() == QDialog::Rejected
) {
945 const QString newName
= dialog
.newName();
946 if (newName
.isEmpty()) {
947 emit
errorMessage(dialog
.errorString());
949 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
950 // as one operation instead of n rename operations like it is done now...
951 Q_ASSERT(newName
.contains('#'));
953 // iterate through all selected items and rename them...
955 foreach (KFileItem item
, items
) {
956 const KUrl
& oldUrl
= item
.url();
958 number
.setNum(index
++);
960 QString name
= newName
;
961 name
.replace('#', number
);
963 if (oldUrl
.fileName() != name
) {
964 KUrl newUrl
= oldUrl
;
965 newUrl
.setFileName(name
);
966 KonqOperations::rename(this, oldUrl
, newUrl
);
967 emit
doingOperation(KonqFileUndoManager::RENAME
);
972 // Only one item has been selected for renaming. Use the custom
973 // renaming mechanism from the views.
974 Q_ASSERT(items
.count() == 1);
976 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
977 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
978 // is a benefit for the user at all -> let's wait for some input first...
979 RenameDialog
dialog(this, items
);
980 if (dialog
.exec() == QDialog::Rejected
) {
984 const QString
& newName
= dialog
.newName();
985 if (newName
.isEmpty()) {
986 emit
errorMessage(dialog
.errorString());
988 const KUrl
& oldUrl
= items
.first().url();
989 KUrl newUrl
= oldUrl
;
990 newUrl
.setFileName(newName
);
991 KonqOperations::rename(this, oldUrl
, newUrl
);
992 emit
doingOperation(KonqFileUndoManager::RENAME
);
997 void DolphinView::trashSelectedItems()
999 emit
doingOperation(KonqFileUndoManager::TRASH
);
1000 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
1003 void DolphinView::deleteSelectedItems()
1005 const KUrl::List list
= selectedUrls();
1006 const bool del
= KonqOperations::askDeleteConfirmation(list
,
1007 KonqOperations::DEL
,
1008 KonqOperations::DEFAULT_CONFIRMATION
,
1012 KIO::Job
* job
= KIO::del(list
);
1013 connect(job
, SIGNAL(result(KJob
*)),
1014 this, SLOT(slotDeleteFileFinished(KJob
*)));
1018 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1020 if (job
->error() == 0) {
1021 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1023 emit
errorMessage(job
->errorString());
1027 void DolphinView::cutSelectedItems()
1029 QMimeData
* mimeData
= new QMimeData();
1030 const KUrl::List kdeUrls
= selectedUrls();
1031 const KUrl::List mostLocalUrls
;
1032 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
1033 QApplication::clipboard()->setMimeData(mimeData
);
1036 void DolphinView::copySelectedItems()
1038 QMimeData
* mimeData
= new QMimeData();
1039 const KUrl::List kdeUrls
= selectedUrls();
1040 const KUrl::List mostLocalUrls
;
1041 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
1042 QApplication::clipboard()->setMimeData(mimeData
);
1045 void DolphinView::paste()
1047 QClipboard
* clipboard
= QApplication::clipboard();
1048 const QMimeData
* mimeData
= clipboard
->mimeData();
1050 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1052 // per default the pasting is done into the current Url of the view
1053 KUrl
destUrl(url());
1055 // check whether the pasting should be done into a selected directory
1056 const KUrl::List selectedUrls
= this->selectedUrls();
1057 if (selectedUrls
.count() == 1) {
1058 const KFileItem
fileItem(S_IFDIR
,
1060 selectedUrls
.first(),
1062 if (fileItem
.isDir()) {
1063 // only one item is selected which is a directory, hence paste
1064 // into this directory
1065 destUrl
= selectedUrls
.first();
1069 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1070 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, destUrl
);
1071 emit
doingOperation(KonqFileUndoManager::MOVE
);
1074 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, destUrl
);
1075 emit
doingOperation(KonqFileUndoManager::COPY
);
1079 QPair
<bool, QString
> DolphinView::pasteInfo() const
1081 QPair
<bool, QString
> ret
;
1082 QClipboard
* clipboard
= QApplication::clipboard();
1083 const QMimeData
* mimeData
= clipboard
->mimeData();
1085 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1086 if (!urls
.isEmpty()) {
1088 ret
.second
= i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls
.count());
1091 ret
.second
= i18nc("@action:inmenu", "Paste");
1095 const KFileItemList items
= selectedItems();
1096 const uint count
= items
.count();
1098 // pasting should not be allowed when more than one file
1101 } else if (count
== 1) {
1102 // Only one file is selected. Pasting is only allowed if this
1103 // file is a directory.
1104 ret
.first
= items
.first().isDir();
1110 KAction
* DolphinView::createRenameAction(KActionCollection
* collection
)
1112 KAction
* rename
= collection
->addAction("rename");
1113 rename
->setText(i18nc("@action:inmenu File", "Rename..."));
1114 rename
->setShortcut(Qt::Key_F2
);
1118 KAction
* DolphinView::createMoveToTrashAction(KActionCollection
* collection
)
1120 KAction
* moveToTrash
= collection
->addAction("move_to_trash");
1121 moveToTrash
->setText(i18nc("@action:inmenu File", "Move to Trash"));
1122 moveToTrash
->setIcon(KIcon("user-trash"));
1123 moveToTrash
->setShortcut(QKeySequence::Delete
);
1127 KAction
* DolphinView::createDeleteAction(KActionCollection
* collection
)
1129 KAction
* deleteAction
= collection
->addAction("delete");
1130 deleteAction
->setIcon(KIcon("edit-delete"));
1131 deleteAction
->setText(i18nc("@action:inmenu File", "Delete"));
1132 deleteAction
->setShortcut(Qt::SHIFT
| Qt::Key_Delete
);
1133 return deleteAction
;
1136 #include "dolphinview.moc"