1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinview.h"
23 #include <QApplication>
26 #include <QItemSelection>
31 #include <kactioncollection.h>
32 #include <kcolorscheme.h>
33 #include <kdirlister.h>
34 #include <kfileitemdelegate.h>
35 #include <kiconeffect.h>
37 #include <kio/deletejob.h>
38 #include <kio/netaccess.h>
39 #include <kio/previewjob.h>
42 #include <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 "dolphindropcontroller.h"
51 #include "dolphinmodel.h"
52 #include "dolphincolumnview.h"
53 #include "dolphincontroller.h"
54 #include "dolphinsortfilterproxymodel.h"
55 #include "dolphindetailsview.h"
56 #include "dolphiniconsview.h"
57 #include "dolphinsettings.h"
58 #include "dolphin_generalsettings.h"
59 #include "iconmanager.h"
60 #include "renamedialog.h"
61 #include "tooltipmanager.h"
62 #include "viewproperties.h"
64 DolphinView::DolphinView(QWidget
* parent
,
66 KDirLister
* dirLister
,
67 DolphinModel
* dolphinModel
,
68 DolphinSortFilterProxyModel
* proxyModel
) :
72 m_loadingDirectory(false),
73 m_storedCategorizedSorting(false),
74 m_tabsForFiles(false),
75 m_isContextMenuOpen(false),
76 m_mode(DolphinView::IconsView
),
82 m_fileItemDelegate(0),
84 m_dolphinModel(dolphinModel
),
85 m_dirLister(dirLister
),
86 m_proxyModel(proxyModel
),
92 m_topLayout
= new QVBoxLayout(this);
93 m_topLayout
->setSpacing(0);
94 m_topLayout
->setMargin(0);
96 m_controller
= new DolphinController(this);
97 m_controller
->setUrl(url
);
99 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
100 this, SIGNAL(urlChanged(const KUrl
&)));
101 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
102 this, SLOT(slotRequestUrlChange(const KUrl
&)));
104 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
105 this, SLOT(openContextMenu(const QPoint
&)));
106 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
107 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
108 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
109 this, SLOT(updateSorting(DolphinView::Sorting
)));
110 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
111 this, SLOT(updateSortOrder(Qt::SortOrder
)));
112 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
113 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
114 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
115 this, SLOT(triggerItem(const KFileItem
&)));
116 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
117 this, SIGNAL(tabRequested(const KUrl
&)));
118 connect(m_controller
, SIGNAL(activated()),
119 this, SLOT(activate()));
120 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
121 this, SLOT(showHoverInformation(const KFileItem
&)));
122 connect(m_controller
, SIGNAL(viewportEntered()),
123 this, SLOT(clearHoverInformation()));
125 connect(m_dirLister
, SIGNAL(redirection(KUrl
, KUrl
)),
126 this, SLOT(slotRedirection(KUrl
, KUrl
)));
127 connect(m_dirLister
, SIGNAL(completed()),
128 this, SLOT(restoreCurrentItem()));
130 applyViewProperties(url
);
131 m_topLayout
->addWidget(itemView());
134 DolphinView::~DolphinView()
138 const KUrl
& DolphinView::url() const
140 return m_controller
->url();
143 KUrl
DolphinView::rootUrl() const
145 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
148 void DolphinView::setActive(bool active
)
150 if (active
== m_active
) {
156 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
158 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
159 // bypasses the problem when having a split view and changing the active view to
160 // update the some URL dependent states. A nicer approach should be no big deal...
161 emit
urlChanged(url());
162 emit
selectionChanged(selectedItems());
167 QWidget
* viewport
= itemView()->viewport();
169 palette
.setColor(viewport
->backgroundRole(), color
);
170 viewport
->setPalette(palette
);
175 itemView()->setFocus();
179 m_controller
->indicateActivationChange(active
);
182 bool DolphinView::isActive() const
187 void DolphinView::setMode(Mode mode
)
189 if (mode
== m_mode
) {
190 return; // the wished mode is already set
197 const KUrl viewPropsUrl
= viewPropertiesUrl();
198 ViewProperties
props(viewPropsUrl
);
199 props
.setViewMode(m_mode
);
202 // the file item delegate has been recreated, apply the current
203 // additional information manually
204 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
205 m_fileItemDelegate
->setShowInformation(infoList
);
206 emit
additionalInfoChanged();
208 // Not all view modes support categorized sorting. Adjust the sorting model
209 // if changing the view mode results in a change of the categorized sorting
211 m_storedCategorizedSorting
= props
.categorizedSorting();
212 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
213 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
214 m_proxyModel
->setCategorizedModel(categorized
);
215 emit
categorizedSortingChanged();
221 DolphinView::Mode
DolphinView::mode() const
226 bool DolphinView::showPreview() const
228 return m_showPreview
;
231 bool DolphinView::showHiddenFiles() const
233 return m_dirLister
->showingDotFiles();
236 bool DolphinView::categorizedSorting() const
238 // If all view modes would support categorized sorting, returning
239 // m_proxyModel->isCategorizedModel() would be the way to go. As
240 // currently only the icons view supports caterized sorting, we remember
241 // the stored view properties state in m_storedCategorizedSorting and
242 // return this state. The application takes care to disable the corresponding
243 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
244 // that this setting is not applied to the current view mode.
245 return m_storedCategorizedSorting
;
248 bool DolphinView::supportsCategorizedSorting() const
250 return m_iconsView
!= 0;
253 void DolphinView::selectAll()
255 QAbstractItemView
* view
= itemView();
256 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
257 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
258 // selection instead of selecting all items. This is bypassed for KDE 4.0
259 // by invoking clearSelection() first.
260 view
->clearSelection();
264 void DolphinView::invertSelection()
266 if (isColumnViewActive()) {
267 // QAbstractItemView does not offer a virtual method invertSelection()
268 // as counterpart to QAbstractItemView::selectAll(). This makes it
269 // necessary to delegate the inverting of the selection to the
270 // column view, as only the selection of the active column should
272 m_columnView
->invertSelection();
274 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
275 const QAbstractItemModel
* itemModel
= selectionModel
->model();
277 const QModelIndex topLeft
= itemModel
->index(0, 0);
278 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
279 itemModel
->columnCount() - 1);
281 const QItemSelection
selection(topLeft
, bottomRight
);
282 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
286 bool DolphinView::hasSelection() const
288 return itemView()->selectionModel()->hasSelection();
291 void DolphinView::clearSelection()
293 itemView()->selectionModel()->clear();
296 KFileItemList
DolphinView::selectedItems() const
298 if (isColumnViewActive()) {
299 return m_columnView
->selectedItems();
302 const QAbstractItemView
* view
= itemView();
304 // Our view has a selection, we will map them back to the DolphinModel
305 // and then fill the KFileItemList.
306 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
308 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
309 KFileItemList itemList
;
311 const QModelIndexList indexList
= selection
.indexes();
312 foreach (const QModelIndex
&index
, indexList
) {
313 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
314 if (!item
.isNull()) {
315 itemList
.append(item
);
322 KUrl::List
DolphinView::selectedUrls() const
325 const KFileItemList list
= selectedItems();
326 foreach (const KFileItem
&item
, list
) {
327 urls
.append(item
.url());
332 int DolphinView::selectedItemsCount() const
334 if (isColumnViewActive()) {
335 // TODO: get rid of this special case by adjusting the dir lister
336 // to the current column
337 return m_columnView
->selectedItems().count();
340 return itemView()->selectionModel()->selection().count();
343 void DolphinView::setContentsPosition(int x
, int y
)
345 QAbstractItemView
* view
= itemView();
347 // the ColumnView takes care itself for the horizontal scrolling
348 if (!isColumnViewActive()) {
349 view
->horizontalScrollBar()->setValue(x
);
351 view
->verticalScrollBar()->setValue(y
);
353 m_loadingDirectory
= false;
356 QPoint
DolphinView::contentsPosition() const
358 const int x
= itemView()->horizontalScrollBar()->value();
359 const int y
= itemView()->verticalScrollBar()->value();
363 void DolphinView::zoomIn()
365 m_controller
->triggerZoomIn();
366 m_iconManager
->updatePreviews();
369 void DolphinView::zoomOut()
371 m_controller
->triggerZoomOut();
372 m_iconManager
->updatePreviews();
375 bool DolphinView::isZoomInPossible() const
377 return m_controller
->isZoomInPossible();
380 bool DolphinView::isZoomOutPossible() const
382 return m_controller
->isZoomOutPossible();
385 void DolphinView::setSorting(Sorting sorting
)
387 if (sorting
!= this->sorting()) {
388 updateSorting(sorting
);
392 DolphinView::Sorting
DolphinView::sorting() const
394 return m_proxyModel
->sorting();
397 void DolphinView::setSortOrder(Qt::SortOrder order
)
399 if (sortOrder() != order
) {
400 updateSortOrder(order
);
404 Qt::SortOrder
DolphinView::sortOrder() const
406 return m_proxyModel
->sortOrder();
409 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
411 const KUrl viewPropsUrl
= viewPropertiesUrl();
412 ViewProperties
props(viewPropsUrl
);
413 props
.setAdditionalInfo(info
);
414 m_fileItemDelegate
->setShowInformation(info
);
416 emit
additionalInfoChanged();
418 if (itemView() != m_detailsView
) {
419 // the details view requires no reloading of the directory, as it maps
420 // the file item delegate info to its columns internally
421 loadDirectory(viewPropsUrl
);
425 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
427 return m_fileItemDelegate
->showInformation();
430 void DolphinView::reload()
433 loadDirectory(url(), true);
436 void DolphinView::refresh()
438 const bool oldActivationState
= m_active
;
442 applyViewProperties(m_controller
->url());
445 setActive(oldActivationState
);
448 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
450 if (m_controller
->url() == url
) {
454 m_iconManager
->cancelPreviews();
455 m_controller
->setUrl(url
); // emits urlChanged, which we forward
457 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
458 applyViewProperties(rootUrl
);
459 loadDirectory(rootUrl
);
460 if (itemView() == m_columnView
) {
461 m_columnView
->setRootUrl(rootUrl
);
462 m_columnView
->showColumn(url
);
465 applyViewProperties(url
);
469 emit
startedPathLoading(url
);
472 void DolphinView::setNameFilter(const QString
& nameFilter
)
474 m_proxyModel
->setFilterRegExp(nameFilter
);
476 if (isColumnViewActive()) {
477 // adjusting the directory lister is not enough in the case of the
478 // column view, as each column has its own directory lister internally...
479 m_columnView
->setNameFilter(nameFilter
);
483 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
485 foreach (const KFileItem
&item
, m_dirLister
->items()) {
494 void DolphinView::setUrl(const KUrl
& url
)
496 // remember current item candidate (see restoreCurrentItem())
497 m_currentItemUrl
= url
;
498 updateView(url
, KUrl());
501 void DolphinView::changeSelection(const KFileItemList
& selection
)
504 if (selection
.isEmpty()) {
507 const KUrl
& baseUrl
= url();
509 QItemSelection new_selection
;
510 foreach(const KFileItem
& item
, selection
) {
511 url
= item
.url().upUrl();
512 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
513 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
514 new_selection
.select(index
, index
);
517 itemView()->selectionModel()->select(new_selection
,
518 QItemSelectionModel::ClearAndSelect
519 | QItemSelectionModel::Current
);
522 void DolphinView::renameSelectedItems()
524 const KFileItemList items
= selectedItems();
525 const int itemCount
= items
.count();
531 // More than one item has been selected for renaming. Open
532 // a rename dialog and rename all items afterwards.
533 RenameDialog
dialog(this, items
);
534 if (dialog
.exec() == QDialog::Rejected
) {
538 const QString newName
= dialog
.newName();
539 if (newName
.isEmpty()) {
540 emit
errorMessage(dialog
.errorString());
542 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
543 // as one operation instead of n rename operations like it is done now...
544 Q_ASSERT(newName
.contains('#'));
546 // iterate through all selected items and rename them...
548 foreach (const KFileItem
&item
, items
) {
549 const KUrl
& oldUrl
= item
.url();
551 number
.setNum(index
++);
553 QString name
= newName
;
554 name
.replace('#', number
);
556 if (oldUrl
.fileName() != name
) {
557 KUrl newUrl
= oldUrl
;
558 newUrl
.setFileName(name
);
559 KonqOperations::rename(this, oldUrl
, newUrl
);
560 emit
doingOperation(KIO::FileUndoManager::Rename
);
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
);
590 emit
doingOperation(KIO::FileUndoManager::Rename
);
595 void DolphinView::trashSelectedItems()
597 emit
doingOperation(KIO::FileUndoManager::Trash
);
598 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
601 void DolphinView::deleteSelectedItems()
603 const KUrl::List list
= selectedUrls();
604 const bool del
= KonqOperations::askDeleteConfirmation(list
,
606 KonqOperations::DEFAULT_CONFIRMATION
,
610 KIO::Job
* job
= KIO::del(list
);
611 connect(job
, SIGNAL(result(KJob
*)),
612 this, SLOT(slotDeleteFileFinished(KJob
*)));
616 void DolphinView::cutSelectedItems()
618 QMimeData
* mimeData
= new QMimeData();
619 const KUrl::List kdeUrls
= selectedUrls();
620 const KUrl::List mostLocalUrls
;
621 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
622 QApplication::clipboard()->setMimeData(mimeData
);
625 void DolphinView::copySelectedItems()
627 QMimeData
* mimeData
= new QMimeData();
628 const KUrl::List kdeUrls
= selectedUrls();
629 const KUrl::List mostLocalUrls
;
630 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
631 QApplication::clipboard()->setMimeData(mimeData
);
634 void DolphinView::paste()
639 void DolphinView::pasteIntoFolder()
641 const KFileItemList items
= selectedItems();
642 if ((items
.count() == 1) && items
.first().isDir()) {
643 pasteToUrl(items
.first().url());
647 void DolphinView::setShowPreview(bool show
)
649 if (m_showPreview
== show
) {
653 const KUrl viewPropsUrl
= viewPropertiesUrl();
654 ViewProperties
props(viewPropsUrl
);
655 props
.setShowPreview(show
);
657 m_showPreview
= show
;
658 m_iconManager
->setShowPreview(show
);
659 emit
showPreviewChanged();
661 loadDirectory(viewPropsUrl
);
664 void DolphinView::setShowHiddenFiles(bool show
)
666 if (m_dirLister
->showingDotFiles() == show
) {
670 const KUrl viewPropsUrl
= viewPropertiesUrl();
671 ViewProperties
props(viewPropsUrl
);
672 props
.setShowHiddenFiles(show
);
674 m_dirLister
->setShowingDotFiles(show
);
675 emit
showHiddenFilesChanged();
677 loadDirectory(viewPropsUrl
);
680 void DolphinView::setCategorizedSorting(bool categorized
)
682 if (categorized
== categorizedSorting()) {
686 // setCategorizedSorting(true) may only get invoked
687 // if the view supports categorized sorting
688 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
690 ViewProperties
props(viewPropertiesUrl());
691 props
.setCategorizedSorting(categorized
);
694 m_storedCategorizedSorting
= categorized
;
695 m_proxyModel
->setCategorizedModel(categorized
);
697 emit
categorizedSortingChanged();
700 void DolphinView::toggleSortOrder()
702 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
703 Qt::DescendingOrder
:
708 void DolphinView::toggleAdditionalInfo(QAction
* action
)
710 const KFileItemDelegate::Information info
=
711 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
713 KFileItemDelegate::InformationList list
= additionalInfo();
715 const bool show
= action
->isChecked();
717 const int index
= list
.indexOf(info
);
718 const bool containsInfo
= (index
>= 0);
719 if (show
&& !containsInfo
) {
721 setAdditionalInfo(list
);
722 } else if (!show
&& containsInfo
) {
723 list
.removeAt(index
);
724 setAdditionalInfo(list
);
725 Q_ASSERT(list
.indexOf(info
) < 0);
730 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
732 QWidget::mouseReleaseEvent(event
);
736 void DolphinView::wheelEvent(QWheelEvent
* event
)
738 if (event
->modifiers() & Qt::ControlModifier
) {
739 const int delta
= event
->delta();
740 if ((delta
> 0) && isZoomInPossible()) {
742 } else if ((delta
< 0) && isZoomOutPossible()) {
749 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
751 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
752 m_controller
->requestActivation();
755 return QWidget::eventFilter(watched
, event
);
758 void DolphinView::activate()
763 void DolphinView::triggerItem(const KFileItem
& item
)
765 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
766 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
767 // items are selected by the user, hence don't trigger the
768 // item specified by 'index'
772 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
773 if (item
.isNull() || m_isContextMenuOpen
) {
777 if (m_toolTipManager
!= 0) {
778 m_toolTipManager
->hideTip();
780 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
783 void DolphinView::emitSelectionChangedSignal()
785 emit
selectionChanged(DolphinView::selectedItems());
788 void DolphinView::openContextMenu(const QPoint
& pos
)
791 if (isColumnViewActive()) {
792 item
= m_columnView
->itemAt(pos
);
794 const QModelIndex index
= itemView()->indexAt(pos
);
795 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
796 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
797 item
= m_dolphinModel
->itemForIndex(dolphinModelIndex
);
801 if (m_toolTipManager
!= 0) {
802 m_toolTipManager
->hideTip();
805 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
806 emit
requestContextMenu(item
, url());
807 m_isContextMenuOpen
= false;
810 void DolphinView::dropUrls(const KUrl::List
& urls
,
811 const KUrl
& destPath
,
812 const KFileItem
& destItem
)
814 Q_ASSERT(!urls
.isEmpty());
815 const KUrl destination
= !destItem
.isNull() && destItem
.isDir() ?
816 destItem
.url() : destPath
;
817 const KUrl sourceDir
= KUrl(urls
.first().directory());
818 if (sourceDir
!= destination
) {
819 DolphinDropController
dropController(this);
820 // forward doingOperation signal up to the mainwindow
821 connect(&dropController
, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)),
822 this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)));
823 dropController
.dropUrls(urls
, destination
);
827 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
829 ViewProperties
props(viewPropertiesUrl());
830 props
.setSorting(sorting
);
832 m_proxyModel
->setSorting(sorting
);
834 emit
sortingChanged(sorting
);
837 void DolphinView::updateSortOrder(Qt::SortOrder order
)
839 ViewProperties
props(viewPropertiesUrl());
840 props
.setSortOrder(order
);
842 m_proxyModel
->setSortOrder(order
);
844 emit
sortOrderChanged(order
);
847 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
849 ViewProperties
props(viewPropertiesUrl());
850 props
.setAdditionalInfo(info
);
853 m_fileItemDelegate
->setShowInformation(info
);
855 emit
additionalInfoChanged();
858 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
860 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
861 (m_mode
== DolphinView::IconsView
);
863 QAction
* showSizeInfo
= collection
->action("show_size_info");
864 QAction
* showDateInfo
= collection
->action("show_date_info");
865 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
866 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
867 QAction
* showGroupInfo
= collection
->action("show_group_info");
868 QAction
* showMimeInfo
= collection
->action("show_mime_info");
870 showSizeInfo
->setChecked(false);
871 showDateInfo
->setChecked(false);
872 showPermissionsInfo
->setChecked(false);
873 showOwnerInfo
->setChecked(false);
874 showGroupInfo
->setChecked(false);
875 showMimeInfo
->setChecked(false);
877 showSizeInfo
->setEnabled(enable
);
878 showDateInfo
->setEnabled(enable
);
879 showPermissionsInfo
->setEnabled(enable
);
880 showOwnerInfo
->setEnabled(enable
);
881 showGroupInfo
->setEnabled(enable
);
882 showMimeInfo
->setEnabled(enable
);
884 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
886 case KFileItemDelegate::Size
:
887 showSizeInfo
->setChecked(true);
889 case KFileItemDelegate::ModificationTime
:
890 showDateInfo
->setChecked(true);
892 case KFileItemDelegate::Permissions
:
893 showPermissionsInfo
->setChecked(true);
895 case KFileItemDelegate::Owner
:
896 showOwnerInfo
->setChecked(true);
898 case KFileItemDelegate::OwnerAndGroup
:
899 showGroupInfo
->setChecked(true);
901 case KFileItemDelegate::FriendlyMimeType
:
902 showMimeInfo
->setChecked(true);
910 QPair
<bool, QString
> DolphinView::pasteInfo() const
912 QPair
<bool, QString
> ret
;
913 QClipboard
* clipboard
= QApplication::clipboard();
914 const QMimeData
* mimeData
= clipboard
->mimeData();
916 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
917 if (!urls
.isEmpty()) {
918 // disable the paste action if no writing is supported
919 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url());
920 ret
.first
= KonqFileItemCapabilities(KFileItemList() << item
).supportsWriting();
922 if (urls
.count() == 1) {
923 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
924 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
925 i18nc("@action:inmenu", "Paste One File");
928 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
932 ret
.second
= i18nc("@action:inmenu", "Paste");
938 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
940 m_tabsForFiles
= tabsForFiles
;
943 bool DolphinView::isTabsForFilesEnabled() const
945 return m_tabsForFiles
;
948 void DolphinView::emitContentsMoved()
950 // only emit the contents moved signal if:
951 // - no directory loading is ongoing (this would reset the contents position
953 // - if the Column View is active: the column view does an automatic
954 // positioning during the loading operation, which must be remembered
955 if (!m_loadingDirectory
|| isColumnViewActive()) {
956 const QPoint
pos(contentsPosition());
957 emit
contentsMoved(pos
.x(), pos
.y());
961 void DolphinView::showHoverInformation(const KFileItem
& item
)
963 emit
requestItemInfo(item
);
966 void DolphinView::clearHoverInformation()
968 emit
requestItemInfo(KFileItem());
971 void DolphinView::slotDeleteFileFinished(KJob
* job
)
973 if (job
->error() == 0) {
974 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
976 emit
errorMessage(job
->errorString());
981 void DolphinView::restoreCurrentItem()
983 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
984 if (dirIndex
.isValid()) {
985 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
986 QAbstractItemView
* view
= itemView();
987 const bool clearSelection
= !hasSelection();
988 view
->setCurrentIndex(proxyIndex
);
989 if (clearSelection
) {
990 view
->clearSelection();
995 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
997 if (!url
.isValid()) {
998 const QString
location(url
.pathOrUrl());
999 if (location
.isEmpty()) {
1000 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1002 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1007 m_loadingDirectory
= true;
1009 m_dirLister
->stop();
1010 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1012 if (isColumnViewActive()) {
1013 // adjusting the directory lister is not enough in the case of the
1014 // column view, as each column has its own directory lister internally...
1016 m_columnView
->reload();
1018 m_columnView
->showColumn(url
);
1023 KUrl
DolphinView::viewPropertiesUrl() const
1025 if (isColumnViewActive()) {
1026 return m_columnView
->rootUrl();
1032 void DolphinView::applyViewProperties(const KUrl
& url
)
1034 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1035 // The column view is active, hence don't apply the view properties
1036 // of sub directories (represented by columns) to the view. The
1037 // view always represents the properties of the first column.
1041 const ViewProperties
props(url
);
1043 const Mode mode
= props
.viewMode();
1044 if (m_mode
!= mode
) {
1049 if (itemView() == 0) {
1052 Q_ASSERT(itemView() != 0);
1053 Q_ASSERT(m_fileItemDelegate
!= 0);
1055 const bool showHiddenFiles
= props
.showHiddenFiles();
1056 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1057 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1058 emit
showHiddenFilesChanged();
1061 m_storedCategorizedSorting
= props
.categorizedSorting();
1062 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1063 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1064 m_proxyModel
->setCategorizedModel(categorized
);
1065 emit
categorizedSortingChanged();
1068 const DolphinView::Sorting sorting
= props
.sorting();
1069 if (sorting
!= m_proxyModel
->sorting()) {
1070 m_proxyModel
->setSorting(sorting
);
1071 emit
sortingChanged(sorting
);
1074 const Qt::SortOrder sortOrder
= props
.sortOrder();
1075 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1076 m_proxyModel
->setSortOrder(sortOrder
);
1077 emit
sortOrderChanged(sortOrder
);
1080 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1081 if (info
!= m_fileItemDelegate
->showInformation()) {
1082 m_fileItemDelegate
->setShowInformation(info
);
1083 emit
additionalInfoChanged();
1086 const bool showPreview
= props
.showPreview();
1087 if (showPreview
!= m_showPreview
) {
1088 m_showPreview
= showPreview
;
1089 m_iconManager
->setShowPreview(showPreview
);
1090 emit
showPreviewChanged();
1094 void DolphinView::createView()
1097 Q_ASSERT(m_iconsView
== 0);
1098 Q_ASSERT(m_detailsView
== 0);
1099 Q_ASSERT(m_columnView
== 0);
1101 QAbstractItemView
* view
= 0;
1104 m_iconsView
= new DolphinIconsView(this, m_controller
);
1110 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1111 view
= m_detailsView
;
1115 m_columnView
= new DolphinColumnView(this, m_controller
);
1116 view
= m_columnView
;
1120 Q_ASSERT(view
!= 0);
1121 view
->installEventFilter(this);
1123 m_controller
->setItemView(view
);
1125 m_fileItemDelegate
= new KFileItemDelegate(view
);
1126 view
->setItemDelegate(m_fileItemDelegate
);
1128 view
->setModel(m_proxyModel
);
1129 if (m_selectionModel
!= 0) {
1130 view
->setSelectionModel(m_selectionModel
);
1132 m_selectionModel
= view
->selectionModel();
1135 // reparent the selection model, as it should not be deleted
1136 // when deleting the model
1137 m_selectionModel
->setParent(this);
1139 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1141 m_iconManager
= new IconManager(view
, m_proxyModel
);
1142 m_iconManager
->setShowPreview(m_showPreview
);
1144 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1145 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1148 m_topLayout
->insertWidget(1, view
);
1150 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1151 this, SLOT(emitSelectionChangedSignal()));
1152 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1153 this, SLOT(emitContentsMoved()));
1154 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1155 this, SLOT(emitContentsMoved()));
1158 void DolphinView::deleteView()
1160 QAbstractItemView
* view
= itemView();
1162 // It's important to set the keyboard focus to the parent
1163 // before deleting the view: Otherwise when having a split
1164 // view the other view will get the focus and will request
1165 // an activation (see DolphinView::eventFilter()).
1168 m_topLayout
->removeWidget(view
);
1170 view
->deleteLater();
1175 m_fileItemDelegate
= 0;
1177 m_toolTipManager
= 0;
1181 QAbstractItemView
* DolphinView::itemView() const
1183 if (m_detailsView
!= 0) {
1184 return m_detailsView
;
1185 } else if (m_columnView
!= 0) {
1186 return m_columnView
;
1192 bool DolphinView::isCutItem(const KFileItem
& item
) const
1194 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1195 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1197 const KUrl
& itemUrl
= item
.url();
1198 KUrl::List::const_iterator it
= cutUrls
.begin();
1199 const KUrl::List::const_iterator end
= cutUrls
.end();
1201 if (*it
== itemUrl
) {
1210 void DolphinView::pasteToUrl(const KUrl
& url
)
1212 QClipboard
* clipboard
= QApplication::clipboard();
1213 const QMimeData
* mimeData
= clipboard
->mimeData();
1215 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1216 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1217 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1218 emit
doingOperation(KIO::FileUndoManager::Move
);
1221 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1222 emit
doingOperation(KIO::FileUndoManager::Copy
);
1226 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1228 emit
requestUrlChange(url
);
1229 m_controller
->setUrl(url
);
1232 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1234 if (oldUrl
== m_controller
->url()) {
1235 m_controller
->setUrl(newUrl
);
1239 #include "dolphinview.moc"