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
),
87 setFocusPolicy(Qt::StrongFocus
);
88 m_topLayout
= new QVBoxLayout(this);
89 m_topLayout
->setSpacing(0);
90 m_topLayout
->setMargin(0);
92 m_controller
= new DolphinController(this);
93 m_controller
->setUrl(url
);
95 // Receiver of the DolphinView signal 'urlChanged()' don't need
96 // to care whether the internal controller changed the URL already or whether
97 // the controller just requested an URL change and will be updated later.
98 // In both cases the URL has been changed:
99 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
100 this, SIGNAL(urlChanged(const KUrl
&)));
101 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
102 this, SIGNAL(urlChanged(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(activated()),
117 this, SLOT(activate()));
118 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
119 this, SLOT(showHoverInformation(const KFileItem
&)));
120 connect(m_controller
, SIGNAL(viewportEntered()),
121 this, SLOT(clearHoverInformation()));
123 applyViewProperties(url
);
124 m_topLayout
->addWidget(itemView());
127 DolphinView::~DolphinView()
131 const KUrl
& DolphinView::url() const
133 return m_controller
->url();
136 KUrl
DolphinView::rootUrl() const
138 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
141 void DolphinView::setActive(bool active
)
143 if (active
== m_active
) {
148 m_selectionModel
->clearSelection();
150 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
152 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
153 // bypasses the problem when having a split view and changing the active view to
154 // update the some URL dependent states. A nicer approach should be no big deal...
155 emit
urlChanged(url());
156 emit
selectionChanged(selectedItems());
161 QWidget
* viewport
= itemView()->viewport();
163 palette
.setColor(viewport
->backgroundRole(), color
);
164 viewport
->setPalette(palette
);
172 m_controller
->indicateActivationChange(active
);
175 bool DolphinView::isActive() const
180 void DolphinView::setMode(Mode mode
)
182 if (mode
== m_mode
) {
183 return; // the wished mode is already set
190 const KUrl viewPropsUrl
= viewPropertiesUrl();
191 ViewProperties
props(viewPropsUrl
);
192 props
.setViewMode(m_mode
);
195 // the file item delegate has been recreated, apply the current
196 // additional information manually
197 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
198 m_fileItemDelegate
->setShowInformation(infoList
);
199 emit
additionalInfoChanged();
201 // Not all view modes support categorized sorting. Adjust the sorting model
202 // if changing the view mode results in a change of the categorized sorting
204 m_storedCategorizedSorting
= props
.categorizedSorting();
205 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
206 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
207 m_proxyModel
->setCategorizedModel(categorized
);
208 emit
categorizedSortingChanged();
214 DolphinView::Mode
DolphinView::mode() const
219 bool DolphinView::showPreview() const
221 return m_showPreview
;
224 bool DolphinView::showHiddenFiles() const
226 return m_dirLister
->showingDotFiles();
229 bool DolphinView::categorizedSorting() const
231 // If all view modes would support categorized sorting, returning
232 // m_proxyModel->isCategorizedModel() would be the way to go. As
233 // currently only the icons view supports caterized sorting, we remember
234 // the stored view properties state in m_storedCategorizedSorting and
235 // return this state. The application takes care to disable the corresponding
236 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
237 // that this setting is not applied to the current view mode.
238 return m_storedCategorizedSorting
;
241 bool DolphinView::supportsCategorizedSorting() const
243 return m_iconsView
!= 0;
246 void DolphinView::selectAll()
248 QAbstractItemView
* view
= itemView();
249 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
250 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
251 // selection instead of selecting all items. This is bypassed for KDE 4.0
252 // by invoking clearSelection() first.
253 view
->clearSelection();
257 void DolphinView::invertSelection()
259 if (isColumnViewActive()) {
260 // QAbstractItemView does not offer a virtual method invertSelection()
261 // as counterpart to QAbstractItemView::selectAll(). This makes it
262 // necessary to delegate the inverting of the selection to the
263 // column view, as only the selection of the active column should
265 m_columnView
->invertSelection();
267 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
268 const QAbstractItemModel
* itemModel
= selectionModel
->model();
270 const QModelIndex topLeft
= itemModel
->index(0, 0);
271 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
272 itemModel
->columnCount() - 1);
274 const QItemSelection
selection(topLeft
, bottomRight
);
275 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
279 bool DolphinView::hasSelection() const
281 return itemView()->selectionModel()->hasSelection();
284 void DolphinView::clearSelection()
286 itemView()->selectionModel()->clear();
289 KFileItemList
DolphinView::selectedItems() const
291 const QAbstractItemView
* view
= itemView();
293 // Our view has a selection, we will map them back to the DolphinModel
294 // and then fill the KFileItemList.
295 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
297 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
298 KFileItemList itemList
;
300 const QModelIndexList indexList
= selection
.indexes();
301 foreach (QModelIndex index
, indexList
) {
302 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
303 if (!item
.isNull()) {
304 itemList
.append(item
);
311 KUrl::List
DolphinView::selectedUrls() const
314 const KFileItemList list
= selectedItems();
315 foreach (KFileItem item
, list
) {
316 urls
.append(item
.url());
321 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
323 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
324 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
327 void DolphinView::setContentsPosition(int x
, int y
)
329 QAbstractItemView
* view
= itemView();
331 // the ColumnView takes care itself for the horizontal scrolling
332 if (!isColumnViewActive()) {
333 view
->horizontalScrollBar()->setValue(x
);
335 view
->verticalScrollBar()->setValue(y
);
337 m_loadingDirectory
= false;
340 QPoint
DolphinView::contentsPosition() const
342 const int x
= itemView()->horizontalScrollBar()->value();
343 const int y
= itemView()->verticalScrollBar()->value();
347 void DolphinView::zoomIn()
349 m_controller
->triggerZoomIn();
350 m_iconManager
->updatePreviews();
353 void DolphinView::zoomOut()
355 m_controller
->triggerZoomOut();
356 m_iconManager
->updatePreviews();
359 bool DolphinView::isZoomInPossible() const
361 return m_controller
->isZoomInPossible();
364 bool DolphinView::isZoomOutPossible() const
366 return m_controller
->isZoomOutPossible();
369 void DolphinView::setSorting(Sorting sorting
)
371 if (sorting
!= this->sorting()) {
372 updateSorting(sorting
);
376 DolphinView::Sorting
DolphinView::sorting() const
378 return m_proxyModel
->sorting();
381 void DolphinView::setSortOrder(Qt::SortOrder order
)
383 if (sortOrder() != order
) {
384 updateSortOrder(order
);
388 Qt::SortOrder
DolphinView::sortOrder() const
390 return m_proxyModel
->sortOrder();
393 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
395 const KUrl viewPropsUrl
= viewPropertiesUrl();
396 ViewProperties
props(viewPropsUrl
);
397 props
.setAdditionalInfo(info
);
398 m_fileItemDelegate
->setShowInformation(info
);
400 emit
additionalInfoChanged();
402 if (itemView() != m_detailsView
) {
403 // the details view requires no reloading of the directory, as it maps
404 // the file item delegate info to its columns internally
405 loadDirectory(viewPropsUrl
);
409 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
411 return m_fileItemDelegate
->showInformation();
414 void DolphinView::reload()
417 loadDirectory(url(), true);
420 void DolphinView::refresh()
422 const bool oldActivationState
= m_active
;
426 applyViewProperties(m_controller
->url());
429 setActive(oldActivationState
);
432 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
434 if (m_controller
->url() == url
) {
438 m_controller
->setUrl(url
); // emits urlChanged, which we forward
440 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
441 applyViewProperties(rootUrl
);
442 loadDirectory(rootUrl
);
443 if (itemView() == m_columnView
) {
444 m_columnView
->setRootUrl(rootUrl
);
445 m_columnView
->showColumn(url
);
448 applyViewProperties(url
);
452 emit
startedPathLoading(url
);
455 void DolphinView::setNameFilter(const QString
& nameFilter
)
457 m_proxyModel
->setFilterRegExp(nameFilter
);
459 if (isColumnViewActive()) {
460 // adjusting the directory lister is not enough in the case of the
461 // column view, as each column has its own directory lister internally...
462 m_columnView
->setNameFilter(nameFilter
);
466 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
468 foreach (KFileItem item
, m_dirLister
->items()) {
477 void DolphinView::setUrl(const KUrl
& url
)
479 updateView(url
, KUrl());
482 void DolphinView::changeSelection(const KFileItemList
& selection
)
485 if (selection
.isEmpty()) {
488 const KUrl
& baseUrl
= url();
490 QItemSelection new_selection
;
491 foreach(const KFileItem
& item
, selection
) {
492 url
= item
.url().upUrl();
493 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
494 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
495 new_selection
.select(index
, index
);
498 itemView()->selectionModel()->select(new_selection
,
499 QItemSelectionModel::ClearAndSelect
500 | QItemSelectionModel::Current
);
503 void DolphinView::renameSelectedItems()
505 const KFileItemList items
= selectedItems();
506 if (items
.count() > 1) {
507 // More than one item has been selected for renaming. Open
508 // a rename dialog and rename all items afterwards.
509 RenameDialog
dialog(this, items
);
510 if (dialog
.exec() == QDialog::Rejected
) {
514 const QString newName
= dialog
.newName();
515 if (newName
.isEmpty()) {
516 emit
errorMessage(dialog
.errorString());
518 // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
519 // as one operation instead of n rename operations like it is done now...
520 Q_ASSERT(newName
.contains('#'));
522 // iterate through all selected items and rename them...
524 foreach (KFileItem item
, items
) {
525 const KUrl
& oldUrl
= item
.url();
527 number
.setNum(index
++);
529 QString name
= newName
;
530 name
.replace('#', number
);
532 if (oldUrl
.fileName() != name
) {
533 KUrl newUrl
= oldUrl
;
534 newUrl
.setFileName(name
);
535 KonqOperations::rename(this, oldUrl
, newUrl
);
536 emit
doingOperation(KonqFileUndoManager::RENAME
);
540 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
541 Q_ASSERT(items
.count() == 1);
543 if (isColumnViewActive()) {
544 m_columnView
->editItem(items
.first());
546 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
547 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
548 itemView()->edit(proxyIndex
);
551 Q_ASSERT(items
.count() == 1);
553 RenameDialog
dialog(this, items
);
554 if (dialog
.exec() == QDialog::Rejected
) {
558 const QString
& newName
= dialog
.newName();
559 if (newName
.isEmpty()) {
560 emit
errorMessage(dialog
.errorString());
562 const KUrl
& oldUrl
= items
.first().url();
563 KUrl newUrl
= oldUrl
;
564 newUrl
.setFileName(newName
);
565 KonqOperations::rename(this, oldUrl
, newUrl
);
566 emit
doingOperation(KonqFileUndoManager::RENAME
);
571 void DolphinView::trashSelectedItems()
573 emit
doingOperation(KonqFileUndoManager::TRASH
);
574 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
577 void DolphinView::deleteSelectedItems()
579 const KUrl::List list
= selectedUrls();
580 const bool del
= KonqOperations::askDeleteConfirmation(list
,
582 KonqOperations::DEFAULT_CONFIRMATION
,
586 KIO::Job
* job
= KIO::del(list
);
587 connect(job
, SIGNAL(result(KJob
*)),
588 this, SLOT(slotDeleteFileFinished(KJob
*)));
592 void DolphinView::cutSelectedItems()
594 QMimeData
* mimeData
= new QMimeData();
595 const KUrl::List kdeUrls
= selectedUrls();
596 const KUrl::List mostLocalUrls
;
597 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
598 QApplication::clipboard()->setMimeData(mimeData
);
601 void DolphinView::copySelectedItems()
603 QMimeData
* mimeData
= new QMimeData();
604 const KUrl::List kdeUrls
= selectedUrls();
605 const KUrl::List mostLocalUrls
;
606 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
607 QApplication::clipboard()->setMimeData(mimeData
);
610 void DolphinView::paste()
615 void DolphinView::pasteIntoFolder()
617 const KFileItemList items
= selectedItems();
618 if ((items
.count() == 1) && items
.first().isDir()) {
619 pasteToUrl(items
.first().url());
623 void DolphinView::setShowPreview(bool show
)
625 if (m_showPreview
== show
) {
629 const KUrl viewPropsUrl
= viewPropertiesUrl();
630 ViewProperties
props(viewPropsUrl
);
631 props
.setShowPreview(show
);
633 m_showPreview
= show
;
634 m_iconManager
->setShowPreview(show
);
635 emit
showPreviewChanged();
637 loadDirectory(viewPropsUrl
);
640 void DolphinView::setShowHiddenFiles(bool show
)
642 if (m_dirLister
->showingDotFiles() == show
) {
646 const KUrl viewPropsUrl
= viewPropertiesUrl();
647 ViewProperties
props(viewPropsUrl
);
648 props
.setShowHiddenFiles(show
);
650 m_dirLister
->setShowingDotFiles(show
);
651 emit
showHiddenFilesChanged();
653 loadDirectory(viewPropsUrl
);
656 void DolphinView::setCategorizedSorting(bool categorized
)
658 if (categorized
== categorizedSorting()) {
662 // setCategorizedSorting(true) may only get invoked
663 // if the view supports categorized sorting
664 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
666 ViewProperties
props(viewPropertiesUrl());
667 props
.setCategorizedSorting(categorized
);
670 m_storedCategorizedSorting
= categorized
;
671 m_proxyModel
->setCategorizedModel(categorized
);
673 emit
categorizedSortingChanged();
676 void DolphinView::toggleSortOrder()
678 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
679 Qt::DescendingOrder
:
684 void DolphinView::toggleAdditionalInfo(QAction
* action
)
686 const KFileItemDelegate::Information info
=
687 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
689 KFileItemDelegate::InformationList list
= additionalInfo();
691 const bool show
= action
->isChecked();
693 const int index
= list
.indexOf(info
);
694 const bool containsInfo
= (index
>= 0);
695 if (show
&& !containsInfo
) {
697 setAdditionalInfo(list
);
698 } else if (!show
&& containsInfo
) {
699 list
.removeAt(index
);
700 setAdditionalInfo(list
);
701 Q_ASSERT(list
.indexOf(info
) < 0);
706 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
708 QWidget::mouseReleaseEvent(event
);
712 void DolphinView::wheelEvent(QWheelEvent
* event
)
714 if (event
->modifiers() & Qt::ControlModifier
) {
715 const int delta
= event
->delta();
716 if ((delta
> 0) && isZoomInPossible()) {
718 } else if ((delta
< 0) && isZoomOutPossible()) {
725 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
727 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
728 m_controller
->requestActivation();
731 return QWidget::eventFilter(watched
, event
);
734 void DolphinView::activate()
739 void DolphinView::triggerItem(const KFileItem
& item
)
741 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
742 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
743 // items are selected by the user, hence don't trigger the
744 // item specified by 'index'
748 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue xxxxxx
749 if (item
.isNull() || m_isContextMenuOpen
) {
753 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
756 void DolphinView::emitSelectionChangedSignal()
758 emit
selectionChanged(DolphinView::selectedItems());
761 void DolphinView::openContextMenu(const QPoint
& pos
)
765 const QModelIndex index
= itemView()->indexAt(pos
);
766 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
767 item
= fileItem(index
);
770 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue xxxxxx
771 emit
requestContextMenu(item
, url());
772 m_isContextMenuOpen
= false;
775 void DolphinView::dropUrls(const KUrl::List
& urls
,
776 const KUrl
& destPath
,
777 const KFileItem
& destItem
)
779 Q_ASSERT(!urls
.isEmpty());
780 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
781 destItem
.url() : destPath
;
782 const KUrl sourceDir
= KUrl(urls
.first().directory());
783 if (sourceDir
!= destination
) {
784 dropUrls(urls
, destination
);
788 void DolphinView::dropUrls(const KUrl::List
& urls
,
789 const KUrl
& destination
)
791 DolphinDropController
dropController(this);
792 // forward doingOperation signal up to the mainwindow
793 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
794 this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)));
795 dropController
.dropUrls(urls
, destination
);
798 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
800 ViewProperties
props(viewPropertiesUrl());
801 props
.setSorting(sorting
);
803 m_proxyModel
->setSorting(sorting
);
805 emit
sortingChanged(sorting
);
808 void DolphinView::updateSortOrder(Qt::SortOrder order
)
810 ViewProperties
props(viewPropertiesUrl());
811 props
.setSortOrder(order
);
813 m_proxyModel
->setSortOrder(order
);
815 emit
sortOrderChanged(order
);
818 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
820 ViewProperties
props(viewPropertiesUrl());
821 props
.setAdditionalInfo(info
);
824 m_fileItemDelegate
->setShowInformation(info
);
826 emit
additionalInfoChanged();
829 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
831 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
832 (m_mode
== DolphinView::IconsView
);
834 QAction
* showSizeInfo
= collection
->action("show_size_info");
835 QAction
* showDateInfo
= collection
->action("show_date_info");
836 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
837 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
838 QAction
* showGroupInfo
= collection
->action("show_group_info");
839 QAction
* showMimeInfo
= collection
->action("show_mime_info");
841 showSizeInfo
->setChecked(false);
842 showDateInfo
->setChecked(false);
843 showPermissionsInfo
->setChecked(false);
844 showOwnerInfo
->setChecked(false);
845 showGroupInfo
->setChecked(false);
846 showMimeInfo
->setChecked(false);
848 showSizeInfo
->setEnabled(enable
);
849 showDateInfo
->setEnabled(enable
);
850 showPermissionsInfo
->setEnabled(enable
);
851 showOwnerInfo
->setEnabled(enable
);
852 showGroupInfo
->setEnabled(enable
);
853 showMimeInfo
->setEnabled(enable
);
855 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
857 case KFileItemDelegate::Size
:
858 showSizeInfo
->setChecked(true);
860 case KFileItemDelegate::ModificationTime
:
861 showDateInfo
->setChecked(true);
863 case KFileItemDelegate::Permissions
:
864 showPermissionsInfo
->setChecked(true);
866 case KFileItemDelegate::Owner
:
867 showOwnerInfo
->setChecked(true);
869 case KFileItemDelegate::OwnerAndGroup
:
870 showGroupInfo
->setChecked(true);
872 case KFileItemDelegate::FriendlyMimeType
:
873 showMimeInfo
->setChecked(true);
881 QPair
<bool, QString
> DolphinView::pasteInfo() const
883 QPair
<bool, QString
> ret
;
884 QClipboard
* clipboard
= QApplication::clipboard();
885 const QMimeData
* mimeData
= clipboard
->mimeData();
887 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
888 if (!urls
.isEmpty()) {
890 if (urls
.count() == 1) {
891 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
892 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
893 i18nc("@action:inmenu", "Paste One File");
896 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
900 ret
.second
= i18nc("@action:inmenu", "Paste");
906 void DolphinView::emitContentsMoved()
908 // only emit the contents moved signal if:
909 // - no directory loading is ongoing (this would reset the contents position
911 // - if the Column View is active: the column view does an automatic
912 // positioning during the loading operation, which must be remembered
913 if (!m_loadingDirectory
|| isColumnViewActive()) {
914 const QPoint
pos(contentsPosition());
915 emit
contentsMoved(pos
.x(), pos
.y());
919 void DolphinView::showHoverInformation(const KFileItem
& item
)
921 emit
requestItemInfo(item
);
924 void DolphinView::clearHoverInformation()
926 emit
requestItemInfo(KFileItem());
929 void DolphinView::slotDeleteFileFinished(KJob
* job
)
931 if (job
->error() == 0) {
932 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
934 emit
errorMessage(job
->errorString());
938 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
940 if (!url
.isValid()) {
941 const QString
location(url
.pathOrUrl());
942 if (location
.isEmpty()) {
943 emit
errorMessage(i18nc("@info:status", "The location is empty."));
945 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
950 m_loadingDirectory
= true;
953 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
955 if (isColumnViewActive()) {
956 // adjusting the directory lister is not enough in the case of the
957 // column view, as each column has its own directory lister internally...
959 m_columnView
->reload();
961 m_columnView
->showColumn(url
);
966 KUrl
DolphinView::viewPropertiesUrl() const
968 if (isColumnViewActive()) {
969 return m_columnView
->rootUrl();
975 void DolphinView::applyViewProperties(const KUrl
& url
)
977 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
978 // The column view is active, hence don't apply the view properties
979 // of sub directories (represented by columns) to the view. The
980 // view always represents the properties of the first column.
984 const ViewProperties
props(url
);
986 const Mode mode
= props
.viewMode();
987 if (m_mode
!= mode
) {
992 if (itemView() == 0) {
995 Q_ASSERT(itemView() != 0);
996 Q_ASSERT(m_fileItemDelegate
!= 0);
998 const bool showHiddenFiles
= props
.showHiddenFiles();
999 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1000 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1001 emit
showHiddenFilesChanged();
1004 m_storedCategorizedSorting
= props
.categorizedSorting();
1005 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1006 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1007 m_proxyModel
->setCategorizedModel(categorized
);
1008 emit
categorizedSortingChanged();
1011 const DolphinView::Sorting sorting
= props
.sorting();
1012 if (sorting
!= m_proxyModel
->sorting()) {
1013 m_proxyModel
->setSorting(sorting
);
1014 emit
sortingChanged(sorting
);
1017 const Qt::SortOrder sortOrder
= props
.sortOrder();
1018 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1019 m_proxyModel
->setSortOrder(sortOrder
);
1020 emit
sortOrderChanged(sortOrder
);
1023 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1024 if (info
!= m_fileItemDelegate
->showInformation()) {
1025 m_fileItemDelegate
->setShowInformation(info
);
1026 emit
additionalInfoChanged();
1029 const bool showPreview
= props
.showPreview();
1030 if (showPreview
!= m_showPreview
) {
1031 m_showPreview
= showPreview
;
1032 m_iconManager
->setShowPreview(showPreview
);
1033 emit
showPreviewChanged();
1037 void DolphinView::createView()
1040 Q_ASSERT(m_iconsView
== 0);
1041 Q_ASSERT(m_detailsView
== 0);
1042 Q_ASSERT(m_columnView
== 0);
1044 QAbstractItemView
* view
= 0;
1047 m_iconsView
= new DolphinIconsView(this, m_controller
);
1053 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1054 view
= m_detailsView
;
1058 m_columnView
= new DolphinColumnView(this, m_controller
);
1059 view
= m_columnView
;
1063 Q_ASSERT(view
!= 0);
1064 view
->installEventFilter(this);
1066 m_controller
->setItemView(view
);
1068 m_fileItemDelegate
= new KFileItemDelegate(view
);
1069 view
->setItemDelegate(m_fileItemDelegate
);
1071 view
->setModel(m_proxyModel
);
1072 if (m_selectionModel
!= 0) {
1073 view
->setSelectionModel(m_selectionModel
);
1075 m_selectionModel
= view
->selectionModel();
1078 // reparent the selection model, as it should not be deleted
1079 // when deleting the model
1080 m_selectionModel
->setParent(this);
1082 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1084 new KMimeTypeResolver(view
, m_dolphinModel
);
1085 m_iconManager
= new IconManager(view
, m_proxyModel
);
1086 m_iconManager
->setShowPreview(m_showPreview
);
1088 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1089 new ToolTipManager(view
, m_proxyModel
);
1092 m_topLayout
->insertWidget(1, view
);
1094 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1095 this, SLOT(emitSelectionChangedSignal()));
1096 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1097 this, SLOT(emitContentsMoved()));
1098 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1099 this, SLOT(emitContentsMoved()));
1102 void DolphinView::deleteView()
1104 QAbstractItemView
* view
= itemView();
1106 m_topLayout
->removeWidget(view
);
1108 view
->deleteLater();
1113 m_fileItemDelegate
= 0;
1118 QAbstractItemView
* DolphinView::itemView() const
1120 if (m_detailsView
!= 0) {
1121 return m_detailsView
;
1122 } else if (m_columnView
!= 0) {
1123 return m_columnView
;
1129 bool DolphinView::isCutItem(const KFileItem
& item
) const
1131 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1132 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1134 const KUrl
& itemUrl
= item
.url();
1135 KUrl::List::const_iterator it
= cutUrls
.begin();
1136 const KUrl::List::const_iterator end
= cutUrls
.end();
1138 if (*it
== itemUrl
) {
1147 void DolphinView::pasteToUrl(const KUrl
& url
)
1149 QClipboard
* clipboard
= QApplication::clipboard();
1150 const QMimeData
* mimeData
= clipboard
->mimeData();
1152 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1153 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1154 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1155 emit
doingOperation(KonqFileUndoManager::MOVE
);
1158 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1159 emit
doingOperation(KonqFileUndoManager::COPY
);
1163 #include "dolphinview.moc"