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_operations.h>
45 #include <konqmimedata.h>
46 #include <ktoggleaction.h>
49 #include "dolphindropcontroller.h"
50 #include "dolphinmodel.h"
51 #include "dolphincolumnview.h"
52 #include "dolphincontroller.h"
53 #include "dolphinsortfilterproxymodel.h"
54 #include "dolphindetailsview.h"
55 #include "dolphiniconsview.h"
56 #include "dolphinsettings.h"
57 #include "dolphin_generalsettings.h"
58 #include "iconmanager.h"
59 #include "renamedialog.h"
60 #include "tooltipmanager.h"
61 #include "viewproperties.h"
63 DolphinView::DolphinView(QWidget
* parent
,
65 KDirLister
* dirLister
,
66 DolphinModel
* dolphinModel
,
67 DolphinSortFilterProxyModel
* proxyModel
) :
71 m_loadingDirectory(false),
72 m_storedCategorizedSorting(false),
73 m_tabsForFiles(false),
74 m_isContextMenuOpen(false),
75 m_mode(DolphinView::IconsView
),
81 m_fileItemDelegate(0),
83 m_dolphinModel(dolphinModel
),
84 m_dirLister(dirLister
),
85 m_proxyModel(proxyModel
),
89 m_topLayout
= new QVBoxLayout(this);
90 m_topLayout
->setSpacing(0);
91 m_topLayout
->setMargin(0);
93 m_controller
= new DolphinController(this);
94 m_controller
->setUrl(url
);
96 // Receiver of the DolphinView signal 'urlChanged()' don't need
97 // to care whether the internal controller changed the URL already or whether
98 // the controller just requested an URL change and will be updated later.
99 // In both cases the URL has been changed:
100 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
101 this, SIGNAL(urlChanged(const KUrl
&)));
102 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
103 this, SIGNAL(urlChanged(const KUrl
&)));
105 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
106 this, SLOT(openContextMenu(const QPoint
&)));
107 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
108 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
109 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
110 this, SLOT(updateSorting(DolphinView::Sorting
)));
111 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
112 this, SLOT(updateSortOrder(Qt::SortOrder
)));
113 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
114 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
115 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
116 this, SLOT(triggerItem(const KFileItem
&)));
117 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
118 this, SIGNAL(tabRequested(const KUrl
&)));
119 connect(m_controller
, SIGNAL(activated()),
120 this, SLOT(activate()));
121 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
122 this, SLOT(showHoverInformation(const KFileItem
&)));
123 connect(m_controller
, SIGNAL(viewportEntered()),
124 this, SLOT(clearHoverInformation()));
126 applyViewProperties(url
);
127 m_topLayout
->addWidget(itemView());
130 DolphinView::~DolphinView()
134 const KUrl
& DolphinView::url() const
136 return m_controller
->url();
139 KUrl
DolphinView::rootUrl() const
141 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
144 void DolphinView::setActive(bool active
)
146 if (active
== m_active
) {
151 m_selectionModel
->clearSelection();
153 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
155 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
156 // bypasses the problem when having a split view and changing the active view to
157 // update the some URL dependent states. A nicer approach should be no big deal...
158 emit
urlChanged(url());
159 emit
selectionChanged(selectedItems());
164 QWidget
* viewport
= itemView()->viewport();
166 palette
.setColor(viewport
->backgroundRole(), color
);
167 viewport
->setPalette(palette
);
175 m_controller
->indicateActivationChange(active
);
178 bool DolphinView::isActive() const
183 void DolphinView::setMode(Mode mode
)
185 if (mode
== m_mode
) {
186 return; // the wished mode is already set
193 const KUrl viewPropsUrl
= viewPropertiesUrl();
194 ViewProperties
props(viewPropsUrl
);
195 props
.setViewMode(m_mode
);
198 // the file item delegate has been recreated, apply the current
199 // additional information manually
200 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
201 m_fileItemDelegate
->setShowInformation(infoList
);
202 emit
additionalInfoChanged();
204 // Not all view modes support categorized sorting. Adjust the sorting model
205 // if changing the view mode results in a change of the categorized sorting
207 m_storedCategorizedSorting
= props
.categorizedSorting();
208 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
209 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
210 m_proxyModel
->setCategorizedModel(categorized
);
211 emit
categorizedSortingChanged();
217 DolphinView::Mode
DolphinView::mode() const
222 bool DolphinView::showPreview() const
224 return m_showPreview
;
227 bool DolphinView::showHiddenFiles() const
229 return m_dirLister
->showingDotFiles();
232 bool DolphinView::categorizedSorting() const
234 // If all view modes would support categorized sorting, returning
235 // m_proxyModel->isCategorizedModel() would be the way to go. As
236 // currently only the icons view supports caterized sorting, we remember
237 // the stored view properties state in m_storedCategorizedSorting and
238 // return this state. The application takes care to disable the corresponding
239 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
240 // that this setting is not applied to the current view mode.
241 return m_storedCategorizedSorting
;
244 bool DolphinView::supportsCategorizedSorting() const
246 return m_iconsView
!= 0;
249 void DolphinView::selectAll()
251 QAbstractItemView
* view
= itemView();
252 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
253 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
254 // selection instead of selecting all items. This is bypassed for KDE 4.0
255 // by invoking clearSelection() first.
256 view
->clearSelection();
260 void DolphinView::invertSelection()
262 if (isColumnViewActive()) {
263 // QAbstractItemView does not offer a virtual method invertSelection()
264 // as counterpart to QAbstractItemView::selectAll(). This makes it
265 // necessary to delegate the inverting of the selection to the
266 // column view, as only the selection of the active column should
268 m_columnView
->invertSelection();
270 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
271 const QAbstractItemModel
* itemModel
= selectionModel
->model();
273 const QModelIndex topLeft
= itemModel
->index(0, 0);
274 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
275 itemModel
->columnCount() - 1);
277 const QItemSelection
selection(topLeft
, bottomRight
);
278 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
282 bool DolphinView::hasSelection() const
284 return itemView()->selectionModel()->hasSelection();
287 void DolphinView::clearSelection()
289 itemView()->selectionModel()->clear();
292 KFileItemList
DolphinView::selectedItems() const
294 const QAbstractItemView
* view
= itemView();
296 // Our view has a selection, we will map them back to the DolphinModel
297 // and then fill the KFileItemList.
298 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
300 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
301 KFileItemList itemList
;
303 const QModelIndexList indexList
= selection
.indexes();
304 foreach (const QModelIndex
&index
, indexList
) {
305 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
306 if (!item
.isNull()) {
307 itemList
.append(item
);
314 KUrl::List
DolphinView::selectedUrls() const
317 const KFileItemList list
= selectedItems();
318 foreach (const KFileItem
&item
, list
) {
319 urls
.append(item
.url());
324 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
326 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
327 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
330 void DolphinView::setContentsPosition(int x
, int y
)
332 QAbstractItemView
* view
= itemView();
334 // the ColumnView takes care itself for the horizontal scrolling
335 if (!isColumnViewActive()) {
336 view
->horizontalScrollBar()->setValue(x
);
338 view
->verticalScrollBar()->setValue(y
);
340 m_loadingDirectory
= false;
343 QPoint
DolphinView::contentsPosition() const
345 const int x
= itemView()->horizontalScrollBar()->value();
346 const int y
= itemView()->verticalScrollBar()->value();
350 void DolphinView::setCurrentItem(const KUrl
& url
)
352 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(url
);
353 if (dirIndex
.isValid()) {
354 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
355 QAbstractItemView
* view
= itemView();
356 const bool clearSelection
= !hasSelection();
357 view
->setCurrentIndex(proxyIndex
);
358 if (clearSelection
) {
359 view
->clearSelection();
364 void DolphinView::zoomIn()
366 m_controller
->triggerZoomIn();
367 m_iconManager
->updatePreviews();
370 void DolphinView::zoomOut()
372 m_controller
->triggerZoomOut();
373 m_iconManager
->updatePreviews();
376 bool DolphinView::isZoomInPossible() const
378 return m_controller
->isZoomInPossible();
381 bool DolphinView::isZoomOutPossible() const
383 return m_controller
->isZoomOutPossible();
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_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 updateView(url
, KUrl());
499 void DolphinView::changeSelection(const KFileItemList
& selection
)
502 if (selection
.isEmpty()) {
505 const KUrl
& baseUrl
= url();
507 QItemSelection new_selection
;
508 foreach(const KFileItem
& item
, selection
) {
509 url
= item
.url().upUrl();
510 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
511 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
512 new_selection
.select(index
, index
);
515 itemView()->selectionModel()->select(new_selection
,
516 QItemSelectionModel::ClearAndSelect
517 | QItemSelectionModel::Current
);
520 void DolphinView::renameSelectedItems()
522 const KFileItemList items
= selectedItems();
523 if (items
.count() > 1) {
524 // More than one item has been selected for renaming. Open
525 // a rename dialog and rename all items afterwards.
526 RenameDialog
dialog(this, items
);
527 if (dialog
.exec() == QDialog::Rejected
) {
531 const QString newName
= dialog
.newName();
532 if (newName
.isEmpty()) {
533 emit
errorMessage(dialog
.errorString());
535 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
536 // as one operation instead of n rename operations like it is done now...
537 Q_ASSERT(newName
.contains('#'));
539 // iterate through all selected items and rename them...
541 foreach (const KFileItem
&item
, items
) {
542 const KUrl
& oldUrl
= item
.url();
544 number
.setNum(index
++);
546 QString name
= newName
;
547 name
.replace('#', number
);
549 if (oldUrl
.fileName() != name
) {
550 KUrl newUrl
= oldUrl
;
551 newUrl
.setFileName(name
);
552 KonqOperations::rename(this, oldUrl
, newUrl
);
553 emit
doingOperation(KIO::FileUndoManager::Rename
);
557 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
558 Q_ASSERT(items
.count() == 1);
560 if (isColumnViewActive()) {
561 m_columnView
->editItem(items
.first());
563 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
564 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
565 itemView()->edit(proxyIndex
);
568 Q_ASSERT(items
.count() == 1);
570 RenameDialog
dialog(this, items
);
571 if (dialog
.exec() == QDialog::Rejected
) {
575 const QString
& newName
= dialog
.newName();
576 if (newName
.isEmpty()) {
577 emit
errorMessage(dialog
.errorString());
579 const KUrl
& oldUrl
= items
.first().url();
580 KUrl newUrl
= oldUrl
;
581 newUrl
.setFileName(newName
);
582 KonqOperations::rename(this, oldUrl
, newUrl
);
583 emit
doingOperation(KIO::FileUndoManager::Rename
);
588 void DolphinView::trashSelectedItems()
590 emit
doingOperation(KIO::FileUndoManager::Trash
);
591 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
594 void DolphinView::deleteSelectedItems()
596 const KUrl::List list
= selectedUrls();
597 const bool del
= KonqOperations::askDeleteConfirmation(list
,
599 KonqOperations::DEFAULT_CONFIRMATION
,
603 KIO::Job
* job
= KIO::del(list
);
604 connect(job
, SIGNAL(result(KJob
*)),
605 this, SLOT(slotDeleteFileFinished(KJob
*)));
609 void DolphinView::cutSelectedItems()
611 QMimeData
* mimeData
= new QMimeData();
612 const KUrl::List kdeUrls
= selectedUrls();
613 const KUrl::List mostLocalUrls
;
614 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
615 QApplication::clipboard()->setMimeData(mimeData
);
618 void DolphinView::copySelectedItems()
620 QMimeData
* mimeData
= new QMimeData();
621 const KUrl::List kdeUrls
= selectedUrls();
622 const KUrl::List mostLocalUrls
;
623 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
624 QApplication::clipboard()->setMimeData(mimeData
);
627 void DolphinView::paste()
632 void DolphinView::pasteIntoFolder()
634 const KFileItemList items
= selectedItems();
635 if ((items
.count() == 1) && items
.first().isDir()) {
636 pasteToUrl(items
.first().url());
640 void DolphinView::setShowPreview(bool show
)
642 if (m_showPreview
== show
) {
646 const KUrl viewPropsUrl
= viewPropertiesUrl();
647 ViewProperties
props(viewPropsUrl
);
648 props
.setShowPreview(show
);
650 m_showPreview
= show
;
651 m_iconManager
->setShowPreview(show
);
652 emit
showPreviewChanged();
654 loadDirectory(viewPropsUrl
);
657 void DolphinView::setShowHiddenFiles(bool show
)
659 if (m_dirLister
->showingDotFiles() == show
) {
663 const KUrl viewPropsUrl
= viewPropertiesUrl();
664 ViewProperties
props(viewPropsUrl
);
665 props
.setShowHiddenFiles(show
);
667 m_dirLister
->setShowingDotFiles(show
);
668 emit
showHiddenFilesChanged();
670 loadDirectory(viewPropsUrl
);
673 void DolphinView::setCategorizedSorting(bool categorized
)
675 if (categorized
== categorizedSorting()) {
679 // setCategorizedSorting(true) may only get invoked
680 // if the view supports categorized sorting
681 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
683 ViewProperties
props(viewPropertiesUrl());
684 props
.setCategorizedSorting(categorized
);
687 m_storedCategorizedSorting
= categorized
;
688 m_proxyModel
->setCategorizedModel(categorized
);
690 emit
categorizedSortingChanged();
693 void DolphinView::toggleSortOrder()
695 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
696 Qt::DescendingOrder
:
701 void DolphinView::toggleAdditionalInfo(QAction
* action
)
703 const KFileItemDelegate::Information info
=
704 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
706 KFileItemDelegate::InformationList list
= additionalInfo();
708 const bool show
= action
->isChecked();
710 const int index
= list
.indexOf(info
);
711 const bool containsInfo
= (index
>= 0);
712 if (show
&& !containsInfo
) {
714 setAdditionalInfo(list
);
715 } else if (!show
&& containsInfo
) {
716 list
.removeAt(index
);
717 setAdditionalInfo(list
);
718 Q_ASSERT(list
.indexOf(info
) < 0);
723 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
725 QWidget::mouseReleaseEvent(event
);
729 void DolphinView::wheelEvent(QWheelEvent
* event
)
731 if (event
->modifiers() & Qt::ControlModifier
) {
732 const int delta
= event
->delta();
733 if ((delta
> 0) && isZoomInPossible()) {
735 } else if ((delta
< 0) && isZoomOutPossible()) {
742 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
744 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
745 m_controller
->requestActivation();
748 return QWidget::eventFilter(watched
, event
);
751 void DolphinView::activate()
756 void DolphinView::triggerItem(const KFileItem
& item
)
758 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
759 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
760 // items are selected by the user, hence don't trigger the
761 // item specified by 'index'
765 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
766 if (item
.isNull() || m_isContextMenuOpen
) {
770 if (m_toolTipManager
!= 0) {
771 m_toolTipManager
->hideTip();
773 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
776 void DolphinView::emitSelectionChangedSignal()
778 emit
selectionChanged(DolphinView::selectedItems());
781 void DolphinView::openContextMenu(const QPoint
& pos
)
785 const QModelIndex index
= itemView()->indexAt(pos
);
786 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
787 item
= fileItem(index
);
790 if (m_toolTipManager
!= 0) {
791 m_toolTipManager
->hideTip();
794 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
795 emit
requestContextMenu(item
, url());
796 m_isContextMenuOpen
= false;
799 void DolphinView::dropUrls(const KUrl::List
& urls
,
800 const KUrl
& destPath
,
801 const KFileItem
& destItem
)
803 Q_ASSERT(!urls
.isEmpty());
804 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
805 destItem
.url() : destPath
;
806 const KUrl sourceDir
= KUrl(urls
.first().directory());
807 if (sourceDir
!= destination
) {
808 dropUrls(urls
, destination
);
812 void DolphinView::dropUrls(const KUrl::List
& urls
,
813 const KUrl
& destination
)
815 DolphinDropController
dropController(this);
816 // forward doingOperation signal up to the mainwindow
817 connect(&dropController
, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)),
818 this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)));
819 dropController
.dropUrls(urls
, destination
);
822 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
824 ViewProperties
props(viewPropertiesUrl());
825 props
.setSorting(sorting
);
827 m_proxyModel
->setSorting(sorting
);
829 emit
sortingChanged(sorting
);
832 void DolphinView::updateSortOrder(Qt::SortOrder order
)
834 ViewProperties
props(viewPropertiesUrl());
835 props
.setSortOrder(order
);
837 m_proxyModel
->setSortOrder(order
);
839 emit
sortOrderChanged(order
);
842 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
844 ViewProperties
props(viewPropertiesUrl());
845 props
.setAdditionalInfo(info
);
848 m_fileItemDelegate
->setShowInformation(info
);
850 emit
additionalInfoChanged();
853 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
855 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
856 (m_mode
== DolphinView::IconsView
);
858 QAction
* showSizeInfo
= collection
->action("show_size_info");
859 QAction
* showDateInfo
= collection
->action("show_date_info");
860 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
861 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
862 QAction
* showGroupInfo
= collection
->action("show_group_info");
863 QAction
* showMimeInfo
= collection
->action("show_mime_info");
865 showSizeInfo
->setChecked(false);
866 showDateInfo
->setChecked(false);
867 showPermissionsInfo
->setChecked(false);
868 showOwnerInfo
->setChecked(false);
869 showGroupInfo
->setChecked(false);
870 showMimeInfo
->setChecked(false);
872 showSizeInfo
->setEnabled(enable
);
873 showDateInfo
->setEnabled(enable
);
874 showPermissionsInfo
->setEnabled(enable
);
875 showOwnerInfo
->setEnabled(enable
);
876 showGroupInfo
->setEnabled(enable
);
877 showMimeInfo
->setEnabled(enable
);
879 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
881 case KFileItemDelegate::Size
:
882 showSizeInfo
->setChecked(true);
884 case KFileItemDelegate::ModificationTime
:
885 showDateInfo
->setChecked(true);
887 case KFileItemDelegate::Permissions
:
888 showPermissionsInfo
->setChecked(true);
890 case KFileItemDelegate::Owner
:
891 showOwnerInfo
->setChecked(true);
893 case KFileItemDelegate::OwnerAndGroup
:
894 showGroupInfo
->setChecked(true);
896 case KFileItemDelegate::FriendlyMimeType
:
897 showMimeInfo
->setChecked(true);
905 QPair
<bool, QString
> DolphinView::pasteInfo() const
907 QPair
<bool, QString
> ret
;
908 QClipboard
* clipboard
= QApplication::clipboard();
909 const QMimeData
* mimeData
= clipboard
->mimeData();
911 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
912 if (!urls
.isEmpty()) {
914 if (urls
.count() == 1) {
915 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
916 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
917 i18nc("@action:inmenu", "Paste One File");
920 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
924 ret
.second
= i18nc("@action:inmenu", "Paste");
930 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
932 m_tabsForFiles
= tabsForFiles
;
935 bool DolphinView::isTabsForFilesEnabled() const
937 return m_tabsForFiles
;
940 void DolphinView::emitContentsMoved()
942 // only emit the contents moved signal if:
943 // - no directory loading is ongoing (this would reset the contents position
945 // - if the Column View is active: the column view does an automatic
946 // positioning during the loading operation, which must be remembered
947 if (!m_loadingDirectory
|| isColumnViewActive()) {
948 const QPoint
pos(contentsPosition());
949 emit
contentsMoved(pos
.x(), pos
.y());
953 void DolphinView::showHoverInformation(const KFileItem
& item
)
955 emit
requestItemInfo(item
);
958 void DolphinView::clearHoverInformation()
960 emit
requestItemInfo(KFileItem());
963 void DolphinView::slotDeleteFileFinished(KJob
* job
)
965 if (job
->error() == 0) {
966 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
968 emit
errorMessage(job
->errorString());
972 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
974 if (!url
.isValid()) {
975 const QString
location(url
.pathOrUrl());
976 if (location
.isEmpty()) {
977 emit
errorMessage(i18nc("@info:status", "The location is empty."));
979 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
984 m_loadingDirectory
= true;
987 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
989 if (isColumnViewActive()) {
990 // adjusting the directory lister is not enough in the case of the
991 // column view, as each column has its own directory lister internally...
993 m_columnView
->reload();
995 m_columnView
->showColumn(url
);
1000 KUrl
DolphinView::viewPropertiesUrl() const
1002 if (isColumnViewActive()) {
1003 return m_columnView
->rootUrl();
1009 void DolphinView::applyViewProperties(const KUrl
& url
)
1011 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1012 // The column view is active, hence don't apply the view properties
1013 // of sub directories (represented by columns) to the view. The
1014 // view always represents the properties of the first column.
1018 const ViewProperties
props(url
);
1020 const Mode mode
= props
.viewMode();
1021 if (m_mode
!= mode
) {
1026 if (itemView() == 0) {
1029 Q_ASSERT(itemView() != 0);
1030 Q_ASSERT(m_fileItemDelegate
!= 0);
1032 const bool showHiddenFiles
= props
.showHiddenFiles();
1033 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1034 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1035 emit
showHiddenFilesChanged();
1038 m_storedCategorizedSorting
= props
.categorizedSorting();
1039 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1040 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1041 m_proxyModel
->setCategorizedModel(categorized
);
1042 emit
categorizedSortingChanged();
1045 const DolphinView::Sorting sorting
= props
.sorting();
1046 if (sorting
!= m_proxyModel
->sorting()) {
1047 m_proxyModel
->setSorting(sorting
);
1048 emit
sortingChanged(sorting
);
1051 const Qt::SortOrder sortOrder
= props
.sortOrder();
1052 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1053 m_proxyModel
->setSortOrder(sortOrder
);
1054 emit
sortOrderChanged(sortOrder
);
1057 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1058 if (info
!= m_fileItemDelegate
->showInformation()) {
1059 m_fileItemDelegate
->setShowInformation(info
);
1060 emit
additionalInfoChanged();
1063 const bool showPreview
= props
.showPreview();
1064 if (showPreview
!= m_showPreview
) {
1065 m_showPreview
= showPreview
;
1066 m_iconManager
->setShowPreview(showPreview
);
1067 emit
showPreviewChanged();
1071 void DolphinView::createView()
1074 Q_ASSERT(m_iconsView
== 0);
1075 Q_ASSERT(m_detailsView
== 0);
1076 Q_ASSERT(m_columnView
== 0);
1078 QAbstractItemView
* view
= 0;
1081 m_iconsView
= new DolphinIconsView(this, m_controller
);
1087 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1088 view
= m_detailsView
;
1092 m_columnView
= new DolphinColumnView(this, m_controller
);
1093 view
= m_columnView
;
1097 Q_ASSERT(view
!= 0);
1098 view
->installEventFilter(this);
1100 m_controller
->setItemView(view
);
1102 m_fileItemDelegate
= new KFileItemDelegate(view
);
1103 view
->setItemDelegate(m_fileItemDelegate
);
1105 view
->setModel(m_proxyModel
);
1106 if (m_selectionModel
!= 0) {
1107 view
->setSelectionModel(m_selectionModel
);
1109 m_selectionModel
= view
->selectionModel();
1112 // reparent the selection model, as it should not be deleted
1113 // when deleting the model
1114 m_selectionModel
->setParent(this);
1116 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1118 new KMimeTypeResolver(view
, m_dolphinModel
);
1119 m_iconManager
= new IconManager(view
, m_proxyModel
);
1120 m_iconManager
->setShowPreview(m_showPreview
);
1122 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1123 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1126 m_topLayout
->insertWidget(1, view
);
1128 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1129 this, SLOT(emitSelectionChangedSignal()));
1130 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1131 this, SLOT(emitContentsMoved()));
1132 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1133 this, SLOT(emitContentsMoved()));
1136 void DolphinView::deleteView()
1138 QAbstractItemView
* view
= itemView();
1140 m_topLayout
->removeWidget(view
);
1142 view
->deleteLater();
1147 m_fileItemDelegate
= 0;
1149 m_toolTipManager
= 0;
1153 QAbstractItemView
* DolphinView::itemView() const
1155 if (m_detailsView
!= 0) {
1156 return m_detailsView
;
1157 } else if (m_columnView
!= 0) {
1158 return m_columnView
;
1164 bool DolphinView::isCutItem(const KFileItem
& item
) const
1166 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1167 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1169 const KUrl
& itemUrl
= item
.url();
1170 KUrl::List::const_iterator it
= cutUrls
.begin();
1171 const KUrl::List::const_iterator end
= cutUrls
.end();
1173 if (*it
== itemUrl
) {
1182 void DolphinView::pasteToUrl(const KUrl
& url
)
1184 QClipboard
* clipboard
= QApplication::clipboard();
1185 const QMimeData
* mimeData
= clipboard
->mimeData();
1187 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1188 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1189 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1190 emit
doingOperation(KIO::FileUndoManager::Move
);
1193 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1194 emit
doingOperation(KIO::FileUndoManager::Copy
);
1198 #include "dolphinview.moc"