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 <kfilepreviewgenerator.h>
35 #include <kiconeffect.h>
37 #include <kio/deletejob.h>
38 #include <kio/netaccess.h>
39 #include <kio/previewjob.h>
42 #include <kmessagebox.h>
43 #include <kmimetyperesolver.h>
44 #include <konq_fileitemcapabilities.h>
45 #include <konq_operations.h>
46 #include <konqmimedata.h>
47 #include <ktoggleaction.h>
50 #include "dolphinmodel.h"
51 #include "dolphincolumnview.h"
52 #include "dolphincontroller.h"
53 #include "dolphinfileitemdelegate.h"
54 #include "dolphinsortfilterproxymodel.h"
55 #include "dolphindetailsview.h"
56 #include "dolphin_detailsmodesettings.h"
57 #include "dolphiniconsview.h"
58 #include "dolphinsettings.h"
59 #include "dolphin_generalsettings.h"
60 #include "draganddrophelper.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),
96 m_topLayout
= new QVBoxLayout(this);
97 m_topLayout
->setSpacing(0);
98 m_topLayout
->setMargin(0);
100 m_controller
= new DolphinController(this);
101 m_controller
->setUrl(url
);
103 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
104 this, SIGNAL(urlChanged(const KUrl
&)));
105 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
106 this, SLOT(slotRequestUrlChange(const KUrl
&)));
108 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
109 this, SLOT(openContextMenu(const QPoint
&)));
110 connect(m_controller
, SIGNAL(urlsDropped(const KFileItem
&, const KUrl
&, QDropEvent
*)),
111 this, SLOT(dropUrls(const KFileItem
&, const KUrl
&, QDropEvent
*)));
112 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
113 this, SLOT(updateSorting(DolphinView::Sorting
)));
114 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
115 this, SLOT(updateSortOrder(Qt::SortOrder
)));
116 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
117 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
118 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
119 this, SLOT(triggerItem(const KFileItem
&)));
120 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
121 this, SIGNAL(tabRequested(const KUrl
&)));
122 connect(m_controller
, SIGNAL(activated()),
123 this, SLOT(activate()));
124 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
125 this, SLOT(showHoverInformation(const KFileItem
&)));
126 connect(m_controller
, SIGNAL(viewportEntered()),
127 this, SLOT(clearHoverInformation()));
129 connect(m_dirLister
, SIGNAL(redirection(KUrl
, KUrl
)),
130 this, SIGNAL(redirection(KUrl
, KUrl
)));
131 connect(m_dirLister
, SIGNAL(completed()),
132 this, SLOT(restoreCurrentItem()));
134 applyViewProperties(url
);
135 m_topLayout
->addWidget(itemView());
138 DolphinView::~DolphinView()
140 deleteExpandedViews();
143 const KUrl
& DolphinView::url() const
145 return m_controller
->url();
148 KUrl
DolphinView::rootUrl() const
150 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
153 void DolphinView::setActive(bool active
)
155 if (active
== m_active
) {
161 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
163 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
164 // bypasses the problem when having a split view and changing the active view to
165 // update the some URL dependent states. A nicer approach should be no big deal...
166 emit
urlChanged(url());
167 emit
selectionChanged(selectedItems());
172 QWidget
* viewport
= itemView()->viewport();
174 palette
.setColor(viewport
->backgroundRole(), color
);
175 viewport
->setPalette(palette
);
180 itemView()->setFocus();
184 m_controller
->indicateActivationChange(active
);
187 bool DolphinView::isActive() const
192 void DolphinView::setMode(Mode mode
)
194 if (mode
== m_mode
) {
195 return; // the wished mode is already set
198 const int oldZoomLevel
= m_controller
->zoomLevel();
203 const KUrl viewPropsUrl
= viewPropertiesUrl();
204 ViewProperties
props(viewPropsUrl
);
205 props
.setViewMode(m_mode
);
208 // the file item delegate has been recreated, apply the current
209 // additional information manually
210 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
211 m_fileItemDelegate
->setShowInformation(infoList
);
212 emit
additionalInfoChanged();
214 // Not all view modes support categorized sorting. Adjust the sorting model
215 // if changing the view mode results in a change of the categorized sorting
217 m_storedCategorizedSorting
= props
.categorizedSorting();
218 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
219 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
220 m_proxyModel
->setCategorizedModel(categorized
);
221 emit
categorizedSortingChanged();
226 updateZoomLevel(oldZoomLevel
);
228 loadDirectory(viewPropsUrl
);
232 DolphinView::Mode
DolphinView::mode() const
237 bool DolphinView::showPreview() const
239 return m_showPreview
;
242 bool DolphinView::showHiddenFiles() const
244 return m_dirLister
->showingDotFiles();
247 bool DolphinView::categorizedSorting() const
249 // If all view modes would support categorized sorting, returning
250 // m_proxyModel->isCategorizedModel() would be the way to go. As
251 // currently only the icons view supports caterized sorting, we remember
252 // the stored view properties state in m_storedCategorizedSorting and
253 // return this state. The application takes care to disable the corresponding
254 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
255 // that this setting is not applied to the current view mode.
256 return m_storedCategorizedSorting
;
259 bool DolphinView::supportsCategorizedSorting() const
261 return m_iconsView
!= 0;
264 void DolphinView::selectAll()
266 QAbstractItemView
* view
= itemView();
267 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
268 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
269 // selection instead of selecting all items. This is bypassed for KDE 4.0
270 // by invoking clearSelection() first.
271 view
->clearSelection();
275 void DolphinView::invertSelection()
277 if (isColumnViewActive()) {
278 // QAbstractItemView does not offer a virtual method invertSelection()
279 // as counterpart to QAbstractItemView::selectAll(). This makes it
280 // necessary to delegate the inverting of the selection to the
281 // column view, as only the selection of the active column should
283 m_columnView
->invertSelection();
285 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
286 const QAbstractItemModel
* itemModel
= selectionModel
->model();
288 const QModelIndex topLeft
= itemModel
->index(0, 0);
289 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
290 itemModel
->columnCount() - 1);
292 const QItemSelection
selection(topLeft
, bottomRight
);
293 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
297 bool DolphinView::hasSelection() const
299 return itemView()->selectionModel()->hasSelection();
302 void DolphinView::clearSelection()
304 itemView()->selectionModel()->clear();
307 KFileItemList
DolphinView::selectedItems() const
309 if (isColumnViewActive()) {
310 return m_columnView
->selectedItems();
313 const QAbstractItemView
* view
= itemView();
315 // Our view has a selection, we will map them back to the DolphinModel
316 // and then fill the KFileItemList.
317 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
319 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
320 KFileItemList itemList
;
322 const QModelIndexList indexList
= selection
.indexes();
323 foreach (const QModelIndex
&index
, indexList
) {
324 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
325 if (!item
.isNull()) {
326 itemList
.append(item
);
333 KUrl::List
DolphinView::selectedUrls() const
336 const KFileItemList list
= selectedItems();
337 foreach (const KFileItem
&item
, list
) {
338 urls
.append(item
.url());
343 int DolphinView::selectedItemsCount() const
345 if (isColumnViewActive()) {
346 // TODO: get rid of this special case by adjusting the dir lister
347 // to the current column
348 return m_columnView
->selectedItems().count();
351 return itemView()->selectionModel()->selection().count();
354 void DolphinView::setContentsPosition(int x
, int y
)
356 QAbstractItemView
* view
= itemView();
358 // the ColumnView takes care itself for the horizontal scrolling
359 if (!isColumnViewActive()) {
360 view
->horizontalScrollBar()->setValue(x
);
362 view
->verticalScrollBar()->setValue(y
);
364 m_loadingDirectory
= false;
367 QPoint
DolphinView::contentsPosition() const
369 const int x
= itemView()->horizontalScrollBar()->value();
370 const int y
= itemView()->verticalScrollBar()->value();
374 void DolphinView::setZoomLevel(int level
)
376 if (level
< ZoomLevelInfo::minimumLevel()) {
377 level
= ZoomLevelInfo::minimumLevel();
378 } else if (level
> ZoomLevelInfo::maximumLevel()) {
379 level
= ZoomLevelInfo::maximumLevel();
382 if (level
!= zoomLevel()) {
383 m_controller
->setZoomLevel(level
);
384 m_previewGenerator
->updatePreviews();
385 emit
zoomLevelChanged(level
);
389 int DolphinView::zoomLevel() const
391 return m_controller
->zoomLevel();
394 void DolphinView::setSorting(Sorting sorting
)
396 if (sorting
!= this->sorting()) {
397 updateSorting(sorting
);
401 DolphinView::Sorting
DolphinView::sorting() const
403 return m_proxyModel
->sorting();
406 void DolphinView::setSortOrder(Qt::SortOrder order
)
408 if (sortOrder() != order
) {
409 updateSortOrder(order
);
413 Qt::SortOrder
DolphinView::sortOrder() const
415 return m_proxyModel
->sortOrder();
418 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
420 const KUrl viewPropsUrl
= viewPropertiesUrl();
421 ViewProperties
props(viewPropsUrl
);
422 props
.setAdditionalInfo(info
);
423 m_fileItemDelegate
->setShowInformation(info
);
425 emit
additionalInfoChanged();
427 if (itemView() != m_detailsView
) {
428 // the details view requires no reloading of the directory, as it maps
429 // the file item delegate info to its columns internally
430 loadDirectory(viewPropsUrl
);
434 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
436 return m_fileItemDelegate
->showInformation();
439 void DolphinView::reload()
442 loadDirectory(url(), true);
445 void DolphinView::refresh()
447 const bool oldActivationState
= m_active
;
448 const int oldZoomLevel
= m_controller
->zoomLevel();
452 applyViewProperties(m_controller
->url());
455 setActive(oldActivationState
);
456 updateZoomLevel(oldZoomLevel
);
459 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
461 if (m_controller
->url() == url
) {
465 m_previewGenerator
->cancelPreviews();
466 m_controller
->setUrl(url
); // emits urlChanged, which we forward
468 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
469 applyViewProperties(rootUrl
);
470 loadDirectory(rootUrl
);
471 if (itemView() == m_columnView
) {
472 m_columnView
->setRootUrl(rootUrl
);
473 m_columnView
->showColumn(url
);
476 applyViewProperties(url
);
480 emit
startedPathLoading(url
);
483 void DolphinView::setNameFilter(const QString
& nameFilter
)
485 m_proxyModel
->setFilterRegExp(nameFilter
);
487 if (isColumnViewActive()) {
488 // adjusting the directory lister is not enough in the case of the
489 // column view, as each column has its own directory lister internally...
490 m_columnView
->setNameFilter(nameFilter
);
494 void DolphinView::calculateItemCount(int& fileCount
,
496 KIO::filesize_t
& totalFileSize
) const
498 foreach (const KFileItem
& item
, m_dirLister
->items()) {
503 totalFileSize
+= item
.size();
508 QString
DolphinView::statusBarText() const
513 KIO::filesize_t totalFileSize
= 0;
515 if (hasSelection()) {
516 // give a summary of the status of the selected files
517 const KFileItemList list
= selectedItems();
518 if (list
.isEmpty()) {
519 // when an item is triggered, it is temporary selected but selectedItems()
520 // will return an empty list
524 KFileItemList::const_iterator it
= list
.begin();
525 const KFileItemList::const_iterator end
= list
.end();
527 const KFileItem
& item
= *it
;
532 totalFileSize
+= item
.size();
537 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
538 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
539 if ((folderCount
> 0) && (fileCount
> 0)) {
540 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
541 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
542 } else if (fileCount
> 0) {
543 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
545 Q_ASSERT(folderCount
> 0);
549 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
550 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
551 fileCount
, folderCount
,
552 totalFileSize
, true);
558 void DolphinView::setUrl(const KUrl
& url
)
560 // remember current item candidate (see restoreCurrentItem())
561 m_currentItemUrl
= url
;
562 updateView(url
, KUrl());
565 void DolphinView::changeSelection(const KFileItemList
& selection
)
568 if (selection
.isEmpty()) {
571 const KUrl
& baseUrl
= url();
573 QItemSelection new_selection
;
574 foreach(const KFileItem
& item
, selection
) {
575 url
= item
.url().upUrl();
576 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
577 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
578 new_selection
.select(index
, index
);
581 itemView()->selectionModel()->select(new_selection
,
582 QItemSelectionModel::ClearAndSelect
583 | QItemSelectionModel::Current
);
586 void DolphinView::renameSelectedItems()
588 const KFileItemList items
= selectedItems();
589 const int itemCount
= items
.count();
595 // More than one item has been selected for renaming. Open
596 // a rename dialog and rename all items afterwards.
597 RenameDialog
dialog(this, items
);
598 if (dialog
.exec() == QDialog::Rejected
) {
602 const QString newName
= dialog
.newName();
603 if (newName
.isEmpty()) {
604 emit
errorMessage(dialog
.errorString());
606 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
607 // as one operation instead of n rename operations like it is done now...
608 Q_ASSERT(newName
.contains('#'));
610 // iterate through all selected items and rename them...
612 foreach (const KFileItem
&item
, items
) {
613 const KUrl
& oldUrl
= item
.url();
615 number
.setNum(index
++);
617 QString name
= newName
;
618 name
.replace('#', number
);
620 if (oldUrl
.fileName() != name
) {
621 KUrl newUrl
= oldUrl
;
622 newUrl
.setFileName(name
);
623 KonqOperations::rename(this, oldUrl
, newUrl
);
627 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
628 Q_ASSERT(itemCount
== 1);
630 if (isColumnViewActive()) {
631 m_columnView
->editItem(items
.first());
633 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
634 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
635 itemView()->edit(proxyIndex
);
638 Q_ASSERT(itemCount
== 1);
640 RenameDialog
dialog(this, items
);
641 if (dialog
.exec() == QDialog::Rejected
) {
645 const QString
& newName
= dialog
.newName();
646 if (newName
.isEmpty()) {
647 emit
errorMessage(dialog
.errorString());
649 const KUrl
& oldUrl
= items
.first().url();
650 KUrl newUrl
= oldUrl
;
651 newUrl
.setFileName(newName
);
652 KonqOperations::rename(this, oldUrl
, newUrl
);
657 void DolphinView::trashSelectedItems()
659 const KUrl::List list
= simplifiedSelectedUrls();
660 KonqOperations::del(this, KonqOperations::TRASH
, list
);
663 void DolphinView::deleteSelectedItems()
665 const KUrl::List list
= simplifiedSelectedUrls();
666 const bool del
= KonqOperations::askDeleteConfirmation(list
,
668 KonqOperations::DEFAULT_CONFIRMATION
,
672 KIO::Job
* job
= KIO::del(list
);
673 connect(job
, SIGNAL(result(KJob
*)),
674 this, SLOT(slotDeleteFileFinished(KJob
*)));
678 void DolphinView::cutSelectedItems()
680 QMimeData
* mimeData
= new QMimeData();
681 const KUrl::List kdeUrls
= simplifiedSelectedUrls();
682 const KUrl::List mostLocalUrls
;
683 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
684 QApplication::clipboard()->setMimeData(mimeData
);
687 void DolphinView::copySelectedItems()
689 QMimeData
* mimeData
= new QMimeData();
690 const KUrl::List kdeUrls
= selectedUrls();
691 const KUrl::List mostLocalUrls
;
692 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
693 QApplication::clipboard()->setMimeData(mimeData
);
696 void DolphinView::paste()
701 void DolphinView::pasteIntoFolder()
703 const KFileItemList items
= selectedItems();
704 if ((items
.count() == 1) && items
.first().isDir()) {
705 pasteToUrl(items
.first().url());
709 void DolphinView::setShowPreview(bool show
)
711 if (m_showPreview
== show
) {
715 const KUrl viewPropsUrl
= viewPropertiesUrl();
716 ViewProperties
props(viewPropsUrl
);
717 props
.setShowPreview(show
);
719 m_showPreview
= show
;
720 m_previewGenerator
->setPreviewShown(show
);
722 const int oldZoomLevel
= m_controller
->zoomLevel();
723 emit
showPreviewChanged();
725 // Enabling or disabling the preview might change the icon size of the view.
726 // As the view does not emit a signal when the icon size has been changed,
727 // the used zoom level of the controller must be adjusted manually:
728 updateZoomLevel(oldZoomLevel
);
730 loadDirectory(viewPropsUrl
);
733 void DolphinView::setShowHiddenFiles(bool show
)
735 if (m_dirLister
->showingDotFiles() == show
) {
739 const KUrl viewPropsUrl
= viewPropertiesUrl();
740 ViewProperties
props(viewPropsUrl
);
741 props
.setShowHiddenFiles(show
);
743 m_dirLister
->setShowingDotFiles(show
);
744 emit
showHiddenFilesChanged();
746 loadDirectory(viewPropsUrl
);
749 void DolphinView::setCategorizedSorting(bool categorized
)
751 if (categorized
== categorizedSorting()) {
755 // setCategorizedSorting(true) may only get invoked
756 // if the view supports categorized sorting
757 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
759 ViewProperties
props(viewPropertiesUrl());
760 props
.setCategorizedSorting(categorized
);
763 m_storedCategorizedSorting
= categorized
;
764 m_proxyModel
->setCategorizedModel(categorized
);
766 emit
categorizedSortingChanged();
769 void DolphinView::toggleSortOrder()
771 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
772 Qt::DescendingOrder
:
777 void DolphinView::toggleAdditionalInfo(QAction
* action
)
779 const KFileItemDelegate::Information info
=
780 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
782 KFileItemDelegate::InformationList list
= additionalInfo();
784 const bool show
= action
->isChecked();
786 const int index
= list
.indexOf(info
);
787 const bool containsInfo
= (index
>= 0);
788 if (show
&& !containsInfo
) {
790 setAdditionalInfo(list
);
791 } else if (!show
&& containsInfo
) {
792 list
.removeAt(index
);
793 setAdditionalInfo(list
);
794 Q_ASSERT(list
.indexOf(info
) < 0);
798 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
800 QWidget::mouseReleaseEvent(event
);
804 void DolphinView::wheelEvent(QWheelEvent
* event
)
806 if (event
->modifiers() & Qt::ControlModifier
) {
807 const int delta
= event
->delta();
808 const int level
= zoomLevel();
810 setZoomLevel(level
+ 1);
811 } else if (delta
< 0) {
812 setZoomLevel(level
- 1);
818 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
820 switch (event
->type()) {
821 case QEvent::FocusIn
:
822 if (watched
== itemView()) {
823 m_controller
->requestActivation();
827 case QEvent::MouseButtonPress
:
828 if ((watched
== itemView()->viewport()) && (m_expandedViews
.count() > 0)) {
829 // Listening to a mousebutton press event to delete expanded views is a
830 // workaround, as it seems impossible for the FolderExpander to know when
831 // a dragging outside a view has been finished. However it works quite well:
832 // A mousebutton press event indicates that a drag operation must be
834 deleteExpandedViews();
838 case QEvent::DragEnter
:
839 if (watched
== itemView()->viewport()) {
848 return QWidget::eventFilter(watched
, event
);
851 void DolphinView::activate()
856 void DolphinView::triggerItem(const KFileItem
& item
)
858 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
859 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
860 // items are selected by the user, hence don't trigger the
861 // item specified by 'index'
865 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
866 if (item
.isNull() || m_isContextMenuOpen
) {
870 if (m_toolTipManager
!= 0) {
871 m_toolTipManager
->hideTip();
873 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
876 void DolphinView::emitSelectionChangedSignal()
878 emit
selectionChanged(DolphinView::selectedItems());
881 void DolphinView::openContextMenu(const QPoint
& pos
)
884 if (isColumnViewActive()) {
885 item
= m_columnView
->itemAt(pos
);
887 const QModelIndex index
= itemView()->indexAt(pos
);
888 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
889 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
890 item
= m_dolphinModel
->itemForIndex(dolphinModelIndex
);
894 if (m_toolTipManager
!= 0) {
895 m_toolTipManager
->hideTip();
898 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
899 emit
requestContextMenu(item
, url());
900 m_isContextMenuOpen
= false;
903 void DolphinView::dropUrls(const KFileItem
& destItem
,
904 const KUrl
& destPath
,
907 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
910 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
912 ViewProperties
props(viewPropertiesUrl());
913 props
.setSorting(sorting
);
915 m_proxyModel
->setSorting(sorting
);
917 emit
sortingChanged(sorting
);
920 void DolphinView::updateSortOrder(Qt::SortOrder order
)
922 ViewProperties
props(viewPropertiesUrl());
923 props
.setSortOrder(order
);
925 m_proxyModel
->setSortOrder(order
);
927 emit
sortOrderChanged(order
);
930 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
932 ViewProperties
props(viewPropertiesUrl());
933 props
.setAdditionalInfo(info
);
936 m_fileItemDelegate
->setShowInformation(info
);
938 emit
additionalInfoChanged();
941 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
943 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
944 (m_mode
== DolphinView::IconsView
);
946 QAction
* showSizeInfo
= collection
->action("show_size_info");
947 QAction
* showDateInfo
= collection
->action("show_date_info");
948 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
949 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
950 QAction
* showGroupInfo
= collection
->action("show_group_info");
951 QAction
* showMimeInfo
= collection
->action("show_mime_info");
953 showSizeInfo
->setChecked(false);
954 showDateInfo
->setChecked(false);
955 showPermissionsInfo
->setChecked(false);
956 showOwnerInfo
->setChecked(false);
957 showGroupInfo
->setChecked(false);
958 showMimeInfo
->setChecked(false);
960 showSizeInfo
->setEnabled(enable
);
961 showDateInfo
->setEnabled(enable
);
962 showPermissionsInfo
->setEnabled(enable
);
963 showOwnerInfo
->setEnabled(enable
);
964 showGroupInfo
->setEnabled(enable
);
965 showMimeInfo
->setEnabled(enable
);
967 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
969 case KFileItemDelegate::Size
:
970 showSizeInfo
->setChecked(true);
972 case KFileItemDelegate::ModificationTime
:
973 showDateInfo
->setChecked(true);
975 case KFileItemDelegate::Permissions
:
976 showPermissionsInfo
->setChecked(true);
978 case KFileItemDelegate::Owner
:
979 showOwnerInfo
->setChecked(true);
981 case KFileItemDelegate::OwnerAndGroup
:
982 showGroupInfo
->setChecked(true);
984 case KFileItemDelegate::FriendlyMimeType
:
985 showMimeInfo
->setChecked(true);
993 QPair
<bool, QString
> DolphinView::pasteInfo() const
995 QPair
<bool, QString
> ret
;
996 QClipboard
* clipboard
= QApplication::clipboard();
997 const QMimeData
* mimeData
= clipboard
->mimeData();
999 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1000 if (!urls
.isEmpty()) {
1001 // disable the paste action if no writing is supported
1002 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url());
1003 ret
.first
= KonqFileItemCapabilities(KFileItemList() << item
).supportsWriting();
1005 if (urls
.count() == 1) {
1006 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
1007 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
1008 i18nc("@action:inmenu", "Paste One File");
1011 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
1015 ret
.second
= i18nc("@action:inmenu", "Paste");
1021 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1023 m_tabsForFiles
= tabsForFiles
;
1026 bool DolphinView::isTabsForFilesEnabled() const
1028 return m_tabsForFiles
;
1031 void DolphinView::emitContentsMoved()
1033 // only emit the contents moved signal if:
1034 // - no directory loading is ongoing (this would reset the contents position
1035 // always to (0, 0))
1036 // - if the Column View is active: the column view does an automatic
1037 // positioning during the loading operation, which must be remembered
1038 if (!m_loadingDirectory
|| isColumnViewActive()) {
1039 const QPoint
pos(contentsPosition());
1040 emit
contentsMoved(pos
.x(), pos
.y());
1044 void DolphinView::showHoverInformation(const KFileItem
& item
)
1046 emit
requestItemInfo(item
);
1049 void DolphinView::clearHoverInformation()
1051 emit
requestItemInfo(KFileItem());
1054 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1056 if (job
->error() == 0) {
1057 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1058 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1059 emit
errorMessage(job
->errorString());
1063 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1065 emit
requestUrlChange(url
);
1066 m_controller
->setUrl(url
);
1069 void DolphinView::restoreCurrentItem()
1071 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
1072 if (dirIndex
.isValid()) {
1073 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
1074 QAbstractItemView
* view
= itemView();
1075 const bool clearSelection
= !hasSelection();
1076 view
->setCurrentIndex(proxyIndex
);
1077 if (clearSelection
) {
1078 view
->clearSelection();
1083 void DolphinView::enterDir(const QModelIndex
& index
, QAbstractItemView
* view
)
1085 // Deleting a view that is the root of a drag operation is not allowed, otherwise
1086 // the dragging gets automatically cancelled by Qt. So before entering a new
1087 // directory, the current view is remembered in m_expandedViews and deleted
1088 // later when the drag operation has been finished (see DolphinView::eventFilter()).
1089 m_expandedViews
.append(view
);
1090 m_controller
->triggerItem(index
);
1093 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1095 if (!url
.isValid()) {
1096 const QString
location(url
.pathOrUrl());
1097 if (location
.isEmpty()) {
1098 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1100 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1105 m_loadingDirectory
= true;
1107 m_dirLister
->stop();
1108 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1110 if (isColumnViewActive()) {
1111 // adjusting the directory lister is not enough in the case of the
1112 // column view, as each column has its own directory lister internally...
1114 m_columnView
->reload();
1116 m_columnView
->showColumn(url
);
1121 KUrl
DolphinView::viewPropertiesUrl() const
1123 if (isColumnViewActive()) {
1124 return m_columnView
->rootUrl();
1130 void DolphinView::applyViewProperties(const KUrl
& url
)
1132 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1133 // The column view is active, hence don't apply the view properties
1134 // of sub directories (represented by columns) to the view. The
1135 // view always represents the properties of the first column.
1139 const ViewProperties
props(url
);
1141 const Mode mode
= props
.viewMode();
1142 if (m_mode
!= mode
) {
1143 const int oldZoomLevel
= m_controller
->zoomLevel();
1149 updateZoomLevel(oldZoomLevel
);
1151 if (itemView() == 0) {
1154 Q_ASSERT(itemView() != 0);
1155 Q_ASSERT(m_fileItemDelegate
!= 0);
1157 const bool showHiddenFiles
= props
.showHiddenFiles();
1158 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1159 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1160 emit
showHiddenFilesChanged();
1163 m_storedCategorizedSorting
= props
.categorizedSorting();
1164 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1165 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1166 m_proxyModel
->setCategorizedModel(categorized
);
1167 emit
categorizedSortingChanged();
1170 const DolphinView::Sorting sorting
= props
.sorting();
1171 if (sorting
!= m_proxyModel
->sorting()) {
1172 m_proxyModel
->setSorting(sorting
);
1173 emit
sortingChanged(sorting
);
1176 const Qt::SortOrder sortOrder
= props
.sortOrder();
1177 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1178 m_proxyModel
->setSortOrder(sortOrder
);
1179 emit
sortOrderChanged(sortOrder
);
1182 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1183 if (info
!= m_fileItemDelegate
->showInformation()) {
1184 m_fileItemDelegate
->setShowInformation(info
);
1185 emit
additionalInfoChanged();
1188 const bool showPreview
= props
.showPreview();
1189 if (showPreview
!= m_showPreview
) {
1190 m_showPreview
= showPreview
;
1191 m_previewGenerator
->setPreviewShown(showPreview
);
1193 const int oldZoomLevel
= m_controller
->zoomLevel();
1194 emit
showPreviewChanged();
1196 // Enabling or disabling the preview might change the icon size of the view.
1197 // As the view does not emit a signal when the icon size has been changed,
1198 // the used zoom level of the controller must be adjusted manually:
1199 updateZoomLevel(oldZoomLevel
);
1203 void DolphinView::createView()
1206 Q_ASSERT(m_iconsView
== 0);
1207 Q_ASSERT(m_detailsView
== 0);
1208 Q_ASSERT(m_columnView
== 0);
1210 QAbstractItemView
* view
= 0;
1213 m_iconsView
= new DolphinIconsView(this, m_controller
);
1219 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1220 view
= m_detailsView
;
1224 m_columnView
= new DolphinColumnView(this, m_controller
);
1225 view
= m_columnView
;
1229 Q_ASSERT(view
!= 0);
1230 view
->installEventFilter(this);
1231 view
->viewport()->installEventFilter(this);
1233 if (m_mode
!= ColumnView
) {
1234 // Give the view the ability to auto-expand its directories on hovering
1235 // (the column view takes care about this itself). If the details view
1236 // uses expandable folders, the auto-expanding should be used always.
1237 DolphinSettings
& settings
= DolphinSettings::instance();
1238 const bool enabled
= settings
.generalSettings()->autoExpandFolders() ||
1239 ((m_detailsView
!= 0) && settings
.detailsModeSettings()->expandableFolders());
1241 FolderExpander
* folderExpander
= new FolderExpander(view
, m_proxyModel
);
1242 folderExpander
->setEnabled(enabled
);
1243 connect(folderExpander
, SIGNAL(enterDir(const QModelIndex
&, QAbstractItemView
*)),
1244 this, SLOT(enterDir(const QModelIndex
&, QAbstractItemView
*)));
1247 m_controller
->setItemView(view
);
1249 m_fileItemDelegate
= new DolphinFileItemDelegate(view
);
1250 m_fileItemDelegate
->setShowToolTipWhenElided(false);
1251 m_fileItemDelegate
->setMinimizedNameColumn(m_mode
== DetailsView
);
1252 view
->setItemDelegate(m_fileItemDelegate
);
1254 view
->setModel(m_proxyModel
);
1255 if (m_selectionModel
!= 0) {
1256 view
->setSelectionModel(m_selectionModel
);
1258 m_selectionModel
= view
->selectionModel();
1261 // reparent the selection model, as it should not be deleted
1262 // when deleting the model
1263 m_selectionModel
->setParent(this);
1265 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1267 m_previewGenerator
= new KFilePreviewGenerator(view
);
1268 m_previewGenerator
->setPreviewShown(m_showPreview
);
1270 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1271 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1272 connect(m_controller
, SIGNAL(hideToolTip()),
1273 m_toolTipManager
, SLOT(hideTip()));
1276 m_topLayout
->insertWidget(1, view
);
1278 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1279 this, SLOT(emitSelectionChangedSignal()));
1280 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1281 this, SLOT(emitContentsMoved()));
1282 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1283 this, SLOT(emitContentsMoved()));
1286 void DolphinView::deleteView()
1288 QAbstractItemView
* view
= itemView();
1290 // It's important to set the keyboard focus to the parent
1291 // before deleting the view: Otherwise when having a split
1292 // view the other view will get the focus and will request
1293 // an activation (see DolphinView::eventFilter()).
1296 m_topLayout
->removeWidget(view
);
1300 m_controller
->disconnect(view
);
1303 bool deleteView
= true;
1304 foreach (const QAbstractItemView
* expandedView
, m_expandedViews
) {
1305 if (view
== expandedView
) {
1306 // the current view got already expanded and must stay alive
1307 // until the dragging has been completed
1313 view
->deleteLater();
1320 m_fileItemDelegate
= 0;
1321 m_previewGenerator
= 0;
1322 m_toolTipManager
= 0;
1326 QAbstractItemView
* DolphinView::itemView() const
1328 if (m_detailsView
!= 0) {
1329 return m_detailsView
;
1330 } else if (m_columnView
!= 0) {
1331 return m_columnView
;
1337 bool DolphinView::isCutItem(const KFileItem
& item
) const
1339 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1340 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1342 const KUrl
& itemUrl
= item
.url();
1343 KUrl::List::const_iterator it
= cutUrls
.begin();
1344 const KUrl::List::const_iterator end
= cutUrls
.end();
1346 if (*it
== itemUrl
) {
1355 void DolphinView::pasteToUrl(const KUrl
& url
)
1357 QClipboard
* clipboard
= QApplication::clipboard();
1358 const QMimeData
* mimeData
= clipboard
->mimeData();
1360 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1361 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1362 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1365 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1369 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1371 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(itemView()->iconSize());
1372 if (oldZoomLevel
!= newZoomLevel
) {
1373 m_controller
->setZoomLevel(newZoomLevel
);
1374 emit
zoomLevelChanged(newZoomLevel
);
1378 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1380 KUrl::List list
= selectedUrls();
1381 if (itemsExpandable() ) {
1382 list
= KonqOperations::simplifiedUrlList(list
);
1387 void DolphinView::deleteExpandedViews()
1389 const QAbstractItemView
* view
= itemView();
1390 foreach (QAbstractItemView
* expandedView
, m_expandedViews
) {
1391 if (expandedView
!= view
) {
1392 expandedView
->deleteLater();
1395 m_expandedViews
.clear();
1398 bool DolphinView::itemsExpandable() const
1400 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1403 #include "dolphinview.moc"