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_isContextMenuOpen(false),
74 m_mode(DolphinView::IconsView
),
80 m_fileItemDelegate(0),
82 m_dolphinModel(dolphinModel
),
83 m_dirLister(dirLister
),
84 m_proxyModel(proxyModel
),
88 setFocusPolicy(Qt::StrongFocus
);
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(activated()),
118 this, SLOT(activate()));
119 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
120 this, SLOT(showHoverInformation(const KFileItem
&)));
121 connect(m_controller
, SIGNAL(viewportEntered()),
122 this, SLOT(clearHoverInformation()));
124 applyViewProperties(url
);
125 m_topLayout
->addWidget(itemView());
128 DolphinView::~DolphinView()
132 const KUrl
& DolphinView::url() const
134 return m_controller
->url();
137 KUrl
DolphinView::rootUrl() const
139 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
142 void DolphinView::setActive(bool active
)
144 if (active
== m_active
) {
149 m_selectionModel
->clearSelection();
151 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
153 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
154 // bypasses the problem when having a split view and changing the active view to
155 // update the some URL dependent states. A nicer approach should be no big deal...
156 emit
urlChanged(url());
157 emit
selectionChanged(selectedItems());
162 QWidget
* viewport
= itemView()->viewport();
164 palette
.setColor(viewport
->backgroundRole(), color
);
165 viewport
->setPalette(palette
);
173 m_controller
->indicateActivationChange(active
);
176 bool DolphinView::isActive() const
181 void DolphinView::setMode(Mode mode
)
183 if (mode
== m_mode
) {
184 return; // the wished mode is already set
191 const KUrl viewPropsUrl
= viewPropertiesUrl();
192 ViewProperties
props(viewPropsUrl
);
193 props
.setViewMode(m_mode
);
196 // the file item delegate has been recreated, apply the current
197 // additional information manually
198 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
199 m_fileItemDelegate
->setShowInformation(infoList
);
200 emit
additionalInfoChanged();
202 // Not all view modes support categorized sorting. Adjust the sorting model
203 // if changing the view mode results in a change of the categorized sorting
205 m_storedCategorizedSorting
= props
.categorizedSorting();
206 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
207 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
208 m_proxyModel
->setCategorizedModel(categorized
);
209 emit
categorizedSortingChanged();
215 DolphinView::Mode
DolphinView::mode() const
220 bool DolphinView::showPreview() const
222 return m_showPreview
;
225 bool DolphinView::showHiddenFiles() const
227 return m_dirLister
->showingDotFiles();
230 bool DolphinView::categorizedSorting() const
232 // If all view modes would support categorized sorting, returning
233 // m_proxyModel->isCategorizedModel() would be the way to go. As
234 // currently only the icons view supports caterized sorting, we remember
235 // the stored view properties state in m_storedCategorizedSorting and
236 // return this state. The application takes care to disable the corresponding
237 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
238 // that this setting is not applied to the current view mode.
239 return m_storedCategorizedSorting
;
242 bool DolphinView::supportsCategorizedSorting() const
244 return m_iconsView
!= 0;
247 void DolphinView::selectAll()
249 QAbstractItemView
* view
= itemView();
250 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
251 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
252 // selection instead of selecting all items. This is bypassed for KDE 4.0
253 // by invoking clearSelection() first.
254 view
->clearSelection();
258 void DolphinView::invertSelection()
260 if (isColumnViewActive()) {
261 // QAbstractItemView does not offer a virtual method invertSelection()
262 // as counterpart to QAbstractItemView::selectAll(). This makes it
263 // necessary to delegate the inverting of the selection to the
264 // column view, as only the selection of the active column should
266 m_columnView
->invertSelection();
268 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
269 const QAbstractItemModel
* itemModel
= selectionModel
->model();
271 const QModelIndex topLeft
= itemModel
->index(0, 0);
272 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
273 itemModel
->columnCount() - 1);
275 const QItemSelection
selection(topLeft
, bottomRight
);
276 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
280 bool DolphinView::hasSelection() const
282 return itemView()->selectionModel()->hasSelection();
285 void DolphinView::clearSelection()
287 itemView()->selectionModel()->clear();
290 KFileItemList
DolphinView::selectedItems() const
292 const QAbstractItemView
* view
= itemView();
294 // Our view has a selection, we will map them back to the DolphinModel
295 // and then fill the KFileItemList.
296 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
298 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
299 KFileItemList itemList
;
301 const QModelIndexList indexList
= selection
.indexes();
302 foreach (QModelIndex index
, indexList
) {
303 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
304 if (!item
.isNull()) {
305 itemList
.append(item
);
312 KUrl::List
DolphinView::selectedUrls() const
315 const KFileItemList list
= selectedItems();
316 foreach (KFileItem item
, list
) {
317 urls
.append(item
.url());
322 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
324 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
325 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
328 void DolphinView::setContentsPosition(int x
, int y
)
330 QAbstractItemView
* view
= itemView();
332 // the ColumnView takes care itself for the horizontal scrolling
333 if (!isColumnViewActive()) {
334 view
->horizontalScrollBar()->setValue(x
);
336 view
->verticalScrollBar()->setValue(y
);
338 m_loadingDirectory
= false;
341 QPoint
DolphinView::contentsPosition() const
343 const int x
= itemView()->horizontalScrollBar()->value();
344 const int y
= itemView()->verticalScrollBar()->value();
348 void DolphinView::zoomIn()
350 m_controller
->triggerZoomIn();
351 m_iconManager
->updatePreviews();
354 void DolphinView::zoomOut()
356 m_controller
->triggerZoomOut();
357 m_iconManager
->updatePreviews();
360 bool DolphinView::isZoomInPossible() const
362 return m_controller
->isZoomInPossible();
365 bool DolphinView::isZoomOutPossible() const
367 return m_controller
->isZoomOutPossible();
370 void DolphinView::setSorting(Sorting sorting
)
372 if (sorting
!= this->sorting()) {
373 updateSorting(sorting
);
377 DolphinView::Sorting
DolphinView::sorting() const
379 return m_proxyModel
->sorting();
382 void DolphinView::setSortOrder(Qt::SortOrder order
)
384 if (sortOrder() != order
) {
385 updateSortOrder(order
);
389 Qt::SortOrder
DolphinView::sortOrder() const
391 return m_proxyModel
->sortOrder();
394 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
396 const KUrl viewPropsUrl
= viewPropertiesUrl();
397 ViewProperties
props(viewPropsUrl
);
398 props
.setAdditionalInfo(info
);
399 m_fileItemDelegate
->setShowInformation(info
);
401 emit
additionalInfoChanged();
403 if (itemView() != m_detailsView
) {
404 // the details view requires no reloading of the directory, as it maps
405 // the file item delegate info to its columns internally
406 loadDirectory(viewPropsUrl
);
410 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
412 return m_fileItemDelegate
->showInformation();
415 void DolphinView::reload()
418 loadDirectory(url(), true);
421 void DolphinView::refresh()
423 const bool oldActivationState
= m_active
;
427 applyViewProperties(m_controller
->url());
430 setActive(oldActivationState
);
433 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
435 if (m_controller
->url() == url
) {
439 m_controller
->setUrl(url
); // emits urlChanged, which we forward
441 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
442 applyViewProperties(rootUrl
);
443 loadDirectory(rootUrl
);
444 if (itemView() == m_columnView
) {
445 m_columnView
->setRootUrl(rootUrl
);
446 m_columnView
->showColumn(url
);
449 applyViewProperties(url
);
453 emit
startedPathLoading(url
);
456 void DolphinView::setNameFilter(const QString
& nameFilter
)
458 m_proxyModel
->setFilterRegExp(nameFilter
);
460 if (isColumnViewActive()) {
461 // adjusting the directory lister is not enough in the case of the
462 // column view, as each column has its own directory lister internally...
463 m_columnView
->setNameFilter(nameFilter
);
467 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
469 foreach (KFileItem item
, m_dirLister
->items()) {
478 void DolphinView::setUrl(const KUrl
& url
)
480 updateView(url
, KUrl());
483 void DolphinView::changeSelection(const KFileItemList
& selection
)
486 if (selection
.isEmpty()) {
489 const KUrl
& baseUrl
= url();
491 QItemSelection new_selection
;
492 foreach(const KFileItem
& item
, selection
) {
493 url
= item
.url().upUrl();
494 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
495 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
496 new_selection
.select(index
, index
);
499 itemView()->selectionModel()->select(new_selection
,
500 QItemSelectionModel::ClearAndSelect
501 | QItemSelectionModel::Current
);
504 void DolphinView::renameSelectedItems()
506 const KFileItemList items
= selectedItems();
507 if (items
.count() > 1) {
508 // More than one item has been selected for renaming. Open
509 // a rename dialog and rename all items afterwards.
510 RenameDialog
dialog(this, items
);
511 if (dialog
.exec() == QDialog::Rejected
) {
515 const QString newName
= dialog
.newName();
516 if (newName
.isEmpty()) {
517 emit
errorMessage(dialog
.errorString());
519 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
520 // as one operation instead of n rename operations like it is done now...
521 Q_ASSERT(newName
.contains('#'));
523 // iterate through all selected items and rename them...
525 foreach (KFileItem item
, items
) {
526 const KUrl
& oldUrl
= item
.url();
528 number
.setNum(index
++);
530 QString name
= newName
;
531 name
.replace('#', number
);
533 if (oldUrl
.fileName() != name
) {
534 KUrl newUrl
= oldUrl
;
535 newUrl
.setFileName(name
);
536 KonqOperations::rename(this, oldUrl
, newUrl
);
537 emit
doingOperation(KonqFileUndoManager::RENAME
);
541 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
542 Q_ASSERT(items
.count() == 1);
544 if (isColumnViewActive()) {
545 m_columnView
->editItem(items
.first());
547 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
548 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
549 itemView()->edit(proxyIndex
);
552 Q_ASSERT(items
.count() == 1);
554 RenameDialog
dialog(this, items
);
555 if (dialog
.exec() == QDialog::Rejected
) {
559 const QString
& newName
= dialog
.newName();
560 if (newName
.isEmpty()) {
561 emit
errorMessage(dialog
.errorString());
563 const KUrl
& oldUrl
= items
.first().url();
564 KUrl newUrl
= oldUrl
;
565 newUrl
.setFileName(newName
);
566 KonqOperations::rename(this, oldUrl
, newUrl
);
567 emit
doingOperation(KonqFileUndoManager::RENAME
);
572 void DolphinView::trashSelectedItems()
574 emit
doingOperation(KonqFileUndoManager::TRASH
);
575 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
578 void DolphinView::deleteSelectedItems()
580 const KUrl::List list
= selectedUrls();
581 const bool del
= KonqOperations::askDeleteConfirmation(list
,
583 KonqOperations::DEFAULT_CONFIRMATION
,
587 KIO::Job
* job
= KIO::del(list
);
588 connect(job
, SIGNAL(result(KJob
*)),
589 this, SLOT(slotDeleteFileFinished(KJob
*)));
593 void DolphinView::cutSelectedItems()
595 QMimeData
* mimeData
= new QMimeData();
596 const KUrl::List kdeUrls
= selectedUrls();
597 const KUrl::List mostLocalUrls
;
598 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
599 QApplication::clipboard()->setMimeData(mimeData
);
602 void DolphinView::copySelectedItems()
604 QMimeData
* mimeData
= new QMimeData();
605 const KUrl::List kdeUrls
= selectedUrls();
606 const KUrl::List mostLocalUrls
;
607 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
608 QApplication::clipboard()->setMimeData(mimeData
);
611 void DolphinView::paste()
616 void DolphinView::pasteIntoFolder()
618 const KFileItemList items
= selectedItems();
619 if ((items
.count() == 1) && items
.first().isDir()) {
620 pasteToUrl(items
.first().url());
624 void DolphinView::setShowPreview(bool show
)
626 if (m_showPreview
== show
) {
630 const KUrl viewPropsUrl
= viewPropertiesUrl();
631 ViewProperties
props(viewPropsUrl
);
632 props
.setShowPreview(show
);
634 m_showPreview
= show
;
635 m_iconManager
->setShowPreview(show
);
636 emit
showPreviewChanged();
638 loadDirectory(viewPropsUrl
);
641 void DolphinView::setShowHiddenFiles(bool show
)
643 if (m_dirLister
->showingDotFiles() == show
) {
647 const KUrl viewPropsUrl
= viewPropertiesUrl();
648 ViewProperties
props(viewPropsUrl
);
649 props
.setShowHiddenFiles(show
);
651 m_dirLister
->setShowingDotFiles(show
);
652 emit
showHiddenFilesChanged();
654 loadDirectory(viewPropsUrl
);
657 void DolphinView::setCategorizedSorting(bool categorized
)
659 if (categorized
== categorizedSorting()) {
663 // setCategorizedSorting(true) may only get invoked
664 // if the view supports categorized sorting
665 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
667 ViewProperties
props(viewPropertiesUrl());
668 props
.setCategorizedSorting(categorized
);
671 m_storedCategorizedSorting
= categorized
;
672 m_proxyModel
->setCategorizedModel(categorized
);
674 emit
categorizedSortingChanged();
677 void DolphinView::toggleSortOrder()
679 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
680 Qt::DescendingOrder
:
685 void DolphinView::toggleAdditionalInfo(QAction
* action
)
687 const KFileItemDelegate::Information info
=
688 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
690 KFileItemDelegate::InformationList list
= additionalInfo();
692 const bool show
= action
->isChecked();
694 const int index
= list
.indexOf(info
);
695 const bool containsInfo
= (index
>= 0);
696 if (show
&& !containsInfo
) {
698 setAdditionalInfo(list
);
699 } else if (!show
&& containsInfo
) {
700 list
.removeAt(index
);
701 setAdditionalInfo(list
);
702 Q_ASSERT(list
.indexOf(info
) < 0);
707 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
709 QWidget::mouseReleaseEvent(event
);
713 void DolphinView::wheelEvent(QWheelEvent
* event
)
715 if (event
->modifiers() & Qt::ControlModifier
) {
716 const int delta
= event
->delta();
717 if ((delta
> 0) && isZoomInPossible()) {
719 } else if ((delta
< 0) && isZoomOutPossible()) {
726 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
728 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
729 m_controller
->requestActivation();
732 return QWidget::eventFilter(watched
, event
);
735 void DolphinView::activate()
740 void DolphinView::triggerItem(const KFileItem
& item
)
742 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
743 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
744 // items are selected by the user, hence don't trigger the
745 // item specified by 'index'
749 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue xxxxxx
750 if (item
.isNull() || m_isContextMenuOpen
) {
754 if (m_toolTipManager
!= 0) {
755 m_toolTipManager
->hideTip();
757 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
760 void DolphinView::emitSelectionChangedSignal()
762 emit
selectionChanged(DolphinView::selectedItems());
765 void DolphinView::openContextMenu(const QPoint
& pos
)
769 const QModelIndex index
= itemView()->indexAt(pos
);
770 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
771 item
= fileItem(index
);
774 if (m_toolTipManager
!= 0) {
775 m_toolTipManager
->hideTip();
778 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue xxxxxx
779 emit
requestContextMenu(item
, url());
780 m_isContextMenuOpen
= false;
783 void DolphinView::dropUrls(const KUrl::List
& urls
,
784 const KUrl
& destPath
,
785 const KFileItem
& destItem
)
787 Q_ASSERT(!urls
.isEmpty());
788 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
789 destItem
.url() : destPath
;
790 const KUrl sourceDir
= KUrl(urls
.first().directory());
791 if (sourceDir
!= destination
) {
792 dropUrls(urls
, destination
);
796 void DolphinView::dropUrls(const KUrl::List
& urls
,
797 const KUrl
& destination
)
799 DolphinDropController
dropController(this);
800 // forward doingOperation signal up to the mainwindow
801 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
802 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
803 dropController
.dropUrls(urls
, destination
);
806 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
808 ViewProperties
props(viewPropertiesUrl());
809 props
.setSorting(sorting
);
811 m_proxyModel
->setSorting(sorting
);
813 emit
sortingChanged(sorting
);
816 void DolphinView::updateSortOrder(Qt::SortOrder order
)
818 ViewProperties
props(viewPropertiesUrl());
819 props
.setSortOrder(order
);
821 m_proxyModel
->setSortOrder(order
);
823 emit
sortOrderChanged(order
);
826 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
828 ViewProperties
props(viewPropertiesUrl());
829 props
.setAdditionalInfo(info
);
832 m_fileItemDelegate
->setShowInformation(info
);
834 emit
additionalInfoChanged();
837 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
839 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
840 (m_mode
== DolphinView::IconsView
);
842 QAction
* showSizeInfo
= collection
->action("show_size_info");
843 QAction
* showDateInfo
= collection
->action("show_date_info");
844 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
845 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
846 QAction
* showGroupInfo
= collection
->action("show_group_info");
847 QAction
* showMimeInfo
= collection
->action("show_mime_info");
849 showSizeInfo
->setChecked(false);
850 showDateInfo
->setChecked(false);
851 showPermissionsInfo
->setChecked(false);
852 showOwnerInfo
->setChecked(false);
853 showGroupInfo
->setChecked(false);
854 showMimeInfo
->setChecked(false);
856 showSizeInfo
->setEnabled(enable
);
857 showDateInfo
->setEnabled(enable
);
858 showPermissionsInfo
->setEnabled(enable
);
859 showOwnerInfo
->setEnabled(enable
);
860 showGroupInfo
->setEnabled(enable
);
861 showMimeInfo
->setEnabled(enable
);
863 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
865 case KFileItemDelegate::Size
:
866 showSizeInfo
->setChecked(true);
868 case KFileItemDelegate::ModificationTime
:
869 showDateInfo
->setChecked(true);
871 case KFileItemDelegate::Permissions
:
872 showPermissionsInfo
->setChecked(true);
874 case KFileItemDelegate::Owner
:
875 showOwnerInfo
->setChecked(true);
877 case KFileItemDelegate::OwnerAndGroup
:
878 showGroupInfo
->setChecked(true);
880 case KFileItemDelegate::FriendlyMimeType
:
881 showMimeInfo
->setChecked(true);
889 QPair
<bool, QString
> DolphinView::pasteInfo() const
891 QPair
<bool, QString
> ret
;
892 QClipboard
* clipboard
= QApplication::clipboard();
893 const QMimeData
* mimeData
= clipboard
->mimeData();
895 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
896 if (!urls
.isEmpty()) {
898 if (urls
.count() == 1) {
899 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
900 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
901 i18nc("@action:inmenu", "Paste One File");
904 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
908 ret
.second
= i18nc("@action:inmenu", "Paste");
914 void DolphinView::emitContentsMoved()
916 // only emit the contents moved signal if:
917 // - no directory loading is ongoing (this would reset the contents position
919 // - if the Column View is active: the column view does an automatic
920 // positioning during the loading operation, which must be remembered
921 if (!m_loadingDirectory
|| isColumnViewActive()) {
922 const QPoint
pos(contentsPosition());
923 emit
contentsMoved(pos
.x(), pos
.y());
927 void DolphinView::showHoverInformation(const KFileItem
& item
)
929 emit
requestItemInfo(item
);
932 void DolphinView::clearHoverInformation()
934 emit
requestItemInfo(KFileItem());
937 void DolphinView::slotDeleteFileFinished(KJob
* job
)
939 if (job
->error() == 0) {
940 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
942 emit
errorMessage(job
->errorString());
946 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
948 if (!url
.isValid()) {
949 const QString
location(url
.pathOrUrl());
950 if (location
.isEmpty()) {
951 emit
errorMessage(i18nc("@info:status", "The location is empty."));
953 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
958 m_loadingDirectory
= true;
961 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
963 if (isColumnViewActive()) {
964 // adjusting the directory lister is not enough in the case of the
965 // column view, as each column has its own directory lister internally...
967 m_columnView
->reload();
969 m_columnView
->showColumn(url
);
974 KUrl
DolphinView::viewPropertiesUrl() const
976 if (isColumnViewActive()) {
977 return m_columnView
->rootUrl();
983 void DolphinView::applyViewProperties(const KUrl
& url
)
985 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
986 // The column view is active, hence don't apply the view properties
987 // of sub directories (represented by columns) to the view. The
988 // view always represents the properties of the first column.
992 const ViewProperties
props(url
);
994 const Mode mode
= props
.viewMode();
995 if (m_mode
!= mode
) {
1000 if (itemView() == 0) {
1003 Q_ASSERT(itemView() != 0);
1004 Q_ASSERT(m_fileItemDelegate
!= 0);
1006 const bool showHiddenFiles
= props
.showHiddenFiles();
1007 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1008 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1009 emit
showHiddenFilesChanged();
1012 m_storedCategorizedSorting
= props
.categorizedSorting();
1013 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1014 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1015 m_proxyModel
->setCategorizedModel(categorized
);
1016 emit
categorizedSortingChanged();
1019 const DolphinView::Sorting sorting
= props
.sorting();
1020 if (sorting
!= m_proxyModel
->sorting()) {
1021 m_proxyModel
->setSorting(sorting
);
1022 emit
sortingChanged(sorting
);
1025 const Qt::SortOrder sortOrder
= props
.sortOrder();
1026 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1027 m_proxyModel
->setSortOrder(sortOrder
);
1028 emit
sortOrderChanged(sortOrder
);
1031 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1032 if (info
!= m_fileItemDelegate
->showInformation()) {
1033 m_fileItemDelegate
->setShowInformation(info
);
1034 emit
additionalInfoChanged();
1037 const bool showPreview
= props
.showPreview();
1038 if (showPreview
!= m_showPreview
) {
1039 m_showPreview
= showPreview
;
1040 m_iconManager
->setShowPreview(showPreview
);
1041 emit
showPreviewChanged();
1045 void DolphinView::createView()
1048 Q_ASSERT(m_iconsView
== 0);
1049 Q_ASSERT(m_detailsView
== 0);
1050 Q_ASSERT(m_columnView
== 0);
1052 QAbstractItemView
* view
= 0;
1055 m_iconsView
= new DolphinIconsView(this, m_controller
);
1061 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1062 view
= m_detailsView
;
1066 m_columnView
= new DolphinColumnView(this, m_controller
);
1067 view
= m_columnView
;
1071 Q_ASSERT(view
!= 0);
1072 view
->installEventFilter(this);
1074 m_controller
->setItemView(view
);
1076 m_fileItemDelegate
= new KFileItemDelegate(view
);
1077 view
->setItemDelegate(m_fileItemDelegate
);
1079 view
->setModel(m_proxyModel
);
1080 if (m_selectionModel
!= 0) {
1081 view
->setSelectionModel(m_selectionModel
);
1083 m_selectionModel
= view
->selectionModel();
1086 // reparent the selection model, as it should not be deleted
1087 // when deleting the model
1088 m_selectionModel
->setParent(this);
1090 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1092 new KMimeTypeResolver(view
, m_dolphinModel
);
1093 m_iconManager
= new IconManager(view
, m_proxyModel
);
1094 m_iconManager
->setShowPreview(m_showPreview
);
1096 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1097 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1100 m_topLayout
->insertWidget(1, view
);
1102 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1103 this, SLOT(emitSelectionChangedSignal()));
1104 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1105 this, SLOT(emitContentsMoved()));
1106 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1107 this, SLOT(emitContentsMoved()));
1110 void DolphinView::deleteView()
1112 QAbstractItemView
* view
= itemView();
1114 m_topLayout
->removeWidget(view
);
1116 view
->deleteLater();
1121 m_fileItemDelegate
= 0;
1123 m_toolTipManager
= 0;
1127 QAbstractItemView
* DolphinView::itemView() const
1129 if (m_detailsView
!= 0) {
1130 return m_detailsView
;
1131 } else if (m_columnView
!= 0) {
1132 return m_columnView
;
1138 bool DolphinView::isCutItem(const KFileItem
& item
) const
1140 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1141 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1143 const KUrl
& itemUrl
= item
.url();
1144 KUrl::List::const_iterator it
= cutUrls
.begin();
1145 const KUrl::List::const_iterator end
= cutUrls
.end();
1147 if (*it
== itemUrl
) {
1156 void DolphinView::pasteToUrl(const KUrl
& url
)
1158 QClipboard
* clipboard
= QApplication::clipboard();
1159 const QMimeData
* mimeData
= clipboard
->mimeData();
1161 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1162 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1163 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1164 emit
doingOperation(KonqFileUndoManager::MOVE
);
1167 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1168 emit
doingOperation(KonqFileUndoManager::COPY
);
1172 #include "dolphinview.moc"