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 setFocusPolicy(Qt::StrongFocus
);
90 m_topLayout
= new QVBoxLayout(this);
91 m_topLayout
->setSpacing(0);
92 m_topLayout
->setMargin(0);
94 m_controller
= new DolphinController(this);
95 m_controller
->setUrl(url
);
97 // Receiver of the DolphinView signal 'urlChanged()' don't need
98 // to care whether the internal controller changed the URL already or whether
99 // the controller just requested an URL change and will be updated later.
100 // In both cases the URL has been changed:
101 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
102 this, SIGNAL(urlChanged(const KUrl
&)));
103 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
104 this, SIGNAL(urlChanged(const KUrl
&)));
106 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
107 this, SLOT(openContextMenu(const QPoint
&)));
108 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
109 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
110 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
111 this, SLOT(updateSorting(DolphinView::Sorting
)));
112 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
113 this, SLOT(updateSortOrder(Qt::SortOrder
)));
114 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
115 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
116 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
117 this, SLOT(triggerItem(const KFileItem
&)));
118 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
119 this, SIGNAL(tabRequested(const KUrl
&)));
120 connect(m_controller
, SIGNAL(activated()),
121 this, SLOT(activate()));
122 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
123 this, SLOT(showHoverInformation(const KFileItem
&)));
124 connect(m_controller
, SIGNAL(viewportEntered()),
125 this, SLOT(clearHoverInformation()));
127 applyViewProperties(url
);
128 m_topLayout
->addWidget(itemView());
131 DolphinView::~DolphinView()
135 const KUrl
& DolphinView::url() const
137 return m_controller
->url();
140 KUrl
DolphinView::rootUrl() const
142 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
145 void DolphinView::setActive(bool active
)
147 if (active
== m_active
) {
152 m_selectionModel
->clearSelection();
154 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
156 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
157 // bypasses the problem when having a split view and changing the active view to
158 // update the some URL dependent states. A nicer approach should be no big deal...
159 emit
urlChanged(url());
160 emit
selectionChanged(selectedItems());
165 QWidget
* viewport
= itemView()->viewport();
167 palette
.setColor(viewport
->backgroundRole(), color
);
168 viewport
->setPalette(palette
);
176 m_controller
->indicateActivationChange(active
);
179 bool DolphinView::isActive() const
184 void DolphinView::setMode(Mode mode
)
186 if (mode
== m_mode
) {
187 return; // the wished mode is already set
194 const KUrl viewPropsUrl
= viewPropertiesUrl();
195 ViewProperties
props(viewPropsUrl
);
196 props
.setViewMode(m_mode
);
199 // the file item delegate has been recreated, apply the current
200 // additional information manually
201 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
202 m_fileItemDelegate
->setShowInformation(infoList
);
203 emit
additionalInfoChanged();
205 // Not all view modes support categorized sorting. Adjust the sorting model
206 // if changing the view mode results in a change of the categorized sorting
208 m_storedCategorizedSorting
= props
.categorizedSorting();
209 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
210 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
211 m_proxyModel
->setCategorizedModel(categorized
);
212 emit
categorizedSortingChanged();
218 DolphinView::Mode
DolphinView::mode() const
223 bool DolphinView::showPreview() const
225 return m_showPreview
;
228 bool DolphinView::showHiddenFiles() const
230 return m_dirLister
->showingDotFiles();
233 bool DolphinView::categorizedSorting() const
235 // If all view modes would support categorized sorting, returning
236 // m_proxyModel->isCategorizedModel() would be the way to go. As
237 // currently only the icons view supports caterized sorting, we remember
238 // the stored view properties state in m_storedCategorizedSorting and
239 // return this state. The application takes care to disable the corresponding
240 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
241 // that this setting is not applied to the current view mode.
242 return m_storedCategorizedSorting
;
245 bool DolphinView::supportsCategorizedSorting() const
247 return m_iconsView
!= 0;
250 void DolphinView::selectAll()
252 QAbstractItemView
* view
= itemView();
253 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
254 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
255 // selection instead of selecting all items. This is bypassed for KDE 4.0
256 // by invoking clearSelection() first.
257 view
->clearSelection();
261 void DolphinView::invertSelection()
263 if (isColumnViewActive()) {
264 // QAbstractItemView does not offer a virtual method invertSelection()
265 // as counterpart to QAbstractItemView::selectAll(). This makes it
266 // necessary to delegate the inverting of the selection to the
267 // column view, as only the selection of the active column should
269 m_columnView
->invertSelection();
271 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
272 const QAbstractItemModel
* itemModel
= selectionModel
->model();
274 const QModelIndex topLeft
= itemModel
->index(0, 0);
275 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
276 itemModel
->columnCount() - 1);
278 const QItemSelection
selection(topLeft
, bottomRight
);
279 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
283 bool DolphinView::hasSelection() const
285 return itemView()->selectionModel()->hasSelection();
288 void DolphinView::clearSelection()
290 itemView()->selectionModel()->clear();
293 KFileItemList
DolphinView::selectedItems() const
295 const QAbstractItemView
* view
= itemView();
297 // Our view has a selection, we will map them back to the DolphinModel
298 // and then fill the KFileItemList.
299 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
301 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
302 KFileItemList itemList
;
304 const QModelIndexList indexList
= selection
.indexes();
305 foreach (const QModelIndex
&index
, indexList
) {
306 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
307 if (!item
.isNull()) {
308 itemList
.append(item
);
315 KUrl::List
DolphinView::selectedUrls() const
318 const KFileItemList list
= selectedItems();
319 foreach (const KFileItem
&item
, list
) {
320 urls
.append(item
.url());
325 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
327 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
328 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
331 void DolphinView::setContentsPosition(int x
, int y
)
333 QAbstractItemView
* view
= itemView();
335 // the ColumnView takes care itself for the horizontal scrolling
336 if (!isColumnViewActive()) {
337 view
->horizontalScrollBar()->setValue(x
);
339 view
->verticalScrollBar()->setValue(y
);
341 m_loadingDirectory
= false;
344 QPoint
DolphinView::contentsPosition() const
346 const int x
= itemView()->horizontalScrollBar()->value();
347 const int y
= itemView()->verticalScrollBar()->value();
351 void DolphinView::zoomIn()
353 m_controller
->triggerZoomIn();
354 m_iconManager
->updatePreviews();
357 void DolphinView::zoomOut()
359 m_controller
->triggerZoomOut();
360 m_iconManager
->updatePreviews();
363 bool DolphinView::isZoomInPossible() const
365 return m_controller
->isZoomInPossible();
368 bool DolphinView::isZoomOutPossible() const
370 return m_controller
->isZoomOutPossible();
373 void DolphinView::setSorting(Sorting sorting
)
375 if (sorting
!= this->sorting()) {
376 updateSorting(sorting
);
380 DolphinView::Sorting
DolphinView::sorting() const
382 return m_proxyModel
->sorting();
385 void DolphinView::setSortOrder(Qt::SortOrder order
)
387 if (sortOrder() != order
) {
388 updateSortOrder(order
);
392 Qt::SortOrder
DolphinView::sortOrder() const
394 return m_proxyModel
->sortOrder();
397 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
399 const KUrl viewPropsUrl
= viewPropertiesUrl();
400 ViewProperties
props(viewPropsUrl
);
401 props
.setAdditionalInfo(info
);
402 m_fileItemDelegate
->setShowInformation(info
);
404 emit
additionalInfoChanged();
406 if (itemView() != m_detailsView
) {
407 // the details view requires no reloading of the directory, as it maps
408 // the file item delegate info to its columns internally
409 loadDirectory(viewPropsUrl
);
413 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
415 return m_fileItemDelegate
->showInformation();
418 void DolphinView::reload()
421 loadDirectory(url(), true);
424 void DolphinView::refresh()
426 const bool oldActivationState
= m_active
;
430 applyViewProperties(m_controller
->url());
433 setActive(oldActivationState
);
436 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
438 if (m_controller
->url() == url
) {
442 m_controller
->setUrl(url
); // emits urlChanged, which we forward
444 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
445 applyViewProperties(rootUrl
);
446 loadDirectory(rootUrl
);
447 if (itemView() == m_columnView
) {
448 m_columnView
->setRootUrl(rootUrl
);
449 m_columnView
->showColumn(url
);
452 applyViewProperties(url
);
456 emit
startedPathLoading(url
);
459 void DolphinView::setNameFilter(const QString
& nameFilter
)
461 m_proxyModel
->setFilterRegExp(nameFilter
);
463 if (isColumnViewActive()) {
464 // adjusting the directory lister is not enough in the case of the
465 // column view, as each column has its own directory lister internally...
466 m_columnView
->setNameFilter(nameFilter
);
470 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
472 foreach (const KFileItem
&item
, m_dirLister
->items()) {
481 void DolphinView::setUrl(const KUrl
& url
)
483 updateView(url
, KUrl());
486 void DolphinView::changeSelection(const KFileItemList
& selection
)
489 if (selection
.isEmpty()) {
492 const KUrl
& baseUrl
= url();
494 QItemSelection new_selection
;
495 foreach(const KFileItem
& item
, selection
) {
496 url
= item
.url().upUrl();
497 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
498 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
499 new_selection
.select(index
, index
);
502 itemView()->selectionModel()->select(new_selection
,
503 QItemSelectionModel::ClearAndSelect
504 | QItemSelectionModel::Current
);
507 void DolphinView::renameSelectedItems()
509 const KFileItemList items
= selectedItems();
510 if (items
.count() > 1) {
511 // More than one item has been selected for renaming. Open
512 // a rename dialog and rename all items afterwards.
513 RenameDialog
dialog(this, items
);
514 if (dialog
.exec() == QDialog::Rejected
) {
518 const QString newName
= dialog
.newName();
519 if (newName
.isEmpty()) {
520 emit
errorMessage(dialog
.errorString());
522 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
523 // as one operation instead of n rename operations like it is done now...
524 Q_ASSERT(newName
.contains('#'));
526 // iterate through all selected items and rename them...
528 foreach (const KFileItem
&item
, items
) {
529 const KUrl
& oldUrl
= item
.url();
531 number
.setNum(index
++);
533 QString name
= newName
;
534 name
.replace('#', number
);
536 if (oldUrl
.fileName() != name
) {
537 KUrl newUrl
= oldUrl
;
538 newUrl
.setFileName(name
);
539 KonqOperations::rename(this, oldUrl
, newUrl
);
540 emit
doingOperation(KIO::FileUndoManager::Rename
);
544 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
545 Q_ASSERT(items
.count() == 1);
547 if (isColumnViewActive()) {
548 m_columnView
->editItem(items
.first());
550 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
551 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
552 itemView()->edit(proxyIndex
);
555 Q_ASSERT(items
.count() == 1);
557 RenameDialog
dialog(this, items
);
558 if (dialog
.exec() == QDialog::Rejected
) {
562 const QString
& newName
= dialog
.newName();
563 if (newName
.isEmpty()) {
564 emit
errorMessage(dialog
.errorString());
566 const KUrl
& oldUrl
= items
.first().url();
567 KUrl newUrl
= oldUrl
;
568 newUrl
.setFileName(newName
);
569 KonqOperations::rename(this, oldUrl
, newUrl
);
570 emit
doingOperation(KIO::FileUndoManager::Rename
);
575 void DolphinView::trashSelectedItems()
577 emit
doingOperation(KIO::FileUndoManager::Trash
);
578 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
581 void DolphinView::deleteSelectedItems()
583 const KUrl::List list
= selectedUrls();
584 const bool del
= KonqOperations::askDeleteConfirmation(list
,
586 KonqOperations::DEFAULT_CONFIRMATION
,
590 KIO::Job
* job
= KIO::del(list
);
591 connect(job
, SIGNAL(result(KJob
*)),
592 this, SLOT(slotDeleteFileFinished(KJob
*)));
596 void DolphinView::cutSelectedItems()
598 QMimeData
* mimeData
= new QMimeData();
599 const KUrl::List kdeUrls
= selectedUrls();
600 const KUrl::List mostLocalUrls
;
601 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
602 QApplication::clipboard()->setMimeData(mimeData
);
605 void DolphinView::copySelectedItems()
607 QMimeData
* mimeData
= new QMimeData();
608 const KUrl::List kdeUrls
= selectedUrls();
609 const KUrl::List mostLocalUrls
;
610 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
611 QApplication::clipboard()->setMimeData(mimeData
);
614 void DolphinView::paste()
619 void DolphinView::pasteIntoFolder()
621 const KFileItemList items
= selectedItems();
622 if ((items
.count() == 1) && items
.first().isDir()) {
623 pasteToUrl(items
.first().url());
627 void DolphinView::setShowPreview(bool show
)
629 if (m_showPreview
== show
) {
633 const KUrl viewPropsUrl
= viewPropertiesUrl();
634 ViewProperties
props(viewPropsUrl
);
635 props
.setShowPreview(show
);
637 m_showPreview
= show
;
638 m_iconManager
->setShowPreview(show
);
639 emit
showPreviewChanged();
641 loadDirectory(viewPropsUrl
);
644 void DolphinView::setShowHiddenFiles(bool show
)
646 if (m_dirLister
->showingDotFiles() == show
) {
650 const KUrl viewPropsUrl
= viewPropertiesUrl();
651 ViewProperties
props(viewPropsUrl
);
652 props
.setShowHiddenFiles(show
);
654 m_dirLister
->setShowingDotFiles(show
);
655 emit
showHiddenFilesChanged();
657 loadDirectory(viewPropsUrl
);
660 void DolphinView::setCategorizedSorting(bool categorized
)
662 if (categorized
== categorizedSorting()) {
666 // setCategorizedSorting(true) may only get invoked
667 // if the view supports categorized sorting
668 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
670 ViewProperties
props(viewPropertiesUrl());
671 props
.setCategorizedSorting(categorized
);
674 m_storedCategorizedSorting
= categorized
;
675 m_proxyModel
->setCategorizedModel(categorized
);
677 emit
categorizedSortingChanged();
680 void DolphinView::toggleSortOrder()
682 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
683 Qt::DescendingOrder
:
688 void DolphinView::toggleAdditionalInfo(QAction
* action
)
690 const KFileItemDelegate::Information info
=
691 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
693 KFileItemDelegate::InformationList list
= additionalInfo();
695 const bool show
= action
->isChecked();
697 const int index
= list
.indexOf(info
);
698 const bool containsInfo
= (index
>= 0);
699 if (show
&& !containsInfo
) {
701 setAdditionalInfo(list
);
702 } else if (!show
&& containsInfo
) {
703 list
.removeAt(index
);
704 setAdditionalInfo(list
);
705 Q_ASSERT(list
.indexOf(info
) < 0);
710 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
712 QWidget::mouseReleaseEvent(event
);
716 void DolphinView::wheelEvent(QWheelEvent
* event
)
718 if (event
->modifiers() & Qt::ControlModifier
) {
719 const int delta
= event
->delta();
720 if ((delta
> 0) && isZoomInPossible()) {
722 } else if ((delta
< 0) && isZoomOutPossible()) {
729 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
731 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
732 m_controller
->requestActivation();
735 return QWidget::eventFilter(watched
, event
);
738 void DolphinView::activate()
743 void DolphinView::triggerItem(const KFileItem
& item
)
745 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
746 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
747 // items are selected by the user, hence don't trigger the
748 // item specified by 'index'
752 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
753 if (item
.isNull() || m_isContextMenuOpen
) {
757 if (m_toolTipManager
!= 0) {
758 m_toolTipManager
->hideTip();
760 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
763 void DolphinView::emitSelectionChangedSignal()
765 emit
selectionChanged(DolphinView::selectedItems());
768 void DolphinView::openContextMenu(const QPoint
& pos
)
772 const QModelIndex index
= itemView()->indexAt(pos
);
773 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
774 item
= fileItem(index
);
777 if (m_toolTipManager
!= 0) {
778 m_toolTipManager
->hideTip();
781 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
782 emit
requestContextMenu(item
, url());
783 m_isContextMenuOpen
= false;
786 void DolphinView::dropUrls(const KUrl::List
& urls
,
787 const KUrl
& destPath
,
788 const KFileItem
& destItem
)
790 Q_ASSERT(!urls
.isEmpty());
791 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
792 destItem
.url() : destPath
;
793 const KUrl sourceDir
= KUrl(urls
.first().directory());
794 if (sourceDir
!= destination
) {
795 dropUrls(urls
, destination
);
799 void DolphinView::dropUrls(const KUrl::List
& urls
,
800 const KUrl
& destination
)
802 DolphinDropController
dropController(this);
803 // forward doingOperation signal up to the mainwindow
804 connect(&dropController
, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)),
805 this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)));
806 dropController
.dropUrls(urls
, destination
);
809 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
811 ViewProperties
props(viewPropertiesUrl());
812 props
.setSorting(sorting
);
814 m_proxyModel
->setSorting(sorting
);
816 emit
sortingChanged(sorting
);
819 void DolphinView::updateSortOrder(Qt::SortOrder order
)
821 ViewProperties
props(viewPropertiesUrl());
822 props
.setSortOrder(order
);
824 m_proxyModel
->setSortOrder(order
);
826 emit
sortOrderChanged(order
);
829 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
831 ViewProperties
props(viewPropertiesUrl());
832 props
.setAdditionalInfo(info
);
835 m_fileItemDelegate
->setShowInformation(info
);
837 emit
additionalInfoChanged();
840 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
842 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
843 (m_mode
== DolphinView::IconsView
);
845 QAction
* showSizeInfo
= collection
->action("show_size_info");
846 QAction
* showDateInfo
= collection
->action("show_date_info");
847 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
848 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
849 QAction
* showGroupInfo
= collection
->action("show_group_info");
850 QAction
* showMimeInfo
= collection
->action("show_mime_info");
852 showSizeInfo
->setChecked(false);
853 showDateInfo
->setChecked(false);
854 showPermissionsInfo
->setChecked(false);
855 showOwnerInfo
->setChecked(false);
856 showGroupInfo
->setChecked(false);
857 showMimeInfo
->setChecked(false);
859 showSizeInfo
->setEnabled(enable
);
860 showDateInfo
->setEnabled(enable
);
861 showPermissionsInfo
->setEnabled(enable
);
862 showOwnerInfo
->setEnabled(enable
);
863 showGroupInfo
->setEnabled(enable
);
864 showMimeInfo
->setEnabled(enable
);
866 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
868 case KFileItemDelegate::Size
:
869 showSizeInfo
->setChecked(true);
871 case KFileItemDelegate::ModificationTime
:
872 showDateInfo
->setChecked(true);
874 case KFileItemDelegate::Permissions
:
875 showPermissionsInfo
->setChecked(true);
877 case KFileItemDelegate::Owner
:
878 showOwnerInfo
->setChecked(true);
880 case KFileItemDelegate::OwnerAndGroup
:
881 showGroupInfo
->setChecked(true);
883 case KFileItemDelegate::FriendlyMimeType
:
884 showMimeInfo
->setChecked(true);
892 QPair
<bool, QString
> DolphinView::pasteInfo() const
894 QPair
<bool, QString
> ret
;
895 QClipboard
* clipboard
= QApplication::clipboard();
896 const QMimeData
* mimeData
= clipboard
->mimeData();
898 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
899 if (!urls
.isEmpty()) {
901 if (urls
.count() == 1) {
902 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
903 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
904 i18nc("@action:inmenu", "Paste One File");
907 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
911 ret
.second
= i18nc("@action:inmenu", "Paste");
917 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
919 m_tabsForFiles
= tabsForFiles
;
922 bool DolphinView::isTabsForFilesEnabled() const
924 return m_tabsForFiles
;
927 void DolphinView::emitContentsMoved()
929 // only emit the contents moved signal if:
930 // - no directory loading is ongoing (this would reset the contents position
932 // - if the Column View is active: the column view does an automatic
933 // positioning during the loading operation, which must be remembered
934 if (!m_loadingDirectory
|| isColumnViewActive()) {
935 const QPoint
pos(contentsPosition());
936 emit
contentsMoved(pos
.x(), pos
.y());
940 void DolphinView::showHoverInformation(const KFileItem
& item
)
942 emit
requestItemInfo(item
);
945 void DolphinView::clearHoverInformation()
947 emit
requestItemInfo(KFileItem());
950 void DolphinView::slotDeleteFileFinished(KJob
* job
)
952 if (job
->error() == 0) {
953 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
955 emit
errorMessage(job
->errorString());
959 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
961 if (!url
.isValid()) {
962 const QString
location(url
.pathOrUrl());
963 if (location
.isEmpty()) {
964 emit
errorMessage(i18nc("@info:status", "The location is empty."));
966 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
971 m_loadingDirectory
= true;
974 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
976 if (isColumnViewActive()) {
977 // adjusting the directory lister is not enough in the case of the
978 // column view, as each column has its own directory lister internally...
980 m_columnView
->reload();
982 m_columnView
->showColumn(url
);
987 KUrl
DolphinView::viewPropertiesUrl() const
989 if (isColumnViewActive()) {
990 return m_columnView
->rootUrl();
996 void DolphinView::applyViewProperties(const KUrl
& url
)
998 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
999 // The column view is active, hence don't apply the view properties
1000 // of sub directories (represented by columns) to the view. The
1001 // view always represents the properties of the first column.
1005 const ViewProperties
props(url
);
1007 const Mode mode
= props
.viewMode();
1008 if (m_mode
!= mode
) {
1013 if (itemView() == 0) {
1016 Q_ASSERT(itemView() != 0);
1017 Q_ASSERT(m_fileItemDelegate
!= 0);
1019 const bool showHiddenFiles
= props
.showHiddenFiles();
1020 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1021 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1022 emit
showHiddenFilesChanged();
1025 m_storedCategorizedSorting
= props
.categorizedSorting();
1026 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1027 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1028 m_proxyModel
->setCategorizedModel(categorized
);
1029 emit
categorizedSortingChanged();
1032 const DolphinView::Sorting sorting
= props
.sorting();
1033 if (sorting
!= m_proxyModel
->sorting()) {
1034 m_proxyModel
->setSorting(sorting
);
1035 emit
sortingChanged(sorting
);
1038 const Qt::SortOrder sortOrder
= props
.sortOrder();
1039 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1040 m_proxyModel
->setSortOrder(sortOrder
);
1041 emit
sortOrderChanged(sortOrder
);
1044 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1045 if (info
!= m_fileItemDelegate
->showInformation()) {
1046 m_fileItemDelegate
->setShowInformation(info
);
1047 emit
additionalInfoChanged();
1050 const bool showPreview
= props
.showPreview();
1051 if (showPreview
!= m_showPreview
) {
1052 m_showPreview
= showPreview
;
1053 m_iconManager
->setShowPreview(showPreview
);
1054 emit
showPreviewChanged();
1058 void DolphinView::createView()
1061 Q_ASSERT(m_iconsView
== 0);
1062 Q_ASSERT(m_detailsView
== 0);
1063 Q_ASSERT(m_columnView
== 0);
1065 QAbstractItemView
* view
= 0;
1068 m_iconsView
= new DolphinIconsView(this, m_controller
);
1074 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1075 view
= m_detailsView
;
1079 m_columnView
= new DolphinColumnView(this, m_controller
);
1080 view
= m_columnView
;
1084 Q_ASSERT(view
!= 0);
1085 view
->installEventFilter(this);
1087 m_controller
->setItemView(view
);
1089 m_fileItemDelegate
= new KFileItemDelegate(view
);
1090 view
->setItemDelegate(m_fileItemDelegate
);
1092 view
->setModel(m_proxyModel
);
1093 if (m_selectionModel
!= 0) {
1094 view
->setSelectionModel(m_selectionModel
);
1096 m_selectionModel
= view
->selectionModel();
1099 // reparent the selection model, as it should not be deleted
1100 // when deleting the model
1101 m_selectionModel
->setParent(this);
1103 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1105 new KMimeTypeResolver(view
, m_dolphinModel
);
1106 m_iconManager
= new IconManager(view
, m_proxyModel
);
1107 m_iconManager
->setShowPreview(m_showPreview
);
1109 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1110 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1113 m_topLayout
->insertWidget(1, view
);
1115 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1116 this, SLOT(emitSelectionChangedSignal()));
1117 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1118 this, SLOT(emitContentsMoved()));
1119 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1120 this, SLOT(emitContentsMoved()));
1123 void DolphinView::deleteView()
1125 QAbstractItemView
* view
= itemView();
1127 m_topLayout
->removeWidget(view
);
1129 view
->deleteLater();
1134 m_fileItemDelegate
= 0;
1136 m_toolTipManager
= 0;
1140 QAbstractItemView
* DolphinView::itemView() const
1142 if (m_detailsView
!= 0) {
1143 return m_detailsView
;
1144 } else if (m_columnView
!= 0) {
1145 return m_columnView
;
1151 bool DolphinView::isCutItem(const KFileItem
& item
) const
1153 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1154 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1156 const KUrl
& itemUrl
= item
.url();
1157 KUrl::List::const_iterator it
= cutUrls
.begin();
1158 const KUrl::List::const_iterator end
= cutUrls
.end();
1160 if (*it
== itemUrl
) {
1169 void DolphinView::pasteToUrl(const KUrl
& url
)
1171 QClipboard
* clipboard
= QApplication::clipboard();
1172 const QMimeData
* mimeData
= clipboard
->mimeData();
1174 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1175 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1176 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1177 emit
doingOperation(KIO::FileUndoManager::Move
);
1180 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1181 emit
doingOperation(KIO::FileUndoManager::Copy
);
1185 #include "dolphinview.moc"