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>
37 #include <kiconeffect.h>
38 #include <kio/netaccess.h>
39 #include <kio/previewjob.h>
40 #include <kmimetyperesolver.h>
41 #include <konqmimedata.h>
42 #include <konq_operations.h>
45 #include "dolphinmodel.h"
46 #include "dolphincolumnview.h"
47 #include "dolphincontroller.h"
48 #include "dolphinsortfilterproxymodel.h"
49 #include "dolphindetailsview.h"
50 #include "dolphiniconsview.h"
51 #include "renamedialog.h"
52 #include "viewproperties.h"
53 #include "dolphinsettings.h"
54 #include "dolphin_generalsettings.h"
56 DolphinView::DolphinView(QWidget
* parent
,
58 KDirLister
* dirLister
,
59 DolphinModel
* dolphinModel
,
60 DolphinSortFilterProxyModel
* proxyModel
) :
64 m_loadingDirectory(false),
65 m_storedCategorizedSorting(false),
66 m_mode(DolphinView::IconsView
),
72 m_fileItemDelegate(0),
73 m_dolphinModel(dolphinModel
),
74 m_dirLister(dirLister
),
75 m_proxyModel(proxyModel
)
77 setFocusPolicy(Qt::StrongFocus
);
78 m_topLayout
= new QVBoxLayout(this);
79 m_topLayout
->setSpacing(0);
80 m_topLayout
->setMargin(0);
82 QClipboard
* clipboard
= QApplication::clipboard();
83 connect(clipboard
, SIGNAL(dataChanged()),
84 this, SLOT(updateCutItems()));
86 connect(m_dirLister
, SIGNAL(completed()),
87 this, SLOT(updateCutItems()));
88 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
89 this, SLOT(generatePreviews(const KFileItemList
&)));
91 m_controller
= new DolphinController(this);
92 m_controller
->setUrl(url
);
94 // Receiver of the DolphinView signal 'urlChanged()' don't need
95 // to care whether the internal controller changed the URL already or whether
96 // the controller just requested an URL change and will be updated later.
97 // In both cases the URL has been changed:
98 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
99 this, SIGNAL(urlChanged(const KUrl
&)));
100 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
101 this, SIGNAL(urlChanged(const KUrl
&)));
103 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
104 this, SLOT(openContextMenu(const QPoint
&)));
105 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
106 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
107 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
108 this, SLOT(updateSorting(DolphinView::Sorting
)));
109 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
110 this, SLOT(updateSortOrder(Qt::SortOrder
)));
111 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
112 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
113 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
114 this, SLOT(triggerItem(const KFileItem
&)));
115 connect(m_controller
, SIGNAL(activated()),
116 this, SLOT(activate()));
117 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
118 this, SLOT(showHoverInformation(const KFileItem
&)));
119 connect(m_controller
, SIGNAL(viewportEntered()),
120 this, SLOT(clearHoverInformation()));
122 applyViewProperties(url
);
123 m_topLayout
->addWidget(itemView());
126 DolphinView::~DolphinView()
130 const KUrl
& DolphinView::url() const
132 return m_controller
->url();
135 KUrl
DolphinView::rootUrl() const
137 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
140 void DolphinView::setActive(bool active
)
142 if (active
== m_active
) {
148 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
150 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
151 // bypasses the problem when having a split view and changing the active view to
152 // update the some URL dependent states. A nicer approach should be no big deal...
153 emit
urlChanged(url());
154 emit
selectionChanged(selectedItems());
159 QWidget
* viewport
= itemView()->viewport();
161 palette
.setColor(viewport
->backgroundRole(), color
);
162 viewport
->setPalette(palette
);
170 m_controller
->indicateActivationChange(active
);
173 bool DolphinView::isActive() const
178 void DolphinView::setMode(Mode mode
)
180 if (mode
== m_mode
) {
181 return; // the wished mode is already set
186 if (isColumnViewActive()) {
187 // When changing the mode in the column view, it makes sense
188 // to go back to the root URL of the column view automatically.
189 // Otherwise there it would not be possible to turn off the column view
190 // without focusing the first column.
191 const KUrl root
= rootUrl();
193 m_controller
->setUrl(root
);
198 // It is important to read the view properties _after_ deleting the view,
199 // as e. g. the detail view might adjust the additional information properties
200 // after getting closed:
201 const KUrl viewPropsUrl
= viewPropertiesUrl();
202 ViewProperties
props(viewPropsUrl
);
203 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();
223 loadDirectory(viewPropsUrl
);
228 DolphinView::Mode
DolphinView::mode() const
233 void DolphinView::setShowPreview(bool show
)
235 if (m_showPreview
== show
) {
239 const KUrl viewPropsUrl
= viewPropertiesUrl();
240 ViewProperties
props(viewPropsUrl
);
241 props
.setShowPreview(show
);
243 m_showPreview
= show
;
245 emit
showPreviewChanged();
247 loadDirectory(viewPropsUrl
, true);
250 bool DolphinView::showPreview() const
252 return m_showPreview
;
255 void DolphinView::setShowHiddenFiles(bool show
)
257 if (m_dirLister
->showingDotFiles() == show
) {
261 const KUrl viewPropsUrl
= viewPropertiesUrl();
262 ViewProperties
props(viewPropsUrl
);
263 props
.setShowHiddenFiles(show
);
265 m_dirLister
->setShowingDotFiles(show
);
266 emit
showHiddenFilesChanged();
268 loadDirectory(viewPropsUrl
, true);
271 bool DolphinView::showHiddenFiles() const
273 return m_dirLister
->showingDotFiles();
276 void DolphinView::setCategorizedSorting(bool categorized
)
278 if (categorized
== categorizedSorting()) {
282 // setCategorizedSorting(true) may only get invoked
283 // if the view supports categorized sorting
284 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
286 ViewProperties
props(viewPropertiesUrl());
287 props
.setCategorizedSorting(categorized
);
290 m_storedCategorizedSorting
= categorized
;
291 m_proxyModel
->setCategorizedModel(categorized
);
293 emit
categorizedSortingChanged();
296 bool DolphinView::categorizedSorting() const
298 // If all view modes would support categorized sorting, returning
299 // m_proxyModel->isCategorizedModel() would be the way to go. As
300 // currently only the icons view supports caterized sorting, we remember
301 // the stored view properties state in m_storedCategorizedSorting and
302 // return this state. The application takes care to disable the corresponding
303 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
304 // that this setting is not applied to the current view mode.
305 return m_storedCategorizedSorting
;
308 bool DolphinView::supportsCategorizedSorting() const
310 return m_iconsView
!= 0;
313 void DolphinView::selectAll()
315 itemView()->selectAll();
318 void DolphinView::invertSelection()
320 if (isColumnViewActive()) {
321 // QAbstractItemView does not offer a virtual method invertSelection()
322 // as counterpart to QAbstractItemView::selectAll(). This makes it
323 // necessary to delegate the inverting of the selection to the
324 // column view, as only the selection of the active column should
326 m_columnView
->invertSelection();
328 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
329 const QAbstractItemModel
* itemModel
= selectionModel
->model();
331 const QModelIndex topLeft
= itemModel
->index(0, 0);
332 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
333 itemModel
->columnCount() - 1);
335 const QItemSelection
selection(topLeft
, bottomRight
);
336 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
340 bool DolphinView::hasSelection() const
342 return itemView()->selectionModel()->hasSelection();
345 void DolphinView::clearSelection()
347 itemView()->selectionModel()->clear();
350 KFileItemList
DolphinView::selectedItems() const
352 const QAbstractItemView
* view
= itemView();
354 // Our view has a selection, we will map them back to the DolphinModel
355 // and then fill the KFileItemList.
356 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
358 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
359 KFileItemList itemList
;
361 const QModelIndexList indexList
= selection
.indexes();
362 foreach (QModelIndex index
, indexList
) {
363 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
364 if (!item
.isNull()) {
365 itemList
.append(item
);
372 KUrl::List
DolphinView::selectedUrls() const
375 const KFileItemList list
= selectedItems();
376 foreach (KFileItem item
, list
) {
377 urls
.append(item
.url());
382 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
384 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
385 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
388 void DolphinView::setContentsPosition(int x
, int y
)
390 QAbstractItemView
* view
= itemView();
392 // the ColumnView takes care itself for the horizontal scrolling
393 if (!isColumnViewActive()) {
394 view
->horizontalScrollBar()->setValue(x
);
396 view
->verticalScrollBar()->setValue(y
);
398 m_loadingDirectory
= false;
401 QPoint
DolphinView::contentsPosition() const
403 const int x
= itemView()->horizontalScrollBar()->value();
404 const int y
= itemView()->verticalScrollBar()->value();
408 void DolphinView::zoomIn()
410 m_controller
->triggerZoomIn();
413 void DolphinView::zoomOut()
415 m_controller
->triggerZoomOut();
418 bool DolphinView::isZoomInPossible() const
420 return m_controller
->isZoomInPossible();
423 bool DolphinView::isZoomOutPossible() const
425 return m_controller
->isZoomOutPossible();
428 void DolphinView::setSorting(Sorting sorting
)
430 if (sorting
!= this->sorting()) {
431 updateSorting(sorting
);
435 DolphinView::Sorting
DolphinView::sorting() const
437 return m_proxyModel
->sorting();
440 void DolphinView::setSortOrder(Qt::SortOrder order
)
442 if (sortOrder() != order
) {
443 updateSortOrder(order
);
447 Qt::SortOrder
DolphinView::sortOrder() const
449 return m_proxyModel
->sortOrder();
452 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
454 const KUrl viewPropsUrl
= viewPropertiesUrl();
455 ViewProperties
props(viewPropsUrl
);
456 props
.setAdditionalInfo(info
);
457 m_fileItemDelegate
->setShowInformation(info
);
459 emit
additionalInfoChanged(info
);
461 if (itemView() != m_detailsView
) {
462 // the details view requires no reloading of the directory, as it maps
463 // the file item delegate info to its columns internally
464 loadDirectory(viewPropsUrl
, true);
468 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
470 return m_fileItemDelegate
->showInformation();
473 void DolphinView::reload()
476 loadDirectory(url(), true);
479 void DolphinView::refresh()
481 const bool oldActivationState
= m_active
;
485 applyViewProperties(m_controller
->url());
488 setActive(oldActivationState
);
491 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
493 if (m_controller
->url() == url
) {
497 m_controller
->setUrl(url
); // emits urlChanged, which we forward
499 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
500 applyViewProperties(rootUrl
);
501 loadDirectory(rootUrl
);
502 if (itemView() == m_columnView
) {
503 m_columnView
->setRootUrl(rootUrl
);
504 m_columnView
->showColumn(url
);
507 applyViewProperties(url
);
511 emit
startedPathLoading(url
);
514 void DolphinView::setNameFilter(const QString
& nameFilter
)
516 m_proxyModel
->setFilterRegExp(nameFilter
);
518 if (isColumnViewActive()) {
519 // adjusting the directory lister is not enough in the case of the
520 // column view, as each column has its own directory lister internally...
521 m_columnView
->setNameFilter(nameFilter
);
525 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
527 foreach (KFileItem item
, m_dirLister
->items()) {
536 void DolphinView::setUrl(const KUrl
& url
)
538 updateView(url
, KUrl());
541 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
543 QWidget::mouseReleaseEvent(event
);
546 void DolphinView::activate()
551 void DolphinView::triggerItem(const KFileItem
& item
)
553 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
554 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
555 // items are selected by the user, hence don't trigger the
556 // item specified by 'index'
564 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
567 void DolphinView::generatePreviews(const KFileItemList
& items
)
569 if (m_controller
->dolphinView()->showPreview()) {
570 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
571 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
572 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
576 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
578 Q_ASSERT(!item
.isNull());
579 if (item
.url().directory() != m_dirLister
->url().path()) {
580 // the preview job is still working on items of an older URL, hence
581 // the item is not part of the directory model anymore
585 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
586 if (idx
.isValid() && (idx
.column() == 0)) {
587 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
588 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
589 KIconEffect iconEffect
;
590 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
591 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
593 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
598 void DolphinView::emitSelectionChangedSignal()
600 emit
selectionChanged(DolphinView::selectedItems());
603 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
605 if (!url
.isValid()) {
606 const QString
location(url
.pathOrUrl());
607 if (location
.isEmpty()) {
608 emit
errorMessage(i18nc("@info:status", "The location is empty."));
610 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
615 m_cutItemsCache
.clear();
616 m_loadingDirectory
= true;
619 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
621 if (isColumnViewActive()) {
622 // adjusting the directory lister is not enough in the case of the
623 // column view, as each column has its own directory lister internally...
625 m_columnView
->reload();
627 m_columnView
->showColumn(url
);
632 KUrl
DolphinView::viewPropertiesUrl() const
634 if (isColumnViewActive()) {
635 return m_dirLister
->url();
641 void DolphinView::applyViewProperties(const KUrl
& url
)
643 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
644 // The column view is active, hence don't apply the view properties
645 // of sub directories (represented by columns) to the view. The
646 // view always represents the properties of the first column.
650 const ViewProperties
props(url
);
652 const Mode mode
= props
.viewMode();
653 if (m_mode
!= mode
) {
658 if (itemView() == 0) {
661 Q_ASSERT(itemView() != 0);
662 Q_ASSERT(m_fileItemDelegate
!= 0);
664 const bool showHiddenFiles
= props
.showHiddenFiles();
665 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
666 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
667 emit
showHiddenFilesChanged();
670 m_storedCategorizedSorting
= props
.categorizedSorting();
671 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
672 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
673 m_proxyModel
->setCategorizedModel(categorized
);
674 emit
categorizedSortingChanged();
677 const DolphinView::Sorting sorting
= props
.sorting();
678 if (sorting
!= m_proxyModel
->sorting()) {
679 m_proxyModel
->setSorting(sorting
);
680 emit
sortingChanged(sorting
);
683 const Qt::SortOrder sortOrder
= props
.sortOrder();
684 if (sortOrder
!= m_proxyModel
->sortOrder()) {
685 m_proxyModel
->setSortOrder(sortOrder
);
686 emit
sortOrderChanged(sortOrder
);
689 KFileItemDelegate::InformationList info
= props
.additionalInfo();
690 if (info
!= m_fileItemDelegate
->showInformation()) {
691 m_fileItemDelegate
->setShowInformation(info
);
692 emit
additionalInfoChanged(info
);
695 const bool showPreview
= props
.showPreview();
696 if (showPreview
!= m_showPreview
) {
697 m_showPreview
= showPreview
;
698 emit
showPreviewChanged();
702 void DolphinView::changeSelection(const KFileItemList
& selection
)
705 if (selection
.isEmpty()) {
708 const KUrl
& baseUrl
= url();
710 QItemSelection new_selection
;
711 foreach(const KFileItem
& item
, selection
) {
712 url
= item
.url().upUrl();
713 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
714 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
715 new_selection
.select(index
, index
);
718 itemView()->selectionModel()->select(new_selection
,
719 QItemSelectionModel::ClearAndSelect
720 | QItemSelectionModel::Current
);
723 void DolphinView::openContextMenu(const QPoint
& pos
)
727 const QModelIndex index
= itemView()->indexAt(pos
);
728 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
729 item
= fileItem(index
);
732 emit
requestContextMenu(item
, url());
735 void DolphinView::dropUrls(const KUrl::List
& urls
,
736 const KUrl
& destPath
,
737 const KFileItem
& destItem
)
739 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
740 destItem
.url() : destPath
;
741 const KUrl sourceDir
= KUrl(urls
.first().directory());
742 if (sourceDir
!= destination
) {
743 dropUrls(urls
, destination
);
747 void DolphinView::dropUrls(const KUrl::List
& urls
,
748 const KUrl
& destination
)
750 emit
urlsDropped(urls
, destination
);
753 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
755 ViewProperties
props(viewPropertiesUrl());
756 props
.setSorting(sorting
);
758 m_proxyModel
->setSorting(sorting
);
760 emit
sortingChanged(sorting
);
763 void DolphinView::updateSortOrder(Qt::SortOrder order
)
765 ViewProperties
props(viewPropertiesUrl());
766 props
.setSortOrder(order
);
768 m_proxyModel
->setSortOrder(order
);
770 emit
sortOrderChanged(order
);
773 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
775 ViewProperties
props(viewPropertiesUrl());
776 props
.setAdditionalInfo(info
);
779 m_fileItemDelegate
->setShowInformation(info
);
781 emit
additionalInfoChanged(info
);
785 void DolphinView::emitContentsMoved()
787 // only emit the contents moved signal if:
788 // - no directory loading is ongoing (this would reset the contents position
790 // - if the Column View is active: the column view does an automatic
791 // positioning during the loading operation, which must be remembered
792 if (!m_loadingDirectory
|| isColumnViewActive()) {
793 const QPoint
pos(contentsPosition());
794 emit
contentsMoved(pos
.x(), pos
.y());
798 void DolphinView::updateCutItems()
800 // restore the icons of all previously selected items to the
802 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
803 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
805 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
806 if (index
.isValid()) {
807 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
811 m_cutItemsCache
.clear();
813 // ... and apply an item effect to all currently cut items
814 applyCutItemEffect();
817 void DolphinView::showHoverInformation(const KFileItem
& item
)
819 if (hasSelection()) {
823 emit
requestItemInfo(item
);
826 void DolphinView::clearHoverInformation()
828 emit
requestItemInfo(KFileItem());
832 void DolphinView::createView()
835 Q_ASSERT(m_iconsView
== 0);
836 Q_ASSERT(m_detailsView
== 0);
837 Q_ASSERT(m_columnView
== 0);
839 QAbstractItemView
* view
= 0;
842 m_iconsView
= new DolphinIconsView(this, m_controller
);
848 m_detailsView
= new DolphinDetailsView(this, m_controller
);
849 view
= m_detailsView
;
853 m_columnView
= new DolphinColumnView(this, m_controller
);
860 m_fileItemDelegate
= new KFileItemDelegate(view
);
861 view
->setItemDelegate(m_fileItemDelegate
);
863 view
->setModel(m_proxyModel
);
864 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
866 new KMimeTypeResolver(view
, m_dolphinModel
);
867 m_topLayout
->insertWidget(1, view
);
869 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
870 this, SLOT(emitSelectionChangedSignal()));
871 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
872 this, SLOT(emitContentsMoved()));
873 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
874 this, SLOT(emitContentsMoved()));
877 void DolphinView::deleteView()
879 QAbstractItemView
* view
= itemView();
881 m_topLayout
->removeWidget(view
);
888 m_fileItemDelegate
= 0;
892 QAbstractItemView
* DolphinView::itemView() const
894 if (m_detailsView
!= 0) {
895 return m_detailsView
;
896 } else if (m_columnView
!= 0) {
903 bool DolphinView::isCutItem(const KFileItem
& item
) const
905 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
906 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
908 const KUrl
& itemUrl
= item
.url();
909 KUrl::List::const_iterator it
= cutUrls
.begin();
910 const KUrl::List::const_iterator end
= cutUrls
.end();
912 if (*it
== itemUrl
) {
921 void DolphinView::applyCutItemEffect()
923 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
924 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
928 KFileItemList
items(m_dirLister
->items());
929 KFileItemList::const_iterator it
= items
.begin();
930 const KFileItemList::const_iterator end
= items
.end();
932 const KFileItem item
= *it
;
933 if (isCutItem(item
)) {
934 const QModelIndex index
= m_dolphinModel
->indexForItem(item
);
935 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
936 if (value
.type() == QVariant::Icon
) {
937 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
938 QPixmap pixmap
= icon
.pixmap(128, 128);
940 // remember current pixmap for the item to be able
941 // to restore it when other items get cut
943 cutItem
.url
= item
.url();
944 cutItem
.pixmap
= pixmap
;
945 m_cutItemsCache
.append(cutItem
);
947 // apply icon effect to the cut item
948 KIconEffect iconEffect
;
949 pixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
950 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
957 KToggleAction
* DolphinView::iconsModeAction(KActionCollection
* actionCollection
)
959 KToggleAction
* iconsView
= actionCollection
->add
<KToggleAction
>("icons");
960 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
961 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
962 iconsView
->setIcon(KIcon("fileview-icon"));
963 iconsView
->setData(QVariant::fromValue(IconsView
));
967 KToggleAction
* DolphinView::detailsModeAction(KActionCollection
* actionCollection
)
969 KToggleAction
* detailsView
= actionCollection
->add
<KToggleAction
>("details");
970 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
971 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
972 detailsView
->setIcon(KIcon("fileview-detailed"));
973 detailsView
->setData(QVariant::fromValue(DetailsView
));
977 KToggleAction
* DolphinView::columnsModeAction(KActionCollection
* actionCollection
)
979 KToggleAction
* columnView
= actionCollection
->add
<KToggleAction
>("columns");
980 columnView
->setText(i18nc("@action:inmenu View Mode", "Columns"));
981 columnView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
982 columnView
->setIcon(KIcon("fileview-column"));
983 columnView
->setData(QVariant::fromValue(ColumnView
));
987 QString
DolphinView::currentViewModeActionName() const
990 case DolphinView::IconsView
:
992 case DolphinView::DetailsView
:
994 case DolphinView::ColumnView
:
997 return QString(); // can't happen
1000 void DolphinView::renameSelectedItems()
1002 const KFileItemList items
= selectedItems();
1003 if (items
.count() > 1) {
1004 // More than one item has been selected for renaming. Open
1005 // a rename dialog and rename all items afterwards.
1006 RenameDialog
dialog(this, items
);
1007 if (dialog
.exec() == QDialog::Rejected
) {
1011 const QString newName
= dialog
.newName();
1012 if (newName
.isEmpty()) {
1013 emit
errorMessage(dialog
.errorString());
1015 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
1016 // as one operation instead of n rename operations like it is done now...
1017 Q_ASSERT(newName
.contains('#'));
1019 // iterate through all selected items and rename them...
1020 const int replaceIndex
= newName
.indexOf('#');
1021 Q_ASSERT(replaceIndex
>= 0);
1024 KFileItemList::const_iterator it
= items
.begin();
1025 const KFileItemList::const_iterator end
= items
.end();
1027 const KUrl
& oldUrl
= (*it
).url();
1029 number
.setNum(index
++);
1031 QString
name(newName
);
1032 name
.replace(replaceIndex
, 1, number
);
1034 if (oldUrl
.fileName() != name
) {
1035 KUrl newUrl
= oldUrl
;
1036 newUrl
.setFileName(name
);
1037 KonqOperations::rename(this, oldUrl
, newUrl
);
1044 // Only one item has been selected for renaming. Use the custom
1045 // renaming mechanism from the views.
1046 Q_ASSERT(items
.count() == 1);
1048 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
1049 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
1050 // is a benefit for the user at all -> let's wait for some input first...
1051 RenameDialog
dialog(this, items
);
1052 if (dialog
.exec() == QDialog::Rejected
) {
1056 const QString
& newName
= dialog
.newName();
1057 if (newName
.isEmpty()) {
1058 emit
errorMessage(dialog
.errorString());
1060 const KUrl
& oldUrl
= items
.first().url();
1061 KUrl newUrl
= oldUrl
;
1062 newUrl
.setFileName(newName
);
1063 KonqOperations::rename(this, oldUrl
, newUrl
);
1069 #include "dolphinview.moc"