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
),
91 m_topLayout
= new QVBoxLayout(this);
92 m_topLayout
->setSpacing(0);
93 m_topLayout
->setMargin(0);
95 m_controller
= new DolphinController(this);
96 m_controller
->setUrl(url
);
98 // Receiver of the DolphinView signal 'urlChanged()' don't need
99 // to care whether the internal controller changed the URL already or whether
100 // the controller just requested an URL change and will be updated later.
101 // In both cases the URL has been changed:
102 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
103 this, SIGNAL(urlChanged(const KUrl
&)));
104 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
105 this, SIGNAL(urlChanged(const KUrl
&)));
107 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
108 this, SLOT(openContextMenu(const QPoint
&)));
109 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
110 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
111 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
112 this, SLOT(updateSorting(DolphinView::Sorting
)));
113 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
114 this, SLOT(updateSortOrder(Qt::SortOrder
)));
115 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
116 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
117 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
118 this, SLOT(triggerItem(const KFileItem
&)));
119 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
120 this, SIGNAL(tabRequested(const KUrl
&)));
121 connect(m_controller
, SIGNAL(activated()),
122 this, SLOT(activate()));
123 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
124 this, SLOT(showHoverInformation(const KFileItem
&)));
125 connect(m_controller
, SIGNAL(viewportEntered()),
126 this, SLOT(clearHoverInformation()));
128 connect(m_dirLister
, SIGNAL(completed()),
129 this, SLOT(restoreCurrentItem()));
131 applyViewProperties(url
);
132 m_topLayout
->addWidget(itemView());
135 DolphinView::~DolphinView()
139 const KUrl
& DolphinView::url() const
141 return m_controller
->url();
144 KUrl
DolphinView::rootUrl() const
146 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
149 void DolphinView::setActive(bool active
)
151 if (active
== m_active
) {
156 m_selectionModel
->clearSelection();
158 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
160 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
161 // bypasses the problem when having a split view and changing the active view to
162 // update the some URL dependent states. A nicer approach should be no big deal...
163 emit
urlChanged(url());
164 emit
selectionChanged(selectedItems());
169 QWidget
* viewport
= itemView()->viewport();
171 palette
.setColor(viewport
->backgroundRole(), color
);
172 viewport
->setPalette(palette
);
180 m_controller
->indicateActivationChange(active
);
183 bool DolphinView::isActive() const
188 void DolphinView::setMode(Mode mode
)
190 if (mode
== m_mode
) {
191 return; // the wished mode is already set
198 const KUrl viewPropsUrl
= viewPropertiesUrl();
199 ViewProperties
props(viewPropsUrl
);
200 props
.setViewMode(m_mode
);
203 // the file item delegate has been recreated, apply the current
204 // additional information manually
205 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
206 m_fileItemDelegate
->setShowInformation(infoList
);
207 emit
additionalInfoChanged();
209 // Not all view modes support categorized sorting. Adjust the sorting model
210 // if changing the view mode results in a change of the categorized sorting
212 m_storedCategorizedSorting
= props
.categorizedSorting();
213 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
214 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
215 m_proxyModel
->setCategorizedModel(categorized
);
216 emit
categorizedSortingChanged();
222 DolphinView::Mode
DolphinView::mode() const
227 bool DolphinView::showPreview() const
229 return m_showPreview
;
232 bool DolphinView::showHiddenFiles() const
234 return m_dirLister
->showingDotFiles();
237 bool DolphinView::categorizedSorting() const
239 // If all view modes would support categorized sorting, returning
240 // m_proxyModel->isCategorizedModel() would be the way to go. As
241 // currently only the icons view supports caterized sorting, we remember
242 // the stored view properties state in m_storedCategorizedSorting and
243 // return this state. The application takes care to disable the corresponding
244 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
245 // that this setting is not applied to the current view mode.
246 return m_storedCategorizedSorting
;
249 bool DolphinView::supportsCategorizedSorting() const
251 return m_iconsView
!= 0;
254 void DolphinView::selectAll()
256 QAbstractItemView
* view
= itemView();
257 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
258 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
259 // selection instead of selecting all items. This is bypassed for KDE 4.0
260 // by invoking clearSelection() first.
261 view
->clearSelection();
265 void DolphinView::invertSelection()
267 if (isColumnViewActive()) {
268 // QAbstractItemView does not offer a virtual method invertSelection()
269 // as counterpart to QAbstractItemView::selectAll(). This makes it
270 // necessary to delegate the inverting of the selection to the
271 // column view, as only the selection of the active column should
273 m_columnView
->invertSelection();
275 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
276 const QAbstractItemModel
* itemModel
= selectionModel
->model();
278 const QModelIndex topLeft
= itemModel
->index(0, 0);
279 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
280 itemModel
->columnCount() - 1);
282 const QItemSelection
selection(topLeft
, bottomRight
);
283 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
287 bool DolphinView::hasSelection() const
289 return itemView()->selectionModel()->hasSelection();
292 void DolphinView::clearSelection()
294 itemView()->selectionModel()->clear();
297 KFileItemList
DolphinView::selectedItems() const
299 const QAbstractItemView
* view
= itemView();
301 // Our view has a selection, we will map them back to the DolphinModel
302 // and then fill the KFileItemList.
303 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
305 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
306 KFileItemList itemList
;
308 const QModelIndexList indexList
= selection
.indexes();
309 foreach (const QModelIndex
&index
, indexList
) {
310 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
311 if (!item
.isNull()) {
312 itemList
.append(item
);
319 KUrl::List
DolphinView::selectedUrls() const
322 const KFileItemList list
= selectedItems();
323 foreach (const KFileItem
&item
, list
) {
324 urls
.append(item
.url());
329 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
331 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
332 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
335 void DolphinView::setContentsPosition(int x
, int y
)
337 QAbstractItemView
* view
= itemView();
339 // the ColumnView takes care itself for the horizontal scrolling
340 if (!isColumnViewActive()) {
341 view
->horizontalScrollBar()->setValue(x
);
343 view
->verticalScrollBar()->setValue(y
);
345 m_loadingDirectory
= false;
348 QPoint
DolphinView::contentsPosition() const
350 const int x
= itemView()->horizontalScrollBar()->value();
351 const int y
= itemView()->verticalScrollBar()->value();
355 void DolphinView::zoomIn()
357 m_controller
->triggerZoomIn();
358 m_iconManager
->updatePreviews();
361 void DolphinView::zoomOut()
363 m_controller
->triggerZoomOut();
364 m_iconManager
->updatePreviews();
367 bool DolphinView::isZoomInPossible() const
369 return m_controller
->isZoomInPossible();
372 bool DolphinView::isZoomOutPossible() const
374 return m_controller
->isZoomOutPossible();
377 void DolphinView::setSorting(Sorting sorting
)
379 if (sorting
!= this->sorting()) {
380 updateSorting(sorting
);
384 DolphinView::Sorting
DolphinView::sorting() const
386 return m_proxyModel
->sorting();
389 void DolphinView::setSortOrder(Qt::SortOrder order
)
391 if (sortOrder() != order
) {
392 updateSortOrder(order
);
396 Qt::SortOrder
DolphinView::sortOrder() const
398 return m_proxyModel
->sortOrder();
401 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
403 const KUrl viewPropsUrl
= viewPropertiesUrl();
404 ViewProperties
props(viewPropsUrl
);
405 props
.setAdditionalInfo(info
);
406 m_fileItemDelegate
->setShowInformation(info
);
408 emit
additionalInfoChanged();
410 if (itemView() != m_detailsView
) {
411 // the details view requires no reloading of the directory, as it maps
412 // the file item delegate info to its columns internally
413 loadDirectory(viewPropsUrl
);
417 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
419 return m_fileItemDelegate
->showInformation();
422 void DolphinView::reload()
425 loadDirectory(url(), true);
428 void DolphinView::refresh()
430 const bool oldActivationState
= m_active
;
434 applyViewProperties(m_controller
->url());
437 setActive(oldActivationState
);
440 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
442 if (m_controller
->url() == url
) {
446 m_controller
->setUrl(url
); // emits urlChanged, which we forward
448 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
449 applyViewProperties(rootUrl
);
450 loadDirectory(rootUrl
);
451 if (itemView() == m_columnView
) {
452 m_columnView
->setRootUrl(rootUrl
);
453 m_columnView
->showColumn(url
);
456 applyViewProperties(url
);
460 emit
startedPathLoading(url
);
463 void DolphinView::setNameFilter(const QString
& nameFilter
)
465 m_proxyModel
->setFilterRegExp(nameFilter
);
467 if (isColumnViewActive()) {
468 // adjusting the directory lister is not enough in the case of the
469 // column view, as each column has its own directory lister internally...
470 m_columnView
->setNameFilter(nameFilter
);
474 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
476 foreach (const KFileItem
&item
, m_dirLister
->items()) {
485 void DolphinView::setUrl(const KUrl
& url
)
487 // remember current item candidate (see restoreCurrentItem())
488 m_currentItemUrl
= url
;
489 updateView(url
, KUrl());
492 void DolphinView::changeSelection(const KFileItemList
& selection
)
495 if (selection
.isEmpty()) {
498 const KUrl
& baseUrl
= url();
500 QItemSelection new_selection
;
501 foreach(const KFileItem
& item
, selection
) {
502 url
= item
.url().upUrl();
503 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
504 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
505 new_selection
.select(index
, index
);
508 itemView()->selectionModel()->select(new_selection
,
509 QItemSelectionModel::ClearAndSelect
510 | QItemSelectionModel::Current
);
513 void DolphinView::renameSelectedItems()
515 const KFileItemList items
= selectedItems();
516 if (items
.count() > 1) {
517 // More than one item has been selected for renaming. Open
518 // a rename dialog and rename all items afterwards.
519 RenameDialog
dialog(this, items
);
520 if (dialog
.exec() == QDialog::Rejected
) {
524 const QString newName
= dialog
.newName();
525 if (newName
.isEmpty()) {
526 emit
errorMessage(dialog
.errorString());
528 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
529 // as one operation instead of n rename operations like it is done now...
530 Q_ASSERT(newName
.contains('#'));
532 // iterate through all selected items and rename them...
534 foreach (const KFileItem
&item
, items
) {
535 const KUrl
& oldUrl
= item
.url();
537 number
.setNum(index
++);
539 QString name
= newName
;
540 name
.replace('#', number
);
542 if (oldUrl
.fileName() != name
) {
543 KUrl newUrl
= oldUrl
;
544 newUrl
.setFileName(name
);
545 KonqOperations::rename(this, oldUrl
, newUrl
);
546 emit
doingOperation(KIO::FileUndoManager::Rename
);
550 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
551 Q_ASSERT(items
.count() == 1);
553 if (isColumnViewActive()) {
554 m_columnView
->editItem(items
.first());
556 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
557 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
558 itemView()->edit(proxyIndex
);
561 Q_ASSERT(items
.count() == 1);
563 RenameDialog
dialog(this, items
);
564 if (dialog
.exec() == QDialog::Rejected
) {
568 const QString
& newName
= dialog
.newName();
569 if (newName
.isEmpty()) {
570 emit
errorMessage(dialog
.errorString());
572 const KUrl
& oldUrl
= items
.first().url();
573 KUrl newUrl
= oldUrl
;
574 newUrl
.setFileName(newName
);
575 KonqOperations::rename(this, oldUrl
, newUrl
);
576 emit
doingOperation(KIO::FileUndoManager::Rename
);
581 void DolphinView::trashSelectedItems()
583 emit
doingOperation(KIO::FileUndoManager::Trash
);
584 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
587 void DolphinView::deleteSelectedItems()
589 const KUrl::List list
= selectedUrls();
590 const bool del
= KonqOperations::askDeleteConfirmation(list
,
592 KonqOperations::DEFAULT_CONFIRMATION
,
596 KIO::Job
* job
= KIO::del(list
);
597 connect(job
, SIGNAL(result(KJob
*)),
598 this, SLOT(slotDeleteFileFinished(KJob
*)));
602 void DolphinView::cutSelectedItems()
604 QMimeData
* mimeData
= new QMimeData();
605 const KUrl::List kdeUrls
= selectedUrls();
606 const KUrl::List mostLocalUrls
;
607 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
608 QApplication::clipboard()->setMimeData(mimeData
);
611 void DolphinView::copySelectedItems()
613 QMimeData
* mimeData
= new QMimeData();
614 const KUrl::List kdeUrls
= selectedUrls();
615 const KUrl::List mostLocalUrls
;
616 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
617 QApplication::clipboard()->setMimeData(mimeData
);
620 void DolphinView::paste()
625 void DolphinView::pasteIntoFolder()
627 const KFileItemList items
= selectedItems();
628 if ((items
.count() == 1) && items
.first().isDir()) {
629 pasteToUrl(items
.first().url());
633 void DolphinView::setShowPreview(bool show
)
635 if (m_showPreview
== show
) {
639 const KUrl viewPropsUrl
= viewPropertiesUrl();
640 ViewProperties
props(viewPropsUrl
);
641 props
.setShowPreview(show
);
643 m_showPreview
= show
;
644 m_iconManager
->setShowPreview(show
);
645 emit
showPreviewChanged();
647 loadDirectory(viewPropsUrl
);
650 void DolphinView::setShowHiddenFiles(bool show
)
652 if (m_dirLister
->showingDotFiles() == show
) {
656 const KUrl viewPropsUrl
= viewPropertiesUrl();
657 ViewProperties
props(viewPropsUrl
);
658 props
.setShowHiddenFiles(show
);
660 m_dirLister
->setShowingDotFiles(show
);
661 emit
showHiddenFilesChanged();
663 loadDirectory(viewPropsUrl
);
666 void DolphinView::setCategorizedSorting(bool categorized
)
668 if (categorized
== categorizedSorting()) {
672 // setCategorizedSorting(true) may only get invoked
673 // if the view supports categorized sorting
674 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
676 ViewProperties
props(viewPropertiesUrl());
677 props
.setCategorizedSorting(categorized
);
680 m_storedCategorizedSorting
= categorized
;
681 m_proxyModel
->setCategorizedModel(categorized
);
683 emit
categorizedSortingChanged();
686 void DolphinView::toggleSortOrder()
688 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
689 Qt::DescendingOrder
:
694 void DolphinView::toggleAdditionalInfo(QAction
* action
)
696 const KFileItemDelegate::Information info
=
697 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
699 KFileItemDelegate::InformationList list
= additionalInfo();
701 const bool show
= action
->isChecked();
703 const int index
= list
.indexOf(info
);
704 const bool containsInfo
= (index
>= 0);
705 if (show
&& !containsInfo
) {
707 setAdditionalInfo(list
);
708 } else if (!show
&& containsInfo
) {
709 list
.removeAt(index
);
710 setAdditionalInfo(list
);
711 Q_ASSERT(list
.indexOf(info
) < 0);
716 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
718 QWidget::mouseReleaseEvent(event
);
722 void DolphinView::wheelEvent(QWheelEvent
* event
)
724 if (event
->modifiers() & Qt::ControlModifier
) {
725 const int delta
= event
->delta();
726 if ((delta
> 0) && isZoomInPossible()) {
728 } else if ((delta
< 0) && isZoomOutPossible()) {
735 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
737 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
738 m_controller
->requestActivation();
741 return QWidget::eventFilter(watched
, event
);
744 void DolphinView::activate()
749 void DolphinView::triggerItem(const KFileItem
& item
)
751 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
752 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
753 // items are selected by the user, hence don't trigger the
754 // item specified by 'index'
758 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
759 if (item
.isNull() || m_isContextMenuOpen
) {
763 if (m_toolTipManager
!= 0) {
764 m_toolTipManager
->hideTip();
766 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
769 void DolphinView::emitSelectionChangedSignal()
771 emit
selectionChanged(DolphinView::selectedItems());
774 void DolphinView::openContextMenu(const QPoint
& pos
)
778 const QModelIndex index
= itemView()->indexAt(pos
);
779 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
780 item
= fileItem(index
);
783 if (m_toolTipManager
!= 0) {
784 m_toolTipManager
->hideTip();
787 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
788 emit
requestContextMenu(item
, url());
789 m_isContextMenuOpen
= false;
792 void DolphinView::dropUrls(const KUrl::List
& urls
,
793 const KUrl
& destPath
,
794 const KFileItem
& destItem
)
796 Q_ASSERT(!urls
.isEmpty());
797 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
798 destItem
.url() : destPath
;
799 const KUrl sourceDir
= KUrl(urls
.first().directory());
800 if (sourceDir
!= destination
) {
801 dropUrls(urls
, destination
);
805 void DolphinView::dropUrls(const KUrl::List
& urls
,
806 const KUrl
& destination
)
808 DolphinDropController
dropController(this);
809 // forward doingOperation signal up to the mainwindow
810 connect(&dropController
, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)),
811 this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)));
812 dropController
.dropUrls(urls
, destination
);
815 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
817 ViewProperties
props(viewPropertiesUrl());
818 props
.setSorting(sorting
);
820 m_proxyModel
->setSorting(sorting
);
822 emit
sortingChanged(sorting
);
825 void DolphinView::updateSortOrder(Qt::SortOrder order
)
827 ViewProperties
props(viewPropertiesUrl());
828 props
.setSortOrder(order
);
830 m_proxyModel
->setSortOrder(order
);
832 emit
sortOrderChanged(order
);
835 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
837 ViewProperties
props(viewPropertiesUrl());
838 props
.setAdditionalInfo(info
);
841 m_fileItemDelegate
->setShowInformation(info
);
843 emit
additionalInfoChanged();
846 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
848 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
849 (m_mode
== DolphinView::IconsView
);
851 QAction
* showSizeInfo
= collection
->action("show_size_info");
852 QAction
* showDateInfo
= collection
->action("show_date_info");
853 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
854 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
855 QAction
* showGroupInfo
= collection
->action("show_group_info");
856 QAction
* showMimeInfo
= collection
->action("show_mime_info");
858 showSizeInfo
->setChecked(false);
859 showDateInfo
->setChecked(false);
860 showPermissionsInfo
->setChecked(false);
861 showOwnerInfo
->setChecked(false);
862 showGroupInfo
->setChecked(false);
863 showMimeInfo
->setChecked(false);
865 showSizeInfo
->setEnabled(enable
);
866 showDateInfo
->setEnabled(enable
);
867 showPermissionsInfo
->setEnabled(enable
);
868 showOwnerInfo
->setEnabled(enable
);
869 showGroupInfo
->setEnabled(enable
);
870 showMimeInfo
->setEnabled(enable
);
872 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
874 case KFileItemDelegate::Size
:
875 showSizeInfo
->setChecked(true);
877 case KFileItemDelegate::ModificationTime
:
878 showDateInfo
->setChecked(true);
880 case KFileItemDelegate::Permissions
:
881 showPermissionsInfo
->setChecked(true);
883 case KFileItemDelegate::Owner
:
884 showOwnerInfo
->setChecked(true);
886 case KFileItemDelegate::OwnerAndGroup
:
887 showGroupInfo
->setChecked(true);
889 case KFileItemDelegate::FriendlyMimeType
:
890 showMimeInfo
->setChecked(true);
898 QPair
<bool, QString
> DolphinView::pasteInfo() const
900 QPair
<bool, QString
> ret
;
901 QClipboard
* clipboard
= QApplication::clipboard();
902 const QMimeData
* mimeData
= clipboard
->mimeData();
904 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
905 if (!urls
.isEmpty()) {
907 if (urls
.count() == 1) {
908 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
909 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
910 i18nc("@action:inmenu", "Paste One File");
913 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
917 ret
.second
= i18nc("@action:inmenu", "Paste");
923 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
925 m_tabsForFiles
= tabsForFiles
;
928 bool DolphinView::isTabsForFilesEnabled() const
930 return m_tabsForFiles
;
933 void DolphinView::emitContentsMoved()
935 // only emit the contents moved signal if:
936 // - no directory loading is ongoing (this would reset the contents position
938 // - if the Column View is active: the column view does an automatic
939 // positioning during the loading operation, which must be remembered
940 if (!m_loadingDirectory
|| isColumnViewActive()) {
941 const QPoint
pos(contentsPosition());
942 emit
contentsMoved(pos
.x(), pos
.y());
946 void DolphinView::showHoverInformation(const KFileItem
& item
)
948 emit
requestItemInfo(item
);
951 void DolphinView::clearHoverInformation()
953 emit
requestItemInfo(KFileItem());
956 void DolphinView::slotDeleteFileFinished(KJob
* job
)
958 if (job
->error() == 0) {
959 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
961 emit
errorMessage(job
->errorString());
966 void DolphinView::restoreCurrentItem()
968 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
969 if (dirIndex
.isValid()) {
970 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
971 QAbstractItemView
* view
= itemView();
972 const bool clearSelection
= !hasSelection();
973 view
->setCurrentIndex(proxyIndex
);
974 if (clearSelection
) {
975 view
->clearSelection();
980 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
982 if (!url
.isValid()) {
983 const QString
location(url
.pathOrUrl());
984 if (location
.isEmpty()) {
985 emit
errorMessage(i18nc("@info:status", "The location is empty."));
987 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
992 m_loadingDirectory
= true;
995 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
997 if (isColumnViewActive()) {
998 // adjusting the directory lister is not enough in the case of the
999 // column view, as each column has its own directory lister internally...
1001 m_columnView
->reload();
1003 m_columnView
->showColumn(url
);
1008 KUrl
DolphinView::viewPropertiesUrl() const
1010 if (isColumnViewActive()) {
1011 return m_columnView
->rootUrl();
1017 void DolphinView::applyViewProperties(const KUrl
& url
)
1019 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1020 // The column view is active, hence don't apply the view properties
1021 // of sub directories (represented by columns) to the view. The
1022 // view always represents the properties of the first column.
1026 const ViewProperties
props(url
);
1028 const Mode mode
= props
.viewMode();
1029 if (m_mode
!= mode
) {
1034 if (itemView() == 0) {
1037 Q_ASSERT(itemView() != 0);
1038 Q_ASSERT(m_fileItemDelegate
!= 0);
1040 const bool showHiddenFiles
= props
.showHiddenFiles();
1041 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1042 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1043 emit
showHiddenFilesChanged();
1046 m_storedCategorizedSorting
= props
.categorizedSorting();
1047 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1048 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1049 m_proxyModel
->setCategorizedModel(categorized
);
1050 emit
categorizedSortingChanged();
1053 const DolphinView::Sorting sorting
= props
.sorting();
1054 if (sorting
!= m_proxyModel
->sorting()) {
1055 m_proxyModel
->setSorting(sorting
);
1056 emit
sortingChanged(sorting
);
1059 const Qt::SortOrder sortOrder
= props
.sortOrder();
1060 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1061 m_proxyModel
->setSortOrder(sortOrder
);
1062 emit
sortOrderChanged(sortOrder
);
1065 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1066 if (info
!= m_fileItemDelegate
->showInformation()) {
1067 m_fileItemDelegate
->setShowInformation(info
);
1068 emit
additionalInfoChanged();
1071 const bool showPreview
= props
.showPreview();
1072 if (showPreview
!= m_showPreview
) {
1073 m_showPreview
= showPreview
;
1074 m_iconManager
->setShowPreview(showPreview
);
1075 emit
showPreviewChanged();
1079 void DolphinView::createView()
1082 Q_ASSERT(m_iconsView
== 0);
1083 Q_ASSERT(m_detailsView
== 0);
1084 Q_ASSERT(m_columnView
== 0);
1086 QAbstractItemView
* view
= 0;
1089 m_iconsView
= new DolphinIconsView(this, m_controller
);
1095 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1096 view
= m_detailsView
;
1100 m_columnView
= new DolphinColumnView(this, m_controller
);
1101 view
= m_columnView
;
1105 Q_ASSERT(view
!= 0);
1106 view
->installEventFilter(this);
1108 m_controller
->setItemView(view
);
1110 m_fileItemDelegate
= new KFileItemDelegate(view
);
1111 view
->setItemDelegate(m_fileItemDelegate
);
1113 view
->setModel(m_proxyModel
);
1114 if (m_selectionModel
!= 0) {
1115 view
->setSelectionModel(m_selectionModel
);
1117 m_selectionModel
= view
->selectionModel();
1120 // reparent the selection model, as it should not be deleted
1121 // when deleting the model
1122 m_selectionModel
->setParent(this);
1124 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1126 new KMimeTypeResolver(view
, m_dolphinModel
);
1127 m_iconManager
= new IconManager(view
, m_proxyModel
);
1128 m_iconManager
->setShowPreview(m_showPreview
);
1130 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1131 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1134 m_topLayout
->insertWidget(1, view
);
1136 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1137 this, SLOT(emitSelectionChangedSignal()));
1138 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1139 this, SLOT(emitContentsMoved()));
1140 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1141 this, SLOT(emitContentsMoved()));
1144 void DolphinView::deleteView()
1146 QAbstractItemView
* view
= itemView();
1148 m_topLayout
->removeWidget(view
);
1150 view
->deleteLater();
1155 m_fileItemDelegate
= 0;
1157 m_toolTipManager
= 0;
1161 QAbstractItemView
* DolphinView::itemView() const
1163 if (m_detailsView
!= 0) {
1164 return m_detailsView
;
1165 } else if (m_columnView
!= 0) {
1166 return m_columnView
;
1172 bool DolphinView::isCutItem(const KFileItem
& item
) const
1174 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1175 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1177 const KUrl
& itemUrl
= item
.url();
1178 KUrl::List::const_iterator it
= cutUrls
.begin();
1179 const KUrl::List::const_iterator end
= cutUrls
.end();
1181 if (*it
== itemUrl
) {
1190 void DolphinView::pasteToUrl(const KUrl
& url
)
1192 QClipboard
* clipboard
= QApplication::clipboard();
1193 const QMimeData
* mimeData
= clipboard
->mimeData();
1195 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1196 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1197 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1198 emit
doingOperation(KIO::FileUndoManager::Move
);
1201 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1202 emit
doingOperation(KIO::FileUndoManager::Copy
);
1206 #include "dolphinview.moc"