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 <kfilepreviewgenerator.h>
36 #include <kiconeffect.h>
38 #include <kio/deletejob.h>
39 #include <kio/netaccess.h>
40 #include <kio/previewjob.h>
43 #include <kmessagebox.h>
44 #include <kmimetyperesolver.h>
45 #include <konq_fileitemcapabilities.h>
46 #include <konq_operations.h>
47 #include <konqmimedata.h>
48 #include <ktoggleaction.h>
51 #include "dolphindropcontroller.h"
52 #include "dolphinmodel.h"
53 #include "dolphincolumnview.h"
54 #include "dolphincontroller.h"
55 #include "dolphinsortfilterproxymodel.h"
56 #include "dolphindetailsview.h"
57 #include "dolphin_detailsmodesettings.h"
58 #include "dolphiniconsview.h"
59 #include "dolphinsettings.h"
60 #include "dolphin_generalsettings.h"
61 #include "folderexpander.h"
62 #include "renamedialog.h"
63 #include "tooltipmanager.h"
64 #include "viewproperties.h"
65 #include "zoomlevelinfo.h"
67 DolphinView::DolphinView(QWidget
* parent
,
69 KDirLister
* dirLister
,
70 DolphinModel
* dolphinModel
,
71 DolphinSortFilterProxyModel
* proxyModel
) :
75 m_loadingDirectory(false),
76 m_storedCategorizedSorting(false),
77 m_tabsForFiles(false),
78 m_isContextMenuOpen(false),
79 m_mode(DolphinView::IconsView
),
85 m_fileItemDelegate(0),
87 m_dolphinModel(dolphinModel
),
88 m_dirLister(dirLister
),
89 m_proxyModel(proxyModel
),
90 m_previewGenerator(0),
95 m_topLayout
= new QVBoxLayout(this);
96 m_topLayout
->setSpacing(0);
97 m_topLayout
->setMargin(0);
99 m_controller
= new DolphinController(this);
100 m_controller
->setUrl(url
);
102 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
103 this, SIGNAL(urlChanged(const KUrl
&)));
104 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
105 this, SLOT(slotRequestUrlChange(const KUrl
&)));
107 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
108 this, SLOT(openContextMenu(const QPoint
&)));
109 connect(m_controller
, SIGNAL(urlsDropped(const KFileItem
&, const KUrl
&, QDropEvent
*)),
110 this, SLOT(dropUrls(const KFileItem
&, const KUrl
&, QDropEvent
*)));
111 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
112 this, SLOT(updateSorting(DolphinView::Sorting
)));
113 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
114 this, SLOT(updateSortOrder(Qt::SortOrder
)));
115 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
116 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
117 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
118 this, SLOT(triggerItem(const KFileItem
&)));
119 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
120 this, SIGNAL(tabRequested(const KUrl
&)));
121 connect(m_controller
, SIGNAL(activated()),
122 this, SLOT(activate()));
123 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
124 this, SLOT(showHoverInformation(const KFileItem
&)));
125 connect(m_controller
, SIGNAL(viewportEntered()),
126 this, SLOT(clearHoverInformation()));
128 connect(m_dirLister
, SIGNAL(redirection(KUrl
, KUrl
)),
129 this, SLOT(slotRedirection(KUrl
, KUrl
)));
130 connect(m_dirLister
, SIGNAL(completed()),
131 this, SLOT(restoreCurrentItem()));
133 applyViewProperties(url
);
134 m_topLayout
->addWidget(itemView());
137 DolphinView::~DolphinView()
141 const KUrl
& DolphinView::url() const
143 return m_controller
->url();
146 KUrl
DolphinView::rootUrl() const
148 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
151 void DolphinView::setActive(bool active
)
153 if (active
== m_active
) {
159 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
161 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
162 // bypasses the problem when having a split view and changing the active view to
163 // update the some URL dependent states. A nicer approach should be no big deal...
164 emit
urlChanged(url());
165 emit
selectionChanged(selectedItems());
170 QWidget
* viewport
= itemView()->viewport();
172 palette
.setColor(viewport
->backgroundRole(), color
);
173 viewport
->setPalette(palette
);
178 itemView()->setFocus();
182 m_controller
->indicateActivationChange(active
);
185 bool DolphinView::isActive() const
190 void DolphinView::setMode(Mode mode
)
192 if (mode
== m_mode
) {
193 return; // the wished mode is already set
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();
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 bool DolphinView::showPreview() const
231 return m_showPreview
;
234 bool DolphinView::showHiddenFiles() const
236 return m_dirLister
->showingDotFiles();
239 bool DolphinView::categorizedSorting() const
241 // If all view modes would support categorized sorting, returning
242 // m_proxyModel->isCategorizedModel() would be the way to go. As
243 // currently only the icons view supports caterized sorting, we remember
244 // the stored view properties state in m_storedCategorizedSorting and
245 // return this state. The application takes care to disable the corresponding
246 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
247 // that this setting is not applied to the current view mode.
248 return m_storedCategorizedSorting
;
251 bool DolphinView::supportsCategorizedSorting() const
253 return m_iconsView
!= 0;
256 void DolphinView::selectAll()
258 QAbstractItemView
* view
= itemView();
259 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
260 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
261 // selection instead of selecting all items. This is bypassed for KDE 4.0
262 // by invoking clearSelection() first.
263 view
->clearSelection();
267 void DolphinView::invertSelection()
269 if (isColumnViewActive()) {
270 // QAbstractItemView does not offer a virtual method invertSelection()
271 // as counterpart to QAbstractItemView::selectAll(). This makes it
272 // necessary to delegate the inverting of the selection to the
273 // column view, as only the selection of the active column should
275 m_columnView
->invertSelection();
277 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
278 const QAbstractItemModel
* itemModel
= selectionModel
->model();
280 const QModelIndex topLeft
= itemModel
->index(0, 0);
281 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
282 itemModel
->columnCount() - 1);
284 const QItemSelection
selection(topLeft
, bottomRight
);
285 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
289 bool DolphinView::hasSelection() const
291 return itemView()->selectionModel()->hasSelection();
294 void DolphinView::clearSelection()
296 itemView()->selectionModel()->clear();
299 KFileItemList
DolphinView::selectedItems() const
301 if (isColumnViewActive()) {
302 return m_columnView
->selectedItems();
305 const QAbstractItemView
* view
= itemView();
307 // Our view has a selection, we will map them back to the DolphinModel
308 // and then fill the KFileItemList.
309 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
311 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
312 KFileItemList itemList
;
314 const QModelIndexList indexList
= selection
.indexes();
315 foreach (const QModelIndex
&index
, indexList
) {
316 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
317 if (!item
.isNull()) {
318 itemList
.append(item
);
325 KUrl::List
DolphinView::selectedUrls() const
328 const KFileItemList list
= selectedItems();
329 foreach (const KFileItem
&item
, list
) {
330 urls
.append(item
.url());
335 int DolphinView::selectedItemsCount() const
337 if (isColumnViewActive()) {
338 // TODO: get rid of this special case by adjusting the dir lister
339 // to the current column
340 return m_columnView
->selectedItems().count();
343 return itemView()->selectionModel()->selection().count();
346 void DolphinView::setContentsPosition(int x
, int y
)
348 QAbstractItemView
* view
= itemView();
350 // the ColumnView takes care itself for the horizontal scrolling
351 if (!isColumnViewActive()) {
352 view
->horizontalScrollBar()->setValue(x
);
354 view
->verticalScrollBar()->setValue(y
);
356 m_loadingDirectory
= false;
359 QPoint
DolphinView::contentsPosition() const
361 const int x
= itemView()->horizontalScrollBar()->value();
362 const int y
= itemView()->verticalScrollBar()->value();
366 void DolphinView::setZoomLevel(int level
)
368 if (level
< ZoomLevelInfo::minimumLevel()) {
369 level
= ZoomLevelInfo::minimumLevel();
370 } else if (level
> ZoomLevelInfo::maximumLevel()) {
371 level
= ZoomLevelInfo::maximumLevel();
374 if (level
!= zoomLevel()) {
375 m_controller
->setZoomLevel(level
);
376 m_previewGenerator
->updatePreviews();
377 emit
zoomLevelChanged(level
);
381 int DolphinView::zoomLevel() const
383 return m_controller
->zoomLevel();
386 void DolphinView::setSorting(Sorting sorting
)
388 if (sorting
!= this->sorting()) {
389 updateSorting(sorting
);
393 DolphinView::Sorting
DolphinView::sorting() const
395 return m_proxyModel
->sorting();
398 void DolphinView::setSortOrder(Qt::SortOrder order
)
400 if (sortOrder() != order
) {
401 updateSortOrder(order
);
405 Qt::SortOrder
DolphinView::sortOrder() const
407 return m_proxyModel
->sortOrder();
410 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
412 const KUrl viewPropsUrl
= viewPropertiesUrl();
413 ViewProperties
props(viewPropsUrl
);
414 props
.setAdditionalInfo(info
);
415 m_fileItemDelegate
->setShowInformation(info
);
417 emit
additionalInfoChanged();
419 if (itemView() != m_detailsView
) {
420 // the details view requires no reloading of the directory, as it maps
421 // the file item delegate info to its columns internally
422 loadDirectory(viewPropsUrl
);
426 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
428 return m_fileItemDelegate
->showInformation();
431 void DolphinView::reload()
434 loadDirectory(url(), true);
437 void DolphinView::refresh()
439 const bool oldActivationState
= m_active
;
443 applyViewProperties(m_controller
->url());
446 setActive(oldActivationState
);
449 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
451 if (m_controller
->url() == url
) {
455 m_previewGenerator
->cancelPreviews();
456 m_controller
->setUrl(url
); // emits urlChanged, which we forward
458 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
459 applyViewProperties(rootUrl
);
460 loadDirectory(rootUrl
);
461 if (itemView() == m_columnView
) {
462 m_columnView
->setRootUrl(rootUrl
);
463 m_columnView
->showColumn(url
);
466 applyViewProperties(url
);
470 emit
startedPathLoading(url
);
473 void DolphinView::setNameFilter(const QString
& nameFilter
)
475 m_proxyModel
->setFilterRegExp(nameFilter
);
477 if (isColumnViewActive()) {
478 // adjusting the directory lister is not enough in the case of the
479 // column view, as each column has its own directory lister internally...
480 m_columnView
->setNameFilter(nameFilter
);
484 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
486 foreach (const KFileItem
&item
, m_dirLister
->items()) {
495 void DolphinView::setUrl(const KUrl
& url
)
497 // remember current item candidate (see restoreCurrentItem())
498 m_currentItemUrl
= url
;
499 updateView(url
, KUrl());
502 void DolphinView::changeSelection(const KFileItemList
& selection
)
505 if (selection
.isEmpty()) {
508 const KUrl
& baseUrl
= url();
510 QItemSelection new_selection
;
511 foreach(const KFileItem
& item
, selection
) {
512 url
= item
.url().upUrl();
513 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
514 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
515 new_selection
.select(index
, index
);
518 itemView()->selectionModel()->select(new_selection
,
519 QItemSelectionModel::ClearAndSelect
520 | QItemSelectionModel::Current
);
523 void DolphinView::renameSelectedItems()
525 const KFileItemList items
= selectedItems();
526 const int itemCount
= items
.count();
532 // More than one item has been selected for renaming. Open
533 // a rename dialog and rename all items afterwards.
534 RenameDialog
dialog(this, items
);
535 if (dialog
.exec() == QDialog::Rejected
) {
539 const QString newName
= dialog
.newName();
540 if (newName
.isEmpty()) {
541 emit
errorMessage(dialog
.errorString());
543 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
544 // as one operation instead of n rename operations like it is done now...
545 Q_ASSERT(newName
.contains('#'));
547 // iterate through all selected items and rename them...
549 foreach (const KFileItem
&item
, items
) {
550 const KUrl
& oldUrl
= item
.url();
552 number
.setNum(index
++);
554 QString name
= newName
;
555 name
.replace('#', number
);
557 if (oldUrl
.fileName() != name
) {
558 KUrl newUrl
= oldUrl
;
559 newUrl
.setFileName(name
);
560 KonqOperations::rename(this, oldUrl
, newUrl
);
564 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
565 Q_ASSERT(itemCount
== 1);
567 if (isColumnViewActive()) {
568 m_columnView
->editItem(items
.first());
570 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
571 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
572 itemView()->edit(proxyIndex
);
575 Q_ASSERT(itemCount
== 1);
577 RenameDialog
dialog(this, items
);
578 if (dialog
.exec() == QDialog::Rejected
) {
582 const QString
& newName
= dialog
.newName();
583 if (newName
.isEmpty()) {
584 emit
errorMessage(dialog
.errorString());
586 const KUrl
& oldUrl
= items
.first().url();
587 KUrl newUrl
= oldUrl
;
588 newUrl
.setFileName(newName
);
589 KonqOperations::rename(this, oldUrl
, newUrl
);
594 void DolphinView::trashSelectedItems()
596 const KUrl::List list
= simplifiedSelectedUrls();
597 KonqOperations::del(this, KonqOperations::TRASH
, list
);
600 void DolphinView::deleteSelectedItems()
602 const KUrl::List list
= simplifiedSelectedUrls();
603 const bool del
= KonqOperations::askDeleteConfirmation(list
,
605 KonqOperations::DEFAULT_CONFIRMATION
,
609 KIO::Job
* job
= KIO::del(list
);
610 connect(job
, SIGNAL(result(KJob
*)),
611 this, SLOT(slotDeleteFileFinished(KJob
*)));
615 void DolphinView::cutSelectedItems()
617 QMimeData
* mimeData
= new QMimeData();
618 const KUrl::List kdeUrls
= simplifiedSelectedUrls();
619 const KUrl::List mostLocalUrls
;
620 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
621 QApplication::clipboard()->setMimeData(mimeData
);
624 void DolphinView::copySelectedItems()
626 QMimeData
* mimeData
= new QMimeData();
627 const KUrl::List kdeUrls
= selectedUrls();
628 const KUrl::List mostLocalUrls
;
629 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
630 QApplication::clipboard()->setMimeData(mimeData
);
633 void DolphinView::paste()
638 void DolphinView::pasteIntoFolder()
640 const KFileItemList items
= selectedItems();
641 if ((items
.count() == 1) && items
.first().isDir()) {
642 pasteToUrl(items
.first().url());
646 void DolphinView::setShowPreview(bool show
)
648 if (m_showPreview
== show
) {
652 const KUrl viewPropsUrl
= viewPropertiesUrl();
653 ViewProperties
props(viewPropsUrl
);
654 props
.setShowPreview(show
);
656 m_showPreview
= show
;
657 m_previewGenerator
->setPreviewShown(show
);
659 const int oldZoomLevel
= m_controller
->zoomLevel();
660 emit
showPreviewChanged();
662 // Enabling or disabling the preview might change the icon size of the view.
663 // As the view does not emit a signal when the icon size has been changed,
664 // the used zoom level of the controller must be adjusted manually:
665 updateZoomLevel(oldZoomLevel
);
667 loadDirectory(viewPropsUrl
);
670 void DolphinView::setShowHiddenFiles(bool show
)
672 if (m_dirLister
->showingDotFiles() == show
) {
676 const KUrl viewPropsUrl
= viewPropertiesUrl();
677 ViewProperties
props(viewPropsUrl
);
678 props
.setShowHiddenFiles(show
);
680 m_dirLister
->setShowingDotFiles(show
);
681 emit
showHiddenFilesChanged();
683 loadDirectory(viewPropsUrl
);
686 void DolphinView::setCategorizedSorting(bool categorized
)
688 if (categorized
== categorizedSorting()) {
692 // setCategorizedSorting(true) may only get invoked
693 // if the view supports categorized sorting
694 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
696 ViewProperties
props(viewPropertiesUrl());
697 props
.setCategorizedSorting(categorized
);
700 m_storedCategorizedSorting
= categorized
;
701 m_proxyModel
->setCategorizedModel(categorized
);
703 emit
categorizedSortingChanged();
706 void DolphinView::toggleSortOrder()
708 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
709 Qt::DescendingOrder
:
714 void DolphinView::toggleAdditionalInfo(QAction
* action
)
716 const KFileItemDelegate::Information info
=
717 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
719 KFileItemDelegate::InformationList list
= additionalInfo();
721 const bool show
= action
->isChecked();
723 const int index
= list
.indexOf(info
);
724 const bool containsInfo
= (index
>= 0);
725 if (show
&& !containsInfo
) {
727 setAdditionalInfo(list
);
728 } else if (!show
&& containsInfo
) {
729 list
.removeAt(index
);
730 setAdditionalInfo(list
);
731 Q_ASSERT(list
.indexOf(info
) < 0);
735 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
737 QWidget::mouseReleaseEvent(event
);
741 void DolphinView::wheelEvent(QWheelEvent
* event
)
743 if (event
->modifiers() & Qt::ControlModifier
) {
744 const int delta
= event
->delta();
745 const int level
= zoomLevel();
747 setZoomLevel(level
+ 1);
748 } else if (delta
< 0) {
749 setZoomLevel(level
- 1);
755 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
757 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
758 m_controller
->requestActivation();
761 return QWidget::eventFilter(watched
, event
);
764 void DolphinView::activate()
769 void DolphinView::triggerItem(const KFileItem
& item
)
771 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
772 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
773 // items are selected by the user, hence don't trigger the
774 // item specified by 'index'
778 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
779 if (item
.isNull() || m_isContextMenuOpen
) {
783 if (m_toolTipManager
!= 0) {
784 m_toolTipManager
->hideTip();
786 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
789 void DolphinView::emitSelectionChangedSignal()
791 emit
selectionChanged(DolphinView::selectedItems());
794 void DolphinView::openContextMenu(const QPoint
& pos
)
797 if (isColumnViewActive()) {
798 item
= m_columnView
->itemAt(pos
);
800 const QModelIndex index
= itemView()->indexAt(pos
);
801 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
802 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
803 item
= m_dolphinModel
->itemForIndex(dolphinModelIndex
);
807 if (m_toolTipManager
!= 0) {
808 m_toolTipManager
->hideTip();
811 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
812 emit
requestContextMenu(item
, url());
813 m_isContextMenuOpen
= false;
816 void DolphinView::dropUrls(const KFileItem
& destItem
,
817 const KUrl
& destPath
,
820 DolphinDropController::dropUrls(destItem
, destPath
, event
, this);
823 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
825 ViewProperties
props(viewPropertiesUrl());
826 props
.setSorting(sorting
);
828 m_proxyModel
->setSorting(sorting
);
830 emit
sortingChanged(sorting
);
833 void DolphinView::updateSortOrder(Qt::SortOrder order
)
835 ViewProperties
props(viewPropertiesUrl());
836 props
.setSortOrder(order
);
838 m_proxyModel
->setSortOrder(order
);
840 emit
sortOrderChanged(order
);
843 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
845 ViewProperties
props(viewPropertiesUrl());
846 props
.setAdditionalInfo(info
);
849 m_fileItemDelegate
->setShowInformation(info
);
851 emit
additionalInfoChanged();
854 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
856 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
857 (m_mode
== DolphinView::IconsView
);
859 QAction
* showSizeInfo
= collection
->action("show_size_info");
860 QAction
* showDateInfo
= collection
->action("show_date_info");
861 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
862 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
863 QAction
* showGroupInfo
= collection
->action("show_group_info");
864 QAction
* showMimeInfo
= collection
->action("show_mime_info");
866 showSizeInfo
->setChecked(false);
867 showDateInfo
->setChecked(false);
868 showPermissionsInfo
->setChecked(false);
869 showOwnerInfo
->setChecked(false);
870 showGroupInfo
->setChecked(false);
871 showMimeInfo
->setChecked(false);
873 showSizeInfo
->setEnabled(enable
);
874 showDateInfo
->setEnabled(enable
);
875 showPermissionsInfo
->setEnabled(enable
);
876 showOwnerInfo
->setEnabled(enable
);
877 showGroupInfo
->setEnabled(enable
);
878 showMimeInfo
->setEnabled(enable
);
880 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
882 case KFileItemDelegate::Size
:
883 showSizeInfo
->setChecked(true);
885 case KFileItemDelegate::ModificationTime
:
886 showDateInfo
->setChecked(true);
888 case KFileItemDelegate::Permissions
:
889 showPermissionsInfo
->setChecked(true);
891 case KFileItemDelegate::Owner
:
892 showOwnerInfo
->setChecked(true);
894 case KFileItemDelegate::OwnerAndGroup
:
895 showGroupInfo
->setChecked(true);
897 case KFileItemDelegate::FriendlyMimeType
:
898 showMimeInfo
->setChecked(true);
906 QPair
<bool, QString
> DolphinView::pasteInfo() const
908 QPair
<bool, QString
> ret
;
909 QClipboard
* clipboard
= QApplication::clipboard();
910 const QMimeData
* mimeData
= clipboard
->mimeData();
912 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
913 if (!urls
.isEmpty()) {
914 // disable the paste action if no writing is supported
915 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url());
916 ret
.first
= KonqFileItemCapabilities(KFileItemList() << item
).supportsWriting();
918 if (urls
.count() == 1) {
919 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
920 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
921 i18nc("@action:inmenu", "Paste One File");
924 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
928 ret
.second
= i18nc("@action:inmenu", "Paste");
934 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
936 m_tabsForFiles
= tabsForFiles
;
939 bool DolphinView::isTabsForFilesEnabled() const
941 return m_tabsForFiles
;
944 void DolphinView::emitContentsMoved()
946 // only emit the contents moved signal if:
947 // - no directory loading is ongoing (this would reset the contents position
949 // - if the Column View is active: the column view does an automatic
950 // positioning during the loading operation, which must be remembered
951 if (!m_loadingDirectory
|| isColumnViewActive()) {
952 const QPoint
pos(contentsPosition());
953 emit
contentsMoved(pos
.x(), pos
.y());
957 void DolphinView::showHoverInformation(const KFileItem
& item
)
959 emit
requestItemInfo(item
);
962 void DolphinView::clearHoverInformation()
964 emit
requestItemInfo(KFileItem());
967 void DolphinView::slotDeleteFileFinished(KJob
* job
)
969 if (job
->error() == 0) {
970 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
972 emit
errorMessage(job
->errorString());
976 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
978 if (oldUrl
== m_controller
->url()) {
979 m_controller
->setUrl(newUrl
);
983 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
985 emit
requestUrlChange(url
);
986 m_controller
->setUrl(url
);
989 void DolphinView::restoreCurrentItem()
991 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
992 if (dirIndex
.isValid()) {
993 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
994 QAbstractItemView
* view
= itemView();
995 const bool clearSelection
= !hasSelection();
996 view
->setCurrentIndex(proxyIndex
);
997 if (clearSelection
) {
998 view
->clearSelection();
1003 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1005 if (!url
.isValid()) {
1006 const QString
location(url
.pathOrUrl());
1007 if (location
.isEmpty()) {
1008 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1010 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1015 m_loadingDirectory
= true;
1017 m_dirLister
->stop();
1018 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1020 if (isColumnViewActive()) {
1021 // adjusting the directory lister is not enough in the case of the
1022 // column view, as each column has its own directory lister internally...
1024 m_columnView
->reload();
1026 m_columnView
->showColumn(url
);
1031 KUrl
DolphinView::viewPropertiesUrl() const
1033 if (isColumnViewActive()) {
1034 return m_columnView
->rootUrl();
1040 void DolphinView::applyViewProperties(const KUrl
& url
)
1042 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1043 // The column view is active, hence don't apply the view properties
1044 // of sub directories (represented by columns) to the view. The
1045 // view always represents the properties of the first column.
1049 const ViewProperties
props(url
);
1051 const Mode mode
= props
.viewMode();
1052 if (m_mode
!= mode
) {
1057 if (itemView() == 0) {
1060 Q_ASSERT(itemView() != 0);
1061 Q_ASSERT(m_fileItemDelegate
!= 0);
1063 const bool showHiddenFiles
= props
.showHiddenFiles();
1064 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1065 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1066 emit
showHiddenFilesChanged();
1069 m_storedCategorizedSorting
= props
.categorizedSorting();
1070 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1071 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1072 m_proxyModel
->setCategorizedModel(categorized
);
1073 emit
categorizedSortingChanged();
1076 const DolphinView::Sorting sorting
= props
.sorting();
1077 if (sorting
!= m_proxyModel
->sorting()) {
1078 m_proxyModel
->setSorting(sorting
);
1079 emit
sortingChanged(sorting
);
1082 const Qt::SortOrder sortOrder
= props
.sortOrder();
1083 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1084 m_proxyModel
->setSortOrder(sortOrder
);
1085 emit
sortOrderChanged(sortOrder
);
1088 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1089 if (info
!= m_fileItemDelegate
->showInformation()) {
1090 m_fileItemDelegate
->setShowInformation(info
);
1091 emit
additionalInfoChanged();
1094 const bool showPreview
= props
.showPreview();
1095 if (showPreview
!= m_showPreview
) {
1096 m_showPreview
= showPreview
;
1097 m_previewGenerator
->setPreviewShown(showPreview
);
1099 const int oldZoomLevel
= m_controller
->zoomLevel();
1100 emit
showPreviewChanged();
1102 // Enabling or disabling the preview might change the icon size of the view.
1103 // As the view does not emit a signal when the icon size has been changed,
1104 // the used zoom level of the controller must be adjusted manually:
1105 updateZoomLevel(oldZoomLevel
);
1109 void DolphinView::createView()
1112 Q_ASSERT(m_iconsView
== 0);
1113 Q_ASSERT(m_detailsView
== 0);
1114 Q_ASSERT(m_columnView
== 0);
1116 QAbstractItemView
* view
= 0;
1119 m_iconsView
= new DolphinIconsView(this, m_controller
);
1125 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1126 view
= m_detailsView
;
1130 m_columnView
= new DolphinColumnView(this, m_controller
);
1131 view
= m_columnView
;
1135 Q_ASSERT(view
!= 0);
1136 view
->installEventFilter(this);
1138 if (m_mode
!= ColumnView
) {
1139 // Give the view the ability to auto-expand its directories on hovering
1140 // (the column view takes care about this itself). If the details view
1141 // uses expandable folders, the auto-expanding should be used always.
1142 DolphinSettings
& settings
= DolphinSettings::instance();
1143 const bool enabled
= settings
.generalSettings()->autoExpandFolders() ||
1144 ((m_detailsView
!= 0) && settings
.detailsModeSettings()->expandableFolders());
1146 FolderExpander
* folderExpander
= new FolderExpander(view
, m_proxyModel
);
1147 folderExpander
->setEnabled(enabled
);
1148 connect(folderExpander
, SIGNAL(enterDir(const QModelIndex
&)),
1149 m_controller
, SLOT(triggerItem(const QModelIndex
&)));
1152 m_controller
->setItemView(view
);
1154 m_fileItemDelegate
= new KFileItemDelegate(view
);
1155 m_fileItemDelegate
->setShowToolTipWhenElided(false);
1156 view
->setItemDelegate(m_fileItemDelegate
);
1158 view
->setModel(m_proxyModel
);
1159 if (m_selectionModel
!= 0) {
1160 view
->setSelectionModel(m_selectionModel
);
1162 m_selectionModel
= view
->selectionModel();
1165 // reparent the selection model, as it should not be deleted
1166 // when deleting the model
1167 m_selectionModel
->setParent(this);
1169 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1171 m_previewGenerator
= new KFilePreviewGenerator(view
, m_proxyModel
);
1172 m_previewGenerator
->setPreviewShown(m_showPreview
);
1174 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1175 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1178 m_topLayout
->insertWidget(1, view
);
1180 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1181 this, SLOT(emitSelectionChangedSignal()));
1182 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1183 this, SLOT(emitContentsMoved()));
1184 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1185 this, SLOT(emitContentsMoved()));
1188 void DolphinView::deleteView()
1190 QAbstractItemView
* view
= itemView();
1192 // It's important to set the keyboard focus to the parent
1193 // before deleting the view: Otherwise when having a split
1194 // view the other view will get the focus and will request
1195 // an activation (see DolphinView::eventFilter()).
1198 m_topLayout
->removeWidget(view
);
1200 view
->deleteLater();
1205 m_fileItemDelegate
= 0;
1206 m_previewGenerator
= 0;
1207 m_toolTipManager
= 0;
1211 QAbstractItemView
* DolphinView::itemView() const
1213 if (m_detailsView
!= 0) {
1214 return m_detailsView
;
1215 } else if (m_columnView
!= 0) {
1216 return m_columnView
;
1222 bool DolphinView::isCutItem(const KFileItem
& item
) const
1224 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1225 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1227 const KUrl
& itemUrl
= item
.url();
1228 KUrl::List::const_iterator it
= cutUrls
.begin();
1229 const KUrl::List::const_iterator end
= cutUrls
.end();
1231 if (*it
== itemUrl
) {
1240 void DolphinView::pasteToUrl(const KUrl
& url
)
1242 QClipboard
* clipboard
= QApplication::clipboard();
1243 const QMimeData
* mimeData
= clipboard
->mimeData();
1245 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1246 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1247 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1250 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1254 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1256 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(itemView()->iconSize());
1257 if (oldZoomLevel
!= newZoomLevel
) {
1258 m_controller
->setZoomLevel(newZoomLevel
);
1259 emit
zoomLevelChanged(newZoomLevel
);
1263 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1265 KUrl::List list
= selectedUrls();
1266 if ((m_detailsView
!= 0) && m_detailsView
->itemsExpandable()) {
1267 list
= KonqOperations::simplifiedUrlList(list
);
1272 #include "dolphinview.moc"