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 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
99 this, SIGNAL(urlChanged(const KUrl
&)));
100 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
101 this, SLOT(slotRequestUrlChange(const KUrl
&)));
103 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
104 this, SLOT(openContextMenu(const QPoint
&)));
105 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
106 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
107 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
108 this, SLOT(updateSorting(DolphinView::Sorting
)));
109 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
110 this, SLOT(updateSortOrder(Qt::SortOrder
)));
111 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
112 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
113 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
114 this, SLOT(triggerItem(const KFileItem
&)));
115 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
116 this, SIGNAL(tabRequested(const KUrl
&)));
117 connect(m_controller
, SIGNAL(activated()),
118 this, SLOT(activate()));
119 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
120 this, SLOT(showHoverInformation(const KFileItem
&)));
121 connect(m_controller
, SIGNAL(viewportEntered()),
122 this, SLOT(clearHoverInformation()));
124 connect(m_dirLister
, SIGNAL(redirection(KUrl
, KUrl
)),
125 this, SLOT(slotRedirection(KUrl
, KUrl
)));
126 connect(m_dirLister
, SIGNAL(completed()),
127 this, SLOT(restoreCurrentItem()));
129 applyViewProperties(url
);
130 m_topLayout
->addWidget(itemView());
133 DolphinView::~DolphinView()
137 const KUrl
& DolphinView::url() const
139 return m_controller
->url();
142 KUrl
DolphinView::rootUrl() const
144 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
147 void DolphinView::setActive(bool active
)
149 if (active
== m_active
) {
155 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
157 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
158 // bypasses the problem when having a split view and changing the active view to
159 // update the some URL dependent states. A nicer approach should be no big deal...
160 emit
urlChanged(url());
161 emit
selectionChanged(selectedItems());
166 QWidget
* viewport
= itemView()->viewport();
168 palette
.setColor(viewport
->backgroundRole(), color
);
169 viewport
->setPalette(palette
);
174 itemView()->setFocus();
178 m_controller
->indicateActivationChange(active
);
181 bool DolphinView::isActive() const
186 void DolphinView::setMode(Mode mode
)
188 if (mode
== m_mode
) {
189 return; // the wished mode is already set
196 const KUrl viewPropsUrl
= viewPropertiesUrl();
197 ViewProperties
props(viewPropsUrl
);
198 props
.setViewMode(m_mode
);
201 // the file item delegate has been recreated, apply the current
202 // additional information manually
203 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
204 m_fileItemDelegate
->setShowInformation(infoList
);
205 emit
additionalInfoChanged();
207 // Not all view modes support categorized sorting. Adjust the sorting model
208 // if changing the view mode results in a change of the categorized sorting
210 m_storedCategorizedSorting
= props
.categorizedSorting();
211 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
212 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
213 m_proxyModel
->setCategorizedModel(categorized
);
214 emit
categorizedSortingChanged();
220 DolphinView::Mode
DolphinView::mode() const
225 bool DolphinView::showPreview() const
227 return m_showPreview
;
230 bool DolphinView::showHiddenFiles() const
232 return m_dirLister
->showingDotFiles();
235 bool DolphinView::categorizedSorting() const
237 // If all view modes would support categorized sorting, returning
238 // m_proxyModel->isCategorizedModel() would be the way to go. As
239 // currently only the icons view supports caterized sorting, we remember
240 // the stored view properties state in m_storedCategorizedSorting and
241 // return this state. The application takes care to disable the corresponding
242 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
243 // that this setting is not applied to the current view mode.
244 return m_storedCategorizedSorting
;
247 bool DolphinView::supportsCategorizedSorting() const
249 return m_iconsView
!= 0;
252 void DolphinView::selectAll()
254 QAbstractItemView
* view
= itemView();
255 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
256 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
257 // selection instead of selecting all items. This is bypassed for KDE 4.0
258 // by invoking clearSelection() first.
259 view
->clearSelection();
263 void DolphinView::invertSelection()
265 if (isColumnViewActive()) {
266 // QAbstractItemView does not offer a virtual method invertSelection()
267 // as counterpart to QAbstractItemView::selectAll(). This makes it
268 // necessary to delegate the inverting of the selection to the
269 // column view, as only the selection of the active column should
271 m_columnView
->invertSelection();
273 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
274 const QAbstractItemModel
* itemModel
= selectionModel
->model();
276 const QModelIndex topLeft
= itemModel
->index(0, 0);
277 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
278 itemModel
->columnCount() - 1);
280 const QItemSelection
selection(topLeft
, bottomRight
);
281 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
285 bool DolphinView::hasSelection() const
287 return itemView()->selectionModel()->hasSelection();
290 void DolphinView::clearSelection()
292 itemView()->selectionModel()->clear();
295 KFileItemList
DolphinView::selectedItems() const
297 const QAbstractItemView
* view
= itemView();
299 // Our view has a selection, we will map them back to the DolphinModel
300 // and then fill the KFileItemList.
301 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
303 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
304 KFileItemList itemList
;
306 const QModelIndexList indexList
= selection
.indexes();
307 foreach (const QModelIndex
&index
, indexList
) {
308 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
309 if (!item
.isNull()) {
310 itemList
.append(item
);
317 KUrl::List
DolphinView::selectedUrls() const
320 const KFileItemList list
= selectedItems();
321 foreach (const KFileItem
&item
, list
) {
322 urls
.append(item
.url());
327 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
329 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
330 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
333 void DolphinView::setContentsPosition(int x
, int y
)
335 QAbstractItemView
* view
= itemView();
337 // the ColumnView takes care itself for the horizontal scrolling
338 if (!isColumnViewActive()) {
339 view
->horizontalScrollBar()->setValue(x
);
341 view
->verticalScrollBar()->setValue(y
);
343 m_loadingDirectory
= false;
346 QPoint
DolphinView::contentsPosition() const
348 const int x
= itemView()->horizontalScrollBar()->value();
349 const int y
= itemView()->verticalScrollBar()->value();
353 void DolphinView::zoomIn()
355 m_controller
->triggerZoomIn();
356 m_iconManager
->updatePreviews();
359 void DolphinView::zoomOut()
361 m_controller
->triggerZoomOut();
362 m_iconManager
->updatePreviews();
365 bool DolphinView::isZoomInPossible() const
367 return m_controller
->isZoomInPossible();
370 bool DolphinView::isZoomOutPossible() const
372 return m_controller
->isZoomOutPossible();
375 void DolphinView::setSorting(Sorting sorting
)
377 if (sorting
!= this->sorting()) {
378 updateSorting(sorting
);
382 DolphinView::Sorting
DolphinView::sorting() const
384 return m_proxyModel
->sorting();
387 void DolphinView::setSortOrder(Qt::SortOrder order
)
389 if (sortOrder() != order
) {
390 updateSortOrder(order
);
394 Qt::SortOrder
DolphinView::sortOrder() const
396 return m_proxyModel
->sortOrder();
399 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
401 const KUrl viewPropsUrl
= viewPropertiesUrl();
402 ViewProperties
props(viewPropsUrl
);
403 props
.setAdditionalInfo(info
);
404 m_fileItemDelegate
->setShowInformation(info
);
406 emit
additionalInfoChanged();
408 if (itemView() != m_detailsView
) {
409 // the details view requires no reloading of the directory, as it maps
410 // the file item delegate info to its columns internally
411 loadDirectory(viewPropsUrl
);
415 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
417 return m_fileItemDelegate
->showInformation();
420 void DolphinView::reload()
423 loadDirectory(url(), true);
426 void DolphinView::refresh()
428 const bool oldActivationState
= m_active
;
432 applyViewProperties(m_controller
->url());
435 setActive(oldActivationState
);
438 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
440 if (m_controller
->url() == url
) {
444 m_controller
->setUrl(url
); // emits urlChanged, which we forward
446 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
447 applyViewProperties(rootUrl
);
448 loadDirectory(rootUrl
);
449 if (itemView() == m_columnView
) {
450 m_columnView
->setRootUrl(rootUrl
);
451 m_columnView
->showColumn(url
);
454 applyViewProperties(url
);
458 emit
startedPathLoading(url
);
461 void DolphinView::setNameFilter(const QString
& nameFilter
)
463 m_proxyModel
->setFilterRegExp(nameFilter
);
465 if (isColumnViewActive()) {
466 // adjusting the directory lister is not enough in the case of the
467 // column view, as each column has its own directory lister internally...
468 m_columnView
->setNameFilter(nameFilter
);
472 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
474 foreach (const KFileItem
&item
, m_dirLister
->items()) {
483 void DolphinView::setUrl(const KUrl
& url
)
485 // remember current item candidate (see restoreCurrentItem())
486 m_currentItemUrl
= url
;
487 updateView(url
, KUrl());
490 void DolphinView::changeSelection(const KFileItemList
& selection
)
493 if (selection
.isEmpty()) {
496 const KUrl
& baseUrl
= url();
498 QItemSelection new_selection
;
499 foreach(const KFileItem
& item
, selection
) {
500 url
= item
.url().upUrl();
501 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
502 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
503 new_selection
.select(index
, index
);
506 itemView()->selectionModel()->select(new_selection
,
507 QItemSelectionModel::ClearAndSelect
508 | QItemSelectionModel::Current
);
511 void DolphinView::renameSelectedItems()
513 const KFileItemList items
= selectedItems();
514 if (items
.count() > 1) {
515 // More than one item has been selected for renaming. Open
516 // a rename dialog and rename all items afterwards.
517 RenameDialog
dialog(this, items
);
518 if (dialog
.exec() == QDialog::Rejected
) {
522 const QString newName
= dialog
.newName();
523 if (newName
.isEmpty()) {
524 emit
errorMessage(dialog
.errorString());
526 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
527 // as one operation instead of n rename operations like it is done now...
528 Q_ASSERT(newName
.contains('#'));
530 // iterate through all selected items and rename them...
532 foreach (const KFileItem
&item
, items
) {
533 const KUrl
& oldUrl
= item
.url();
535 number
.setNum(index
++);
537 QString name
= newName
;
538 name
.replace('#', number
);
540 if (oldUrl
.fileName() != name
) {
541 KUrl newUrl
= oldUrl
;
542 newUrl
.setFileName(name
);
543 KonqOperations::rename(this, oldUrl
, newUrl
);
544 emit
doingOperation(KIO::FileUndoManager::Rename
);
548 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
549 Q_ASSERT(items
.count() == 1);
551 if (isColumnViewActive()) {
552 m_columnView
->editItem(items
.first());
554 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
555 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
556 itemView()->edit(proxyIndex
);
559 Q_ASSERT(items
.count() == 1);
561 RenameDialog
dialog(this, items
);
562 if (dialog
.exec() == QDialog::Rejected
) {
566 const QString
& newName
= dialog
.newName();
567 if (newName
.isEmpty()) {
568 emit
errorMessage(dialog
.errorString());
570 const KUrl
& oldUrl
= items
.first().url();
571 KUrl newUrl
= oldUrl
;
572 newUrl
.setFileName(newName
);
573 KonqOperations::rename(this, oldUrl
, newUrl
);
574 emit
doingOperation(KIO::FileUndoManager::Rename
);
579 void DolphinView::trashSelectedItems()
581 emit
doingOperation(KIO::FileUndoManager::Trash
);
582 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
585 void DolphinView::deleteSelectedItems()
587 const KUrl::List list
= selectedUrls();
588 const bool del
= KonqOperations::askDeleteConfirmation(list
,
590 KonqOperations::DEFAULT_CONFIRMATION
,
594 KIO::Job
* job
= KIO::del(list
);
595 connect(job
, SIGNAL(result(KJob
*)),
596 this, SLOT(slotDeleteFileFinished(KJob
*)));
600 void DolphinView::cutSelectedItems()
602 QMimeData
* mimeData
= new QMimeData();
603 const KUrl::List kdeUrls
= selectedUrls();
604 const KUrl::List mostLocalUrls
;
605 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
606 QApplication::clipboard()->setMimeData(mimeData
);
609 void DolphinView::copySelectedItems()
611 QMimeData
* mimeData
= new QMimeData();
612 const KUrl::List kdeUrls
= selectedUrls();
613 const KUrl::List mostLocalUrls
;
614 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
615 QApplication::clipboard()->setMimeData(mimeData
);
618 void DolphinView::paste()
623 void DolphinView::pasteIntoFolder()
625 const KFileItemList items
= selectedItems();
626 if ((items
.count() == 1) && items
.first().isDir()) {
627 pasteToUrl(items
.first().url());
631 void DolphinView::setShowPreview(bool show
)
633 if (m_showPreview
== show
) {
637 const KUrl viewPropsUrl
= viewPropertiesUrl();
638 ViewProperties
props(viewPropsUrl
);
639 props
.setShowPreview(show
);
641 m_showPreview
= show
;
642 m_iconManager
->setShowPreview(show
);
643 emit
showPreviewChanged();
645 loadDirectory(viewPropsUrl
);
648 void DolphinView::setShowHiddenFiles(bool show
)
650 if (m_dirLister
->showingDotFiles() == show
) {
654 const KUrl viewPropsUrl
= viewPropertiesUrl();
655 ViewProperties
props(viewPropsUrl
);
656 props
.setShowHiddenFiles(show
);
658 m_dirLister
->setShowingDotFiles(show
);
659 emit
showHiddenFilesChanged();
661 loadDirectory(viewPropsUrl
);
664 void DolphinView::setCategorizedSorting(bool categorized
)
666 if (categorized
== categorizedSorting()) {
670 // setCategorizedSorting(true) may only get invoked
671 // if the view supports categorized sorting
672 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
674 ViewProperties
props(viewPropertiesUrl());
675 props
.setCategorizedSorting(categorized
);
678 m_storedCategorizedSorting
= categorized
;
679 m_proxyModel
->setCategorizedModel(categorized
);
681 emit
categorizedSortingChanged();
684 void DolphinView::toggleSortOrder()
686 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
687 Qt::DescendingOrder
:
692 void DolphinView::toggleAdditionalInfo(QAction
* action
)
694 const KFileItemDelegate::Information info
=
695 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
697 KFileItemDelegate::InformationList list
= additionalInfo();
699 const bool show
= action
->isChecked();
701 const int index
= list
.indexOf(info
);
702 const bool containsInfo
= (index
>= 0);
703 if (show
&& !containsInfo
) {
705 setAdditionalInfo(list
);
706 } else if (!show
&& containsInfo
) {
707 list
.removeAt(index
);
708 setAdditionalInfo(list
);
709 Q_ASSERT(list
.indexOf(info
) < 0);
714 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
716 QWidget::mouseReleaseEvent(event
);
720 void DolphinView::wheelEvent(QWheelEvent
* event
)
722 if (event
->modifiers() & Qt::ControlModifier
) {
723 const int delta
= event
->delta();
724 if ((delta
> 0) && isZoomInPossible()) {
726 } else if ((delta
< 0) && isZoomOutPossible()) {
733 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
735 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
736 m_controller
->requestActivation();
739 return QWidget::eventFilter(watched
, event
);
742 void DolphinView::activate()
747 void DolphinView::triggerItem(const KFileItem
& item
)
749 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
750 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
751 // items are selected by the user, hence don't trigger the
752 // item specified by 'index'
756 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
757 if (item
.isNull() || m_isContextMenuOpen
) {
761 if (m_toolTipManager
!= 0) {
762 m_toolTipManager
->hideTip();
764 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
767 void DolphinView::emitSelectionChangedSignal()
769 emit
selectionChanged(DolphinView::selectedItems());
772 void DolphinView::openContextMenu(const QPoint
& pos
)
776 const QModelIndex index
= itemView()->indexAt(pos
);
777 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
778 item
= fileItem(index
);
781 if (m_toolTipManager
!= 0) {
782 m_toolTipManager
->hideTip();
785 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
786 emit
requestContextMenu(item
, url());
787 m_isContextMenuOpen
= false;
790 void DolphinView::dropUrls(const KUrl::List
& urls
,
791 const KUrl
& destPath
,
792 const KFileItem
& destItem
)
794 Q_ASSERT(!urls
.isEmpty());
795 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
796 destItem
.url() : destPath
;
797 const KUrl sourceDir
= KUrl(urls
.first().directory());
798 if (sourceDir
!= destination
) {
799 dropUrls(urls
, destination
);
803 void DolphinView::dropUrls(const KUrl::List
& urls
,
804 const KUrl
& destination
)
806 DolphinDropController
dropController(this);
807 // forward doingOperation signal up to the mainwindow
808 connect(&dropController
, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)),
809 this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)));
810 dropController
.dropUrls(urls
, destination
);
813 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
815 ViewProperties
props(viewPropertiesUrl());
816 props
.setSorting(sorting
);
818 m_proxyModel
->setSorting(sorting
);
820 emit
sortingChanged(sorting
);
823 void DolphinView::updateSortOrder(Qt::SortOrder order
)
825 ViewProperties
props(viewPropertiesUrl());
826 props
.setSortOrder(order
);
828 m_proxyModel
->setSortOrder(order
);
830 emit
sortOrderChanged(order
);
833 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
835 ViewProperties
props(viewPropertiesUrl());
836 props
.setAdditionalInfo(info
);
839 m_fileItemDelegate
->setShowInformation(info
);
841 emit
additionalInfoChanged();
844 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
846 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
847 (m_mode
== DolphinView::IconsView
);
849 QAction
* showSizeInfo
= collection
->action("show_size_info");
850 QAction
* showDateInfo
= collection
->action("show_date_info");
851 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
852 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
853 QAction
* showGroupInfo
= collection
->action("show_group_info");
854 QAction
* showMimeInfo
= collection
->action("show_mime_info");
856 showSizeInfo
->setChecked(false);
857 showDateInfo
->setChecked(false);
858 showPermissionsInfo
->setChecked(false);
859 showOwnerInfo
->setChecked(false);
860 showGroupInfo
->setChecked(false);
861 showMimeInfo
->setChecked(false);
863 showSizeInfo
->setEnabled(enable
);
864 showDateInfo
->setEnabled(enable
);
865 showPermissionsInfo
->setEnabled(enable
);
866 showOwnerInfo
->setEnabled(enable
);
867 showGroupInfo
->setEnabled(enable
);
868 showMimeInfo
->setEnabled(enable
);
870 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
872 case KFileItemDelegate::Size
:
873 showSizeInfo
->setChecked(true);
875 case KFileItemDelegate::ModificationTime
:
876 showDateInfo
->setChecked(true);
878 case KFileItemDelegate::Permissions
:
879 showPermissionsInfo
->setChecked(true);
881 case KFileItemDelegate::Owner
:
882 showOwnerInfo
->setChecked(true);
884 case KFileItemDelegate::OwnerAndGroup
:
885 showGroupInfo
->setChecked(true);
887 case KFileItemDelegate::FriendlyMimeType
:
888 showMimeInfo
->setChecked(true);
896 QPair
<bool, QString
> DolphinView::pasteInfo() const
898 QPair
<bool, QString
> ret
;
899 QClipboard
* clipboard
= QApplication::clipboard();
900 const QMimeData
* mimeData
= clipboard
->mimeData();
902 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
903 if (!urls
.isEmpty()) {
905 if (urls
.count() == 1) {
906 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
907 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
908 i18nc("@action:inmenu", "Paste One File");
911 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
915 ret
.second
= i18nc("@action:inmenu", "Paste");
921 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
923 m_tabsForFiles
= tabsForFiles
;
926 bool DolphinView::isTabsForFilesEnabled() const
928 return m_tabsForFiles
;
931 void DolphinView::emitContentsMoved()
933 // only emit the contents moved signal if:
934 // - no directory loading is ongoing (this would reset the contents position
936 // - if the Column View is active: the column view does an automatic
937 // positioning during the loading operation, which must be remembered
938 if (!m_loadingDirectory
|| isColumnViewActive()) {
939 const QPoint
pos(contentsPosition());
940 emit
contentsMoved(pos
.x(), pos
.y());
944 void DolphinView::showHoverInformation(const KFileItem
& item
)
946 emit
requestItemInfo(item
);
949 void DolphinView::clearHoverInformation()
951 emit
requestItemInfo(KFileItem());
954 void DolphinView::slotDeleteFileFinished(KJob
* job
)
956 if (job
->error() == 0) {
957 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
959 emit
errorMessage(job
->errorString());
964 void DolphinView::restoreCurrentItem()
966 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
967 if (dirIndex
.isValid()) {
968 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
969 QAbstractItemView
* view
= itemView();
970 const bool clearSelection
= !hasSelection();
971 view
->setCurrentIndex(proxyIndex
);
972 if (clearSelection
) {
973 view
->clearSelection();
978 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
980 if (!url
.isValid()) {
981 const QString
location(url
.pathOrUrl());
982 if (location
.isEmpty()) {
983 emit
errorMessage(i18nc("@info:status", "The location is empty."));
985 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
990 m_loadingDirectory
= true;
993 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
995 if (isColumnViewActive()) {
996 // adjusting the directory lister is not enough in the case of the
997 // column view, as each column has its own directory lister internally...
999 m_columnView
->reload();
1001 m_columnView
->showColumn(url
);
1006 KUrl
DolphinView::viewPropertiesUrl() const
1008 if (isColumnViewActive()) {
1009 return m_columnView
->rootUrl();
1015 void DolphinView::applyViewProperties(const KUrl
& url
)
1017 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1018 // The column view is active, hence don't apply the view properties
1019 // of sub directories (represented by columns) to the view. The
1020 // view always represents the properties of the first column.
1024 const ViewProperties
props(url
);
1026 const Mode mode
= props
.viewMode();
1027 if (m_mode
!= mode
) {
1032 if (itemView() == 0) {
1035 Q_ASSERT(itemView() != 0);
1036 Q_ASSERT(m_fileItemDelegate
!= 0);
1038 const bool showHiddenFiles
= props
.showHiddenFiles();
1039 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1040 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1041 emit
showHiddenFilesChanged();
1044 m_storedCategorizedSorting
= props
.categorizedSorting();
1045 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1046 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1047 m_proxyModel
->setCategorizedModel(categorized
);
1048 emit
categorizedSortingChanged();
1051 const DolphinView::Sorting sorting
= props
.sorting();
1052 if (sorting
!= m_proxyModel
->sorting()) {
1053 m_proxyModel
->setSorting(sorting
);
1054 emit
sortingChanged(sorting
);
1057 const Qt::SortOrder sortOrder
= props
.sortOrder();
1058 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1059 m_proxyModel
->setSortOrder(sortOrder
);
1060 emit
sortOrderChanged(sortOrder
);
1063 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1064 if (info
!= m_fileItemDelegate
->showInformation()) {
1065 m_fileItemDelegate
->setShowInformation(info
);
1066 emit
additionalInfoChanged();
1069 const bool showPreview
= props
.showPreview();
1070 if (showPreview
!= m_showPreview
) {
1071 m_showPreview
= showPreview
;
1072 m_iconManager
->setShowPreview(showPreview
);
1073 emit
showPreviewChanged();
1077 void DolphinView::createView()
1080 Q_ASSERT(m_iconsView
== 0);
1081 Q_ASSERT(m_detailsView
== 0);
1082 Q_ASSERT(m_columnView
== 0);
1084 QAbstractItemView
* view
= 0;
1087 m_iconsView
= new DolphinIconsView(this, m_controller
);
1093 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1094 view
= m_detailsView
;
1098 m_columnView
= new DolphinColumnView(this, m_controller
);
1099 view
= m_columnView
;
1103 Q_ASSERT(view
!= 0);
1104 view
->installEventFilter(this);
1106 m_controller
->setItemView(view
);
1108 m_fileItemDelegate
= new KFileItemDelegate(view
);
1109 view
->setItemDelegate(m_fileItemDelegate
);
1111 view
->setModel(m_proxyModel
);
1112 if (m_selectionModel
!= 0) {
1113 view
->setSelectionModel(m_selectionModel
);
1115 m_selectionModel
= view
->selectionModel();
1118 // reparent the selection model, as it should not be deleted
1119 // when deleting the model
1120 m_selectionModel
->setParent(this);
1122 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1124 new KMimeTypeResolver(view
, m_dolphinModel
);
1125 m_iconManager
= new IconManager(view
, m_proxyModel
);
1126 m_iconManager
->setShowPreview(m_showPreview
);
1128 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1129 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1132 m_topLayout
->insertWidget(1, view
);
1134 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1135 this, SLOT(emitSelectionChangedSignal()));
1136 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1137 this, SLOT(emitContentsMoved()));
1138 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1139 this, SLOT(emitContentsMoved()));
1142 void DolphinView::deleteView()
1144 QAbstractItemView
* view
= itemView();
1146 m_topLayout
->removeWidget(view
);
1148 view
->deleteLater();
1153 m_fileItemDelegate
= 0;
1155 m_toolTipManager
= 0;
1159 QAbstractItemView
* DolphinView::itemView() const
1161 if (m_detailsView
!= 0) {
1162 return m_detailsView
;
1163 } else if (m_columnView
!= 0) {
1164 return m_columnView
;
1170 bool DolphinView::isCutItem(const KFileItem
& item
) const
1172 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1173 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1175 const KUrl
& itemUrl
= item
.url();
1176 KUrl::List::const_iterator it
= cutUrls
.begin();
1177 const KUrl::List::const_iterator end
= cutUrls
.end();
1179 if (*it
== itemUrl
) {
1188 void DolphinView::pasteToUrl(const KUrl
& url
)
1190 QClipboard
* clipboard
= QApplication::clipboard();
1191 const QMimeData
* mimeData
= clipboard
->mimeData();
1193 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1194 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1195 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1196 emit
doingOperation(KIO::FileUndoManager::Move
);
1199 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1200 emit
doingOperation(KIO::FileUndoManager::Copy
);
1204 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1206 emit
requestUrlChange(url
);
1207 m_controller
->setUrl(url
);
1210 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1212 if (oldUrl
== m_controller
->url()) {
1213 m_controller
->setUrl(newUrl
);
1217 #include "dolphinview.moc"