1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinview.h"
23 #include <QApplication>
26 #include <QItemSelection>
31 #include <kactioncollection.h>
32 #include <kcolorscheme.h>
33 #include <kdirlister.h>
34 #include <kfileitemdelegate.h>
35 #include <kiconeffect.h>
37 #include <kio/deletejob.h>
38 #include <kio/netaccess.h>
39 #include <kio/previewjob.h>
42 #include <kmessagebox.h>
43 #include <kmimetyperesolver.h>
44 #include <konq_operations.h>
45 #include <konqmimedata.h>
46 #include <ktoggleaction.h>
49 #include "dolphindropcontroller.h"
50 #include "dolphinmodel.h"
51 #include "dolphincolumnview.h"
52 #include "dolphincontroller.h"
53 #include "dolphinsortfilterproxymodel.h"
54 #include "dolphindetailsview.h"
55 #include "dolphiniconsview.h"
56 #include "dolphinsettings.h"
57 #include "dolphin_generalsettings.h"
58 #include "iconmanager.h"
59 #include "renamedialog.h"
60 #include "tooltipmanager.h"
61 #include "viewproperties.h"
63 DolphinView::DolphinView(QWidget
* parent
,
65 KDirLister
* dirLister
,
66 DolphinModel
* dolphinModel
,
67 DolphinSortFilterProxyModel
* proxyModel
) :
71 m_loadingDirectory(false),
72 m_storedCategorizedSorting(false),
73 m_tabsForFiles(false),
74 m_isContextMenuOpen(false),
75 m_mode(DolphinView::IconsView
),
81 m_fileItemDelegate(0),
83 m_dolphinModel(dolphinModel
),
84 m_dirLister(dirLister
),
85 m_proxyModel(proxyModel
),
89 m_topLayout
= new QVBoxLayout(this);
90 m_topLayout
->setSpacing(0);
91 m_topLayout
->setMargin(0);
93 m_controller
= new DolphinController(this);
94 m_controller
->setUrl(url
);
96 // Receiver of the DolphinView signal 'urlChanged()' don't need
97 // to care whether the internal controller changed the URL already or whether
98 // the controller just requested an URL change and will be updated later.
99 // In both cases the URL has been changed:
100 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
101 this, SIGNAL(urlChanged(const KUrl
&)));
102 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
103 this, SIGNAL(urlChanged(const KUrl
&)));
105 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
106 this, SLOT(openContextMenu(const QPoint
&)));
107 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
108 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
109 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
110 this, SLOT(updateSorting(DolphinView::Sorting
)));
111 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
112 this, SLOT(updateSortOrder(Qt::SortOrder
)));
113 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
114 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
115 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
116 this, SLOT(triggerItem(const KFileItem
&)));
117 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
118 this, SIGNAL(tabRequested(const KUrl
&)));
119 connect(m_controller
, SIGNAL(activated()),
120 this, SLOT(activate()));
121 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
122 this, SLOT(showHoverInformation(const KFileItem
&)));
123 connect(m_controller
, SIGNAL(viewportEntered()),
124 this, SLOT(clearHoverInformation()));
126 applyViewProperties(url
);
127 m_topLayout
->addWidget(itemView());
130 DolphinView::~DolphinView()
134 const KUrl
& DolphinView::url() const
136 return m_controller
->url();
139 KUrl
DolphinView::rootUrl() const
141 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
144 void DolphinView::setActive(bool active
)
146 if (active
== m_active
) {
151 m_selectionModel
->clearSelection();
153 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
155 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
156 // bypasses the problem when having a split view and changing the active view to
157 // update the some URL dependent states. A nicer approach should be no big deal...
158 emit
urlChanged(url());
159 emit
selectionChanged(selectedItems());
164 QWidget
* viewport
= itemView()->viewport();
166 palette
.setColor(viewport
->backgroundRole(), color
);
167 viewport
->setPalette(palette
);
175 m_controller
->indicateActivationChange(active
);
178 bool DolphinView::isActive() const
183 void DolphinView::setMode(Mode mode
)
185 if (mode
== m_mode
) {
186 return; // the wished mode is already set
193 const KUrl viewPropsUrl
= viewPropertiesUrl();
194 ViewProperties
props(viewPropsUrl
);
195 props
.setViewMode(m_mode
);
198 // the file item delegate has been recreated, apply the current
199 // additional information manually
200 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
201 m_fileItemDelegate
->setShowInformation(infoList
);
202 emit
additionalInfoChanged();
204 // Not all view modes support categorized sorting. Adjust the sorting model
205 // if changing the view mode results in a change of the categorized sorting
207 m_storedCategorizedSorting
= props
.categorizedSorting();
208 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
209 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
210 m_proxyModel
->setCategorizedModel(categorized
);
211 emit
categorizedSortingChanged();
217 DolphinView::Mode
DolphinView::mode() const
222 bool DolphinView::showPreview() const
224 return m_showPreview
;
227 bool DolphinView::showHiddenFiles() const
229 return m_dirLister
->showingDotFiles();
232 bool DolphinView::categorizedSorting() const
234 // If all view modes would support categorized sorting, returning
235 // m_proxyModel->isCategorizedModel() would be the way to go. As
236 // currently only the icons view supports caterized sorting, we remember
237 // the stored view properties state in m_storedCategorizedSorting and
238 // return this state. The application takes care to disable the corresponding
239 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
240 // that this setting is not applied to the current view mode.
241 return m_storedCategorizedSorting
;
244 bool DolphinView::supportsCategorizedSorting() const
246 return m_iconsView
!= 0;
249 void DolphinView::selectAll()
251 QAbstractItemView
* view
= itemView();
252 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
253 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
254 // selection instead of selecting all items. This is bypassed for KDE 4.0
255 // by invoking clearSelection() first.
256 view
->clearSelection();
260 void DolphinView::invertSelection()
262 if (isColumnViewActive()) {
263 // QAbstractItemView does not offer a virtual method invertSelection()
264 // as counterpart to QAbstractItemView::selectAll(). This makes it
265 // necessary to delegate the inverting of the selection to the
266 // column view, as only the selection of the active column should
268 m_columnView
->invertSelection();
270 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
271 const QAbstractItemModel
* itemModel
= selectionModel
->model();
273 const QModelIndex topLeft
= itemModel
->index(0, 0);
274 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
275 itemModel
->columnCount() - 1);
277 const QItemSelection
selection(topLeft
, bottomRight
);
278 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
282 bool DolphinView::hasSelection() const
284 return itemView()->selectionModel()->hasSelection();
287 void DolphinView::clearSelection()
289 itemView()->selectionModel()->clear();
292 KFileItemList
DolphinView::selectedItems() const
294 const QAbstractItemView
* view
= itemView();
296 // Our view has a selection, we will map them back to the DolphinModel
297 // and then fill the KFileItemList.
298 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
300 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
301 KFileItemList itemList
;
303 const QModelIndexList indexList
= selection
.indexes();
304 foreach (const QModelIndex
&index
, indexList
) {
305 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
306 if (!item
.isNull()) {
307 itemList
.append(item
);
314 KUrl::List
DolphinView::selectedUrls() const
317 const KFileItemList list
= selectedItems();
318 foreach (const KFileItem
&item
, list
) {
319 urls
.append(item
.url());
324 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
326 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
327 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
330 void DolphinView::setContentsPosition(int x
, int y
)
332 QAbstractItemView
* view
= itemView();
334 // the ColumnView takes care itself for the horizontal scrolling
335 if (!isColumnViewActive()) {
336 view
->horizontalScrollBar()->setValue(x
);
338 view
->verticalScrollBar()->setValue(y
);
340 m_loadingDirectory
= false;
343 QPoint
DolphinView::contentsPosition() const
345 const int x
= itemView()->horizontalScrollBar()->value();
346 const int y
= itemView()->verticalScrollBar()->value();
350 void DolphinView::zoomIn()
352 m_controller
->triggerZoomIn();
353 m_iconManager
->updatePreviews();
356 void DolphinView::zoomOut()
358 m_controller
->triggerZoomOut();
359 m_iconManager
->updatePreviews();
362 bool DolphinView::isZoomInPossible() const
364 return m_controller
->isZoomInPossible();
367 bool DolphinView::isZoomOutPossible() const
369 return m_controller
->isZoomOutPossible();
372 void DolphinView::setSorting(Sorting sorting
)
374 if (sorting
!= this->sorting()) {
375 updateSorting(sorting
);
379 DolphinView::Sorting
DolphinView::sorting() const
381 return m_proxyModel
->sorting();
384 void DolphinView::setSortOrder(Qt::SortOrder order
)
386 if (sortOrder() != order
) {
387 updateSortOrder(order
);
391 Qt::SortOrder
DolphinView::sortOrder() const
393 return m_proxyModel
->sortOrder();
396 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
398 const KUrl viewPropsUrl
= viewPropertiesUrl();
399 ViewProperties
props(viewPropsUrl
);
400 props
.setAdditionalInfo(info
);
401 m_fileItemDelegate
->setShowInformation(info
);
403 emit
additionalInfoChanged();
405 if (itemView() != m_detailsView
) {
406 // the details view requires no reloading of the directory, as it maps
407 // the file item delegate info to its columns internally
408 loadDirectory(viewPropsUrl
);
412 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
414 return m_fileItemDelegate
->showInformation();
417 void DolphinView::reload()
420 loadDirectory(url(), true);
423 void DolphinView::refresh()
425 const bool oldActivationState
= m_active
;
429 applyViewProperties(m_controller
->url());
432 setActive(oldActivationState
);
435 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
437 if (m_controller
->url() == url
) {
441 m_controller
->setUrl(url
); // emits urlChanged, which we forward
443 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
444 applyViewProperties(rootUrl
);
445 loadDirectory(rootUrl
);
446 if (itemView() == m_columnView
) {
447 m_columnView
->setRootUrl(rootUrl
);
448 m_columnView
->showColumn(url
);
451 applyViewProperties(url
);
455 emit
startedPathLoading(url
);
458 void DolphinView::setNameFilter(const QString
& nameFilter
)
460 m_proxyModel
->setFilterRegExp(nameFilter
);
462 if (isColumnViewActive()) {
463 // adjusting the directory lister is not enough in the case of the
464 // column view, as each column has its own directory lister internally...
465 m_columnView
->setNameFilter(nameFilter
);
469 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
471 foreach (const KFileItem
&item
, m_dirLister
->items()) {
480 void DolphinView::setUrl(const KUrl
& url
)
482 updateView(url
, KUrl());
485 void DolphinView::changeSelection(const KFileItemList
& selection
)
488 if (selection
.isEmpty()) {
491 const KUrl
& baseUrl
= url();
493 QItemSelection new_selection
;
494 foreach(const KFileItem
& item
, selection
) {
495 url
= item
.url().upUrl();
496 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
497 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
498 new_selection
.select(index
, index
);
501 itemView()->selectionModel()->select(new_selection
,
502 QItemSelectionModel::ClearAndSelect
503 | QItemSelectionModel::Current
);
506 void DolphinView::renameSelectedItems()
508 const KFileItemList items
= selectedItems();
509 if (items
.count() > 1) {
510 // More than one item has been selected for renaming. Open
511 // a rename dialog and rename all items afterwards.
512 RenameDialog
dialog(this, items
);
513 if (dialog
.exec() == QDialog::Rejected
) {
517 const QString newName
= dialog
.newName();
518 if (newName
.isEmpty()) {
519 emit
errorMessage(dialog
.errorString());
521 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
522 // as one operation instead of n rename operations like it is done now...
523 Q_ASSERT(newName
.contains('#'));
525 // iterate through all selected items and rename them...
527 foreach (const KFileItem
&item
, items
) {
528 const KUrl
& oldUrl
= item
.url();
530 number
.setNum(index
++);
532 QString name
= newName
;
533 name
.replace('#', number
);
535 if (oldUrl
.fileName() != name
) {
536 KUrl newUrl
= oldUrl
;
537 newUrl
.setFileName(name
);
538 KonqOperations::rename(this, oldUrl
, newUrl
);
539 emit
doingOperation(KIO::FileUndoManager::Rename
);
543 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
544 Q_ASSERT(items
.count() == 1);
546 if (isColumnViewActive()) {
547 m_columnView
->editItem(items
.first());
549 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
550 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
551 itemView()->edit(proxyIndex
);
554 Q_ASSERT(items
.count() == 1);
556 RenameDialog
dialog(this, items
);
557 if (dialog
.exec() == QDialog::Rejected
) {
561 const QString
& newName
= dialog
.newName();
562 if (newName
.isEmpty()) {
563 emit
errorMessage(dialog
.errorString());
565 const KUrl
& oldUrl
= items
.first().url();
566 KUrl newUrl
= oldUrl
;
567 newUrl
.setFileName(newName
);
568 KonqOperations::rename(this, oldUrl
, newUrl
);
569 emit
doingOperation(KIO::FileUndoManager::Rename
);
574 void DolphinView::trashSelectedItems()
576 emit
doingOperation(KIO::FileUndoManager::Trash
);
577 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
580 void DolphinView::deleteSelectedItems()
582 const KUrl::List list
= selectedUrls();
583 const bool del
= KonqOperations::askDeleteConfirmation(list
,
585 KonqOperations::DEFAULT_CONFIRMATION
,
589 KIO::Job
* job
= KIO::del(list
);
590 connect(job
, SIGNAL(result(KJob
*)),
591 this, SLOT(slotDeleteFileFinished(KJob
*)));
595 void DolphinView::cutSelectedItems()
597 QMimeData
* mimeData
= new QMimeData();
598 const KUrl::List kdeUrls
= selectedUrls();
599 const KUrl::List mostLocalUrls
;
600 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
601 QApplication::clipboard()->setMimeData(mimeData
);
604 void DolphinView::copySelectedItems()
606 QMimeData
* mimeData
= new QMimeData();
607 const KUrl::List kdeUrls
= selectedUrls();
608 const KUrl::List mostLocalUrls
;
609 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
610 QApplication::clipboard()->setMimeData(mimeData
);
613 void DolphinView::paste()
618 void DolphinView::pasteIntoFolder()
620 const KFileItemList items
= selectedItems();
621 if ((items
.count() == 1) && items
.first().isDir()) {
622 pasteToUrl(items
.first().url());
626 void DolphinView::setShowPreview(bool show
)
628 if (m_showPreview
== show
) {
632 const KUrl viewPropsUrl
= viewPropertiesUrl();
633 ViewProperties
props(viewPropsUrl
);
634 props
.setShowPreview(show
);
636 m_showPreview
= show
;
637 m_iconManager
->setShowPreview(show
);
638 emit
showPreviewChanged();
640 loadDirectory(viewPropsUrl
);
643 void DolphinView::setShowHiddenFiles(bool show
)
645 if (m_dirLister
->showingDotFiles() == show
) {
649 const KUrl viewPropsUrl
= viewPropertiesUrl();
650 ViewProperties
props(viewPropsUrl
);
651 props
.setShowHiddenFiles(show
);
653 m_dirLister
->setShowingDotFiles(show
);
654 emit
showHiddenFilesChanged();
656 loadDirectory(viewPropsUrl
);
659 void DolphinView::setCategorizedSorting(bool categorized
)
661 if (categorized
== categorizedSorting()) {
665 // setCategorizedSorting(true) may only get invoked
666 // if the view supports categorized sorting
667 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
669 ViewProperties
props(viewPropertiesUrl());
670 props
.setCategorizedSorting(categorized
);
673 m_storedCategorizedSorting
= categorized
;
674 m_proxyModel
->setCategorizedModel(categorized
);
676 emit
categorizedSortingChanged();
679 void DolphinView::toggleSortOrder()
681 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
682 Qt::DescendingOrder
:
687 void DolphinView::toggleAdditionalInfo(QAction
* action
)
689 const KFileItemDelegate::Information info
=
690 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
692 KFileItemDelegate::InformationList list
= additionalInfo();
694 const bool show
= action
->isChecked();
696 const int index
= list
.indexOf(info
);
697 const bool containsInfo
= (index
>= 0);
698 if (show
&& !containsInfo
) {
700 setAdditionalInfo(list
);
701 } else if (!show
&& containsInfo
) {
702 list
.removeAt(index
);
703 setAdditionalInfo(list
);
704 Q_ASSERT(list
.indexOf(info
) < 0);
709 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
711 QWidget::mouseReleaseEvent(event
);
715 void DolphinView::wheelEvent(QWheelEvent
* event
)
717 if (event
->modifiers() & Qt::ControlModifier
) {
718 const int delta
= event
->delta();
719 if ((delta
> 0) && isZoomInPossible()) {
721 } else if ((delta
< 0) && isZoomOutPossible()) {
728 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
730 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
731 m_controller
->requestActivation();
734 return QWidget::eventFilter(watched
, event
);
737 void DolphinView::activate()
742 void DolphinView::triggerItem(const KFileItem
& item
)
744 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
745 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
746 // items are selected by the user, hence don't trigger the
747 // item specified by 'index'
751 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
752 if (item
.isNull() || m_isContextMenuOpen
) {
756 if (m_toolTipManager
!= 0) {
757 m_toolTipManager
->hideTip();
759 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
762 void DolphinView::emitSelectionChangedSignal()
764 emit
selectionChanged(DolphinView::selectedItems());
767 void DolphinView::openContextMenu(const QPoint
& pos
)
771 const QModelIndex index
= itemView()->indexAt(pos
);
772 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
773 item
= fileItem(index
);
776 if (m_toolTipManager
!= 0) {
777 m_toolTipManager
->hideTip();
780 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
781 emit
requestContextMenu(item
, url());
782 m_isContextMenuOpen
= false;
785 void DolphinView::dropUrls(const KUrl::List
& urls
,
786 const KUrl
& destPath
,
787 const KFileItem
& destItem
)
789 Q_ASSERT(!urls
.isEmpty());
790 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
791 destItem
.url() : destPath
;
792 const KUrl sourceDir
= KUrl(urls
.first().directory());
793 if (sourceDir
!= destination
) {
794 dropUrls(urls
, destination
);
798 void DolphinView::dropUrls(const KUrl::List
& urls
,
799 const KUrl
& destination
)
801 DolphinDropController
dropController(this);
802 // forward doingOperation signal up to the mainwindow
803 connect(&dropController
, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)),
804 this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)));
805 dropController
.dropUrls(urls
, destination
);
808 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
810 ViewProperties
props(viewPropertiesUrl());
811 props
.setSorting(sorting
);
813 m_proxyModel
->setSorting(sorting
);
815 emit
sortingChanged(sorting
);
818 void DolphinView::updateSortOrder(Qt::SortOrder order
)
820 ViewProperties
props(viewPropertiesUrl());
821 props
.setSortOrder(order
);
823 m_proxyModel
->setSortOrder(order
);
825 emit
sortOrderChanged(order
);
828 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
830 ViewProperties
props(viewPropertiesUrl());
831 props
.setAdditionalInfo(info
);
834 m_fileItemDelegate
->setShowInformation(info
);
836 emit
additionalInfoChanged();
839 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
841 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
842 (m_mode
== DolphinView::IconsView
);
844 QAction
* showSizeInfo
= collection
->action("show_size_info");
845 QAction
* showDateInfo
= collection
->action("show_date_info");
846 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
847 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
848 QAction
* showGroupInfo
= collection
->action("show_group_info");
849 QAction
* showMimeInfo
= collection
->action("show_mime_info");
851 showSizeInfo
->setChecked(false);
852 showDateInfo
->setChecked(false);
853 showPermissionsInfo
->setChecked(false);
854 showOwnerInfo
->setChecked(false);
855 showGroupInfo
->setChecked(false);
856 showMimeInfo
->setChecked(false);
858 showSizeInfo
->setEnabled(enable
);
859 showDateInfo
->setEnabled(enable
);
860 showPermissionsInfo
->setEnabled(enable
);
861 showOwnerInfo
->setEnabled(enable
);
862 showGroupInfo
->setEnabled(enable
);
863 showMimeInfo
->setEnabled(enable
);
865 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
867 case KFileItemDelegate::Size
:
868 showSizeInfo
->setChecked(true);
870 case KFileItemDelegate::ModificationTime
:
871 showDateInfo
->setChecked(true);
873 case KFileItemDelegate::Permissions
:
874 showPermissionsInfo
->setChecked(true);
876 case KFileItemDelegate::Owner
:
877 showOwnerInfo
->setChecked(true);
879 case KFileItemDelegate::OwnerAndGroup
:
880 showGroupInfo
->setChecked(true);
882 case KFileItemDelegate::FriendlyMimeType
:
883 showMimeInfo
->setChecked(true);
891 QPair
<bool, QString
> DolphinView::pasteInfo() const
893 QPair
<bool, QString
> ret
;
894 QClipboard
* clipboard
= QApplication::clipboard();
895 const QMimeData
* mimeData
= clipboard
->mimeData();
897 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
898 if (!urls
.isEmpty()) {
900 if (urls
.count() == 1) {
901 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
902 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
903 i18nc("@action:inmenu", "Paste One File");
906 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
910 ret
.second
= i18nc("@action:inmenu", "Paste");
916 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
918 m_tabsForFiles
= tabsForFiles
;
921 bool DolphinView::isTabsForFilesEnabled() const
923 return m_tabsForFiles
;
926 void DolphinView::emitContentsMoved()
928 // only emit the contents moved signal if:
929 // - no directory loading is ongoing (this would reset the contents position
931 // - if the Column View is active: the column view does an automatic
932 // positioning during the loading operation, which must be remembered
933 if (!m_loadingDirectory
|| isColumnViewActive()) {
934 const QPoint
pos(contentsPosition());
935 emit
contentsMoved(pos
.x(), pos
.y());
939 void DolphinView::showHoverInformation(const KFileItem
& item
)
941 emit
requestItemInfo(item
);
944 void DolphinView::clearHoverInformation()
946 emit
requestItemInfo(KFileItem());
949 void DolphinView::slotDeleteFileFinished(KJob
* job
)
951 if (job
->error() == 0) {
952 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
954 emit
errorMessage(job
->errorString());
958 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
960 if (!url
.isValid()) {
961 const QString
location(url
.pathOrUrl());
962 if (location
.isEmpty()) {
963 emit
errorMessage(i18nc("@info:status", "The location is empty."));
965 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
970 m_loadingDirectory
= true;
973 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
975 if (isColumnViewActive()) {
976 // adjusting the directory lister is not enough in the case of the
977 // column view, as each column has its own directory lister internally...
979 m_columnView
->reload();
981 m_columnView
->showColumn(url
);
986 KUrl
DolphinView::viewPropertiesUrl() const
988 if (isColumnViewActive()) {
989 return m_columnView
->rootUrl();
995 void DolphinView::applyViewProperties(const KUrl
& url
)
997 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
998 // The column view is active, hence don't apply the view properties
999 // of sub directories (represented by columns) to the view. The
1000 // view always represents the properties of the first column.
1004 const ViewProperties
props(url
);
1006 const Mode mode
= props
.viewMode();
1007 if (m_mode
!= mode
) {
1012 if (itemView() == 0) {
1015 Q_ASSERT(itemView() != 0);
1016 Q_ASSERT(m_fileItemDelegate
!= 0);
1018 const bool showHiddenFiles
= props
.showHiddenFiles();
1019 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1020 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1021 emit
showHiddenFilesChanged();
1024 m_storedCategorizedSorting
= props
.categorizedSorting();
1025 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1026 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1027 m_proxyModel
->setCategorizedModel(categorized
);
1028 emit
categorizedSortingChanged();
1031 const DolphinView::Sorting sorting
= props
.sorting();
1032 if (sorting
!= m_proxyModel
->sorting()) {
1033 m_proxyModel
->setSorting(sorting
);
1034 emit
sortingChanged(sorting
);
1037 const Qt::SortOrder sortOrder
= props
.sortOrder();
1038 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1039 m_proxyModel
->setSortOrder(sortOrder
);
1040 emit
sortOrderChanged(sortOrder
);
1043 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1044 if (info
!= m_fileItemDelegate
->showInformation()) {
1045 m_fileItemDelegate
->setShowInformation(info
);
1046 emit
additionalInfoChanged();
1049 const bool showPreview
= props
.showPreview();
1050 if (showPreview
!= m_showPreview
) {
1051 m_showPreview
= showPreview
;
1052 m_iconManager
->setShowPreview(showPreview
);
1053 emit
showPreviewChanged();
1057 void DolphinView::createView()
1060 Q_ASSERT(m_iconsView
== 0);
1061 Q_ASSERT(m_detailsView
== 0);
1062 Q_ASSERT(m_columnView
== 0);
1064 QAbstractItemView
* view
= 0;
1067 m_iconsView
= new DolphinIconsView(this, m_controller
);
1073 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1074 view
= m_detailsView
;
1078 m_columnView
= new DolphinColumnView(this, m_controller
);
1079 view
= m_columnView
;
1083 Q_ASSERT(view
!= 0);
1084 view
->installEventFilter(this);
1086 m_controller
->setItemView(view
);
1088 m_fileItemDelegate
= new KFileItemDelegate(view
);
1089 view
->setItemDelegate(m_fileItemDelegate
);
1091 view
->setModel(m_proxyModel
);
1092 if (m_selectionModel
!= 0) {
1093 view
->setSelectionModel(m_selectionModel
);
1095 m_selectionModel
= view
->selectionModel();
1098 // reparent the selection model, as it should not be deleted
1099 // when deleting the model
1100 m_selectionModel
->setParent(this);
1102 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1104 new KMimeTypeResolver(view
, m_dolphinModel
);
1105 m_iconManager
= new IconManager(view
, m_proxyModel
);
1106 m_iconManager
->setShowPreview(m_showPreview
);
1108 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1109 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1112 m_topLayout
->insertWidget(1, view
);
1114 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1115 this, SLOT(emitSelectionChangedSignal()));
1116 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1117 this, SLOT(emitContentsMoved()));
1118 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1119 this, SLOT(emitContentsMoved()));
1122 void DolphinView::deleteView()
1124 QAbstractItemView
* view
= itemView();
1126 m_topLayout
->removeWidget(view
);
1128 view
->deleteLater();
1133 m_fileItemDelegate
= 0;
1135 m_toolTipManager
= 0;
1139 QAbstractItemView
* DolphinView::itemView() const
1141 if (m_detailsView
!= 0) {
1142 return m_detailsView
;
1143 } else if (m_columnView
!= 0) {
1144 return m_columnView
;
1150 bool DolphinView::isCutItem(const KFileItem
& item
) const
1152 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1153 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1155 const KUrl
& itemUrl
= item
.url();
1156 KUrl::List::const_iterator it
= cutUrls
.begin();
1157 const KUrl::List::const_iterator end
= cutUrls
.end();
1159 if (*it
== itemUrl
) {
1168 void DolphinView::pasteToUrl(const KUrl
& url
)
1170 QClipboard
* clipboard
= QApplication::clipboard();
1171 const QMimeData
* mimeData
= clipboard
->mimeData();
1173 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1174 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1175 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1176 emit
doingOperation(KIO::FileUndoManager::Move
);
1179 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1180 emit
doingOperation(KIO::FileUndoManager::Copy
);
1184 #include "dolphinview.moc"