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, SLOT(slotRequestUrlChange(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(redirection(KUrl
, KUrl
)),
129 this, SLOT(slotRedirection(KUrl
, KUrl
)));
130 connect(m_dirLister
, SIGNAL(completed()),
131 this, SLOT(restoreCurrentItem()));
133 applyViewProperties(url
);
134 m_topLayout
->addWidget(itemView());
137 DolphinView::~DolphinView()
141 const KUrl
& DolphinView::url() const
143 return m_controller
->url();
146 KUrl
DolphinView::rootUrl() const
148 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
151 void DolphinView::setActive(bool active
)
153 if (active
== m_active
) {
158 m_selectionModel
->clearSelection();
160 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
162 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
163 // bypasses the problem when having a split view and changing the active view to
164 // update the some URL dependent states. A nicer approach should be no big deal...
165 emit
urlChanged(url());
166 emit
selectionChanged(selectedItems());
171 QWidget
* viewport
= itemView()->viewport();
173 palette
.setColor(viewport
->backgroundRole(), color
);
174 viewport
->setPalette(palette
);
179 itemView()->setFocus();
183 m_controller
->indicateActivationChange(active
);
186 bool DolphinView::isActive() const
191 void DolphinView::setMode(Mode mode
)
193 if (mode
== m_mode
) {
194 return; // the wished mode is already set
201 const KUrl viewPropsUrl
= viewPropertiesUrl();
202 ViewProperties
props(viewPropsUrl
);
203 props
.setViewMode(m_mode
);
206 // the file item delegate has been recreated, apply the current
207 // additional information manually
208 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
209 m_fileItemDelegate
->setShowInformation(infoList
);
210 emit
additionalInfoChanged();
212 // Not all view modes support categorized sorting. Adjust the sorting model
213 // if changing the view mode results in a change of the categorized sorting
215 m_storedCategorizedSorting
= props
.categorizedSorting();
216 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
217 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
218 m_proxyModel
->setCategorizedModel(categorized
);
219 emit
categorizedSortingChanged();
225 DolphinView::Mode
DolphinView::mode() const
230 bool DolphinView::showPreview() const
232 return m_showPreview
;
235 bool DolphinView::showHiddenFiles() const
237 return m_dirLister
->showingDotFiles();
240 bool DolphinView::categorizedSorting() const
242 // If all view modes would support categorized sorting, returning
243 // m_proxyModel->isCategorizedModel() would be the way to go. As
244 // currently only the icons view supports caterized sorting, we remember
245 // the stored view properties state in m_storedCategorizedSorting and
246 // return this state. The application takes care to disable the corresponding
247 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
248 // that this setting is not applied to the current view mode.
249 return m_storedCategorizedSorting
;
252 bool DolphinView::supportsCategorizedSorting() const
254 return m_iconsView
!= 0;
257 void DolphinView::selectAll()
259 QAbstractItemView
* view
= itemView();
260 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
261 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
262 // selection instead of selecting all items. This is bypassed for KDE 4.0
263 // by invoking clearSelection() first.
264 view
->clearSelection();
268 void DolphinView::invertSelection()
270 if (isColumnViewActive()) {
271 // QAbstractItemView does not offer a virtual method invertSelection()
272 // as counterpart to QAbstractItemView::selectAll(). This makes it
273 // necessary to delegate the inverting of the selection to the
274 // column view, as only the selection of the active column should
276 m_columnView
->invertSelection();
278 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
279 const QAbstractItemModel
* itemModel
= selectionModel
->model();
281 const QModelIndex topLeft
= itemModel
->index(0, 0);
282 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
283 itemModel
->columnCount() - 1);
285 const QItemSelection
selection(topLeft
, bottomRight
);
286 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
290 bool DolphinView::hasSelection() const
292 return itemView()->selectionModel()->hasSelection();
295 void DolphinView::clearSelection()
297 itemView()->selectionModel()->clear();
300 KFileItemList
DolphinView::selectedItems() const
302 const QAbstractItemView
* view
= itemView();
304 // Our view has a selection, we will map them back to the DolphinModel
305 // and then fill the KFileItemList.
306 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
308 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
309 KFileItemList itemList
;
311 const QModelIndexList indexList
= selection
.indexes();
312 foreach (const QModelIndex
&index
, indexList
) {
313 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
314 if (!item
.isNull()) {
315 itemList
.append(item
);
322 KUrl::List
DolphinView::selectedUrls() const
325 const KFileItemList list
= selectedItems();
326 foreach (const KFileItem
&item
, list
) {
327 urls
.append(item
.url());
332 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
334 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
335 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
338 void DolphinView::setContentsPosition(int x
, int y
)
340 QAbstractItemView
* view
= itemView();
342 // the ColumnView takes care itself for the horizontal scrolling
343 if (!isColumnViewActive()) {
344 view
->horizontalScrollBar()->setValue(x
);
346 view
->verticalScrollBar()->setValue(y
);
348 m_loadingDirectory
= false;
351 QPoint
DolphinView::contentsPosition() const
353 const int x
= itemView()->horizontalScrollBar()->value();
354 const int y
= itemView()->verticalScrollBar()->value();
358 void DolphinView::zoomIn()
360 m_controller
->triggerZoomIn();
361 m_iconManager
->updatePreviews();
364 void DolphinView::zoomOut()
366 m_controller
->triggerZoomOut();
367 m_iconManager
->updatePreviews();
370 bool DolphinView::isZoomInPossible() const
372 return m_controller
->isZoomInPossible();
375 bool DolphinView::isZoomOutPossible() const
377 return m_controller
->isZoomOutPossible();
380 void DolphinView::setSorting(Sorting sorting
)
382 if (sorting
!= this->sorting()) {
383 updateSorting(sorting
);
387 DolphinView::Sorting
DolphinView::sorting() const
389 return m_proxyModel
->sorting();
392 void DolphinView::setSortOrder(Qt::SortOrder order
)
394 if (sortOrder() != order
) {
395 updateSortOrder(order
);
399 Qt::SortOrder
DolphinView::sortOrder() const
401 return m_proxyModel
->sortOrder();
404 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
406 const KUrl viewPropsUrl
= viewPropertiesUrl();
407 ViewProperties
props(viewPropsUrl
);
408 props
.setAdditionalInfo(info
);
409 m_fileItemDelegate
->setShowInformation(info
);
411 emit
additionalInfoChanged();
413 if (itemView() != m_detailsView
) {
414 // the details view requires no reloading of the directory, as it maps
415 // the file item delegate info to its columns internally
416 loadDirectory(viewPropsUrl
);
420 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
422 return m_fileItemDelegate
->showInformation();
425 void DolphinView::reload()
428 loadDirectory(url(), true);
431 void DolphinView::refresh()
433 const bool oldActivationState
= m_active
;
437 applyViewProperties(m_controller
->url());
440 setActive(oldActivationState
);
443 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
445 if (m_controller
->url() == url
) {
449 m_controller
->setUrl(url
); // emits urlChanged, which we forward
451 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
452 applyViewProperties(rootUrl
);
453 loadDirectory(rootUrl
);
454 if (itemView() == m_columnView
) {
455 m_columnView
->setRootUrl(rootUrl
);
456 m_columnView
->showColumn(url
);
459 applyViewProperties(url
);
463 emit
startedPathLoading(url
);
466 void DolphinView::setNameFilter(const QString
& nameFilter
)
468 m_proxyModel
->setFilterRegExp(nameFilter
);
470 if (isColumnViewActive()) {
471 // adjusting the directory lister is not enough in the case of the
472 // column view, as each column has its own directory lister internally...
473 m_columnView
->setNameFilter(nameFilter
);
477 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
479 foreach (const KFileItem
&item
, m_dirLister
->items()) {
488 void DolphinView::setUrl(const KUrl
& url
)
490 // remember current item candidate (see restoreCurrentItem())
491 m_currentItemUrl
= url
;
492 updateView(url
, KUrl());
495 void DolphinView::changeSelection(const KFileItemList
& selection
)
498 if (selection
.isEmpty()) {
501 const KUrl
& baseUrl
= url();
503 QItemSelection new_selection
;
504 foreach(const KFileItem
& item
, selection
) {
505 url
= item
.url().upUrl();
506 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
507 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
508 new_selection
.select(index
, index
);
511 itemView()->selectionModel()->select(new_selection
,
512 QItemSelectionModel::ClearAndSelect
513 | QItemSelectionModel::Current
);
516 void DolphinView::renameSelectedItems()
518 const KFileItemList items
= selectedItems();
519 if (items
.count() > 1) {
520 // More than one item has been selected for renaming. Open
521 // a rename dialog and rename all items afterwards.
522 RenameDialog
dialog(this, items
);
523 if (dialog
.exec() == QDialog::Rejected
) {
527 const QString newName
= dialog
.newName();
528 if (newName
.isEmpty()) {
529 emit
errorMessage(dialog
.errorString());
531 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
532 // as one operation instead of n rename operations like it is done now...
533 Q_ASSERT(newName
.contains('#'));
535 // iterate through all selected items and rename them...
537 foreach (const KFileItem
&item
, items
) {
538 const KUrl
& oldUrl
= item
.url();
540 number
.setNum(index
++);
542 QString name
= newName
;
543 name
.replace('#', number
);
545 if (oldUrl
.fileName() != name
) {
546 KUrl newUrl
= oldUrl
;
547 newUrl
.setFileName(name
);
548 KonqOperations::rename(this, oldUrl
, newUrl
);
549 emit
doingOperation(KIO::FileUndoManager::Rename
);
553 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
554 Q_ASSERT(items
.count() == 1);
556 if (isColumnViewActive()) {
557 m_columnView
->editItem(items
.first());
559 const QModelIndex dirIndex
= m_dolphinModel
->indexForItem(items
.first());
560 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
561 itemView()->edit(proxyIndex
);
564 Q_ASSERT(items
.count() == 1);
566 RenameDialog
dialog(this, items
);
567 if (dialog
.exec() == QDialog::Rejected
) {
571 const QString
& newName
= dialog
.newName();
572 if (newName
.isEmpty()) {
573 emit
errorMessage(dialog
.errorString());
575 const KUrl
& oldUrl
= items
.first().url();
576 KUrl newUrl
= oldUrl
;
577 newUrl
.setFileName(newName
);
578 KonqOperations::rename(this, oldUrl
, newUrl
);
579 emit
doingOperation(KIO::FileUndoManager::Rename
);
584 void DolphinView::trashSelectedItems()
586 emit
doingOperation(KIO::FileUndoManager::Trash
);
587 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls());
590 void DolphinView::deleteSelectedItems()
592 const KUrl::List list
= selectedUrls();
593 const bool del
= KonqOperations::askDeleteConfirmation(list
,
595 KonqOperations::DEFAULT_CONFIRMATION
,
599 KIO::Job
* job
= KIO::del(list
);
600 connect(job
, SIGNAL(result(KJob
*)),
601 this, SLOT(slotDeleteFileFinished(KJob
*)));
605 void DolphinView::cutSelectedItems()
607 QMimeData
* mimeData
= new QMimeData();
608 const KUrl::List kdeUrls
= selectedUrls();
609 const KUrl::List mostLocalUrls
;
610 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
611 QApplication::clipboard()->setMimeData(mimeData
);
614 void DolphinView::copySelectedItems()
616 QMimeData
* mimeData
= new QMimeData();
617 const KUrl::List kdeUrls
= selectedUrls();
618 const KUrl::List mostLocalUrls
;
619 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
620 QApplication::clipboard()->setMimeData(mimeData
);
623 void DolphinView::paste()
628 void DolphinView::pasteIntoFolder()
630 const KFileItemList items
= selectedItems();
631 if ((items
.count() == 1) && items
.first().isDir()) {
632 pasteToUrl(items
.first().url());
636 void DolphinView::setShowPreview(bool show
)
638 if (m_showPreview
== show
) {
642 const KUrl viewPropsUrl
= viewPropertiesUrl();
643 ViewProperties
props(viewPropsUrl
);
644 props
.setShowPreview(show
);
646 m_showPreview
= show
;
647 m_iconManager
->setShowPreview(show
);
648 emit
showPreviewChanged();
650 loadDirectory(viewPropsUrl
);
653 void DolphinView::setShowHiddenFiles(bool show
)
655 if (m_dirLister
->showingDotFiles() == show
) {
659 const KUrl viewPropsUrl
= viewPropertiesUrl();
660 ViewProperties
props(viewPropsUrl
);
661 props
.setShowHiddenFiles(show
);
663 m_dirLister
->setShowingDotFiles(show
);
664 emit
showHiddenFilesChanged();
666 loadDirectory(viewPropsUrl
);
669 void DolphinView::setCategorizedSorting(bool categorized
)
671 if (categorized
== categorizedSorting()) {
675 // setCategorizedSorting(true) may only get invoked
676 // if the view supports categorized sorting
677 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
679 ViewProperties
props(viewPropertiesUrl());
680 props
.setCategorizedSorting(categorized
);
683 m_storedCategorizedSorting
= categorized
;
684 m_proxyModel
->setCategorizedModel(categorized
);
686 emit
categorizedSortingChanged();
689 void DolphinView::toggleSortOrder()
691 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
692 Qt::DescendingOrder
:
697 void DolphinView::toggleAdditionalInfo(QAction
* action
)
699 const KFileItemDelegate::Information info
=
700 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
702 KFileItemDelegate::InformationList list
= additionalInfo();
704 const bool show
= action
->isChecked();
706 const int index
= list
.indexOf(info
);
707 const bool containsInfo
= (index
>= 0);
708 if (show
&& !containsInfo
) {
710 setAdditionalInfo(list
);
711 } else if (!show
&& containsInfo
) {
712 list
.removeAt(index
);
713 setAdditionalInfo(list
);
714 Q_ASSERT(list
.indexOf(info
) < 0);
719 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
721 QWidget::mouseReleaseEvent(event
);
725 void DolphinView::wheelEvent(QWheelEvent
* event
)
727 if (event
->modifiers() & Qt::ControlModifier
) {
728 const int delta
= event
->delta();
729 if ((delta
> 0) && isZoomInPossible()) {
731 } else if ((delta
< 0) && isZoomOutPossible()) {
738 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
740 if ((watched
== itemView()) && (event
->type() == QEvent::FocusIn
)) {
741 m_controller
->requestActivation();
744 return QWidget::eventFilter(watched
, event
);
747 void DolphinView::activate()
752 void DolphinView::triggerItem(const KFileItem
& item
)
754 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
755 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
756 // items are selected by the user, hence don't trigger the
757 // item specified by 'index'
761 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
762 if (item
.isNull() || m_isContextMenuOpen
) {
766 if (m_toolTipManager
!= 0) {
767 m_toolTipManager
->hideTip();
769 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
772 void DolphinView::emitSelectionChangedSignal()
774 emit
selectionChanged(DolphinView::selectedItems());
777 void DolphinView::openContextMenu(const QPoint
& pos
)
781 const QModelIndex index
= itemView()->indexAt(pos
);
782 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
783 item
= fileItem(index
);
786 if (m_toolTipManager
!= 0) {
787 m_toolTipManager
->hideTip();
790 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
791 emit
requestContextMenu(item
, url());
792 m_isContextMenuOpen
= false;
795 void DolphinView::dropUrls(const KUrl::List
& urls
,
796 const KUrl
& destPath
,
797 const KFileItem
& destItem
)
799 Q_ASSERT(!urls
.isEmpty());
800 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
801 destItem
.url() : destPath
;
802 const KUrl sourceDir
= KUrl(urls
.first().directory());
803 if (sourceDir
!= destination
) {
804 dropUrls(urls
, destination
);
808 void DolphinView::dropUrls(const KUrl::List
& urls
,
809 const KUrl
& destination
)
811 DolphinDropController
dropController(this);
812 // forward doingOperation signal up to the mainwindow
813 connect(&dropController
, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)),
814 this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType
)));
815 dropController
.dropUrls(urls
, destination
);
818 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
820 ViewProperties
props(viewPropertiesUrl());
821 props
.setSorting(sorting
);
823 m_proxyModel
->setSorting(sorting
);
825 emit
sortingChanged(sorting
);
828 void DolphinView::updateSortOrder(Qt::SortOrder order
)
830 ViewProperties
props(viewPropertiesUrl());
831 props
.setSortOrder(order
);
833 m_proxyModel
->setSortOrder(order
);
835 emit
sortOrderChanged(order
);
838 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
840 ViewProperties
props(viewPropertiesUrl());
841 props
.setAdditionalInfo(info
);
844 m_fileItemDelegate
->setShowInformation(info
);
846 emit
additionalInfoChanged();
849 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
851 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
852 (m_mode
== DolphinView::IconsView
);
854 QAction
* showSizeInfo
= collection
->action("show_size_info");
855 QAction
* showDateInfo
= collection
->action("show_date_info");
856 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
857 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
858 QAction
* showGroupInfo
= collection
->action("show_group_info");
859 QAction
* showMimeInfo
= collection
->action("show_mime_info");
861 showSizeInfo
->setChecked(false);
862 showDateInfo
->setChecked(false);
863 showPermissionsInfo
->setChecked(false);
864 showOwnerInfo
->setChecked(false);
865 showGroupInfo
->setChecked(false);
866 showMimeInfo
->setChecked(false);
868 showSizeInfo
->setEnabled(enable
);
869 showDateInfo
->setEnabled(enable
);
870 showPermissionsInfo
->setEnabled(enable
);
871 showOwnerInfo
->setEnabled(enable
);
872 showGroupInfo
->setEnabled(enable
);
873 showMimeInfo
->setEnabled(enable
);
875 foreach (KFileItemDelegate::Information info
, m_fileItemDelegate
->showInformation()) {
877 case KFileItemDelegate::Size
:
878 showSizeInfo
->setChecked(true);
880 case KFileItemDelegate::ModificationTime
:
881 showDateInfo
->setChecked(true);
883 case KFileItemDelegate::Permissions
:
884 showPermissionsInfo
->setChecked(true);
886 case KFileItemDelegate::Owner
:
887 showOwnerInfo
->setChecked(true);
889 case KFileItemDelegate::OwnerAndGroup
:
890 showGroupInfo
->setChecked(true);
892 case KFileItemDelegate::FriendlyMimeType
:
893 showMimeInfo
->setChecked(true);
901 QPair
<bool, QString
> DolphinView::pasteInfo() const
903 QPair
<bool, QString
> ret
;
904 QClipboard
* clipboard
= QApplication::clipboard();
905 const QMimeData
* mimeData
= clipboard
->mimeData();
907 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
908 if (!urls
.isEmpty()) {
910 if (urls
.count() == 1) {
911 const KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, urls
.first(), true);
912 ret
.second
= item
.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
913 i18nc("@action:inmenu", "Paste One File");
916 ret
.second
= i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls
.count());
920 ret
.second
= i18nc("@action:inmenu", "Paste");
926 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
928 m_tabsForFiles
= tabsForFiles
;
931 bool DolphinView::isTabsForFilesEnabled() const
933 return m_tabsForFiles
;
936 void DolphinView::emitContentsMoved()
938 // only emit the contents moved signal if:
939 // - no directory loading is ongoing (this would reset the contents position
941 // - if the Column View is active: the column view does an automatic
942 // positioning during the loading operation, which must be remembered
943 if (!m_loadingDirectory
|| isColumnViewActive()) {
944 const QPoint
pos(contentsPosition());
945 emit
contentsMoved(pos
.x(), pos
.y());
949 void DolphinView::showHoverInformation(const KFileItem
& item
)
951 emit
requestItemInfo(item
);
954 void DolphinView::clearHoverInformation()
956 emit
requestItemInfo(KFileItem());
959 void DolphinView::slotDeleteFileFinished(KJob
* job
)
961 if (job
->error() == 0) {
962 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
964 emit
errorMessage(job
->errorString());
969 void DolphinView::restoreCurrentItem()
971 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_currentItemUrl
);
972 if (dirIndex
.isValid()) {
973 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
974 QAbstractItemView
* view
= itemView();
975 const bool clearSelection
= !hasSelection();
976 view
->setCurrentIndex(proxyIndex
);
977 if (clearSelection
) {
978 view
->clearSelection();
983 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
985 if (!url
.isValid()) {
986 const QString
location(url
.pathOrUrl());
987 if (location
.isEmpty()) {
988 emit
errorMessage(i18nc("@info:status", "The location is empty."));
990 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
995 m_loadingDirectory
= true;
998 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1000 if (isColumnViewActive()) {
1001 // adjusting the directory lister is not enough in the case of the
1002 // column view, as each column has its own directory lister internally...
1004 m_columnView
->reload();
1006 m_columnView
->showColumn(url
);
1011 KUrl
DolphinView::viewPropertiesUrl() const
1013 if (isColumnViewActive()) {
1014 return m_columnView
->rootUrl();
1020 void DolphinView::applyViewProperties(const KUrl
& url
)
1022 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
1023 // The column view is active, hence don't apply the view properties
1024 // of sub directories (represented by columns) to the view. The
1025 // view always represents the properties of the first column.
1029 const ViewProperties
props(url
);
1031 const Mode mode
= props
.viewMode();
1032 if (m_mode
!= mode
) {
1037 if (itemView() == 0) {
1040 Q_ASSERT(itemView() != 0);
1041 Q_ASSERT(m_fileItemDelegate
!= 0);
1043 const bool showHiddenFiles
= props
.showHiddenFiles();
1044 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
1045 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
1046 emit
showHiddenFilesChanged();
1049 m_storedCategorizedSorting
= props
.categorizedSorting();
1050 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1051 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
1052 m_proxyModel
->setCategorizedModel(categorized
);
1053 emit
categorizedSortingChanged();
1056 const DolphinView::Sorting sorting
= props
.sorting();
1057 if (sorting
!= m_proxyModel
->sorting()) {
1058 m_proxyModel
->setSorting(sorting
);
1059 emit
sortingChanged(sorting
);
1062 const Qt::SortOrder sortOrder
= props
.sortOrder();
1063 if (sortOrder
!= m_proxyModel
->sortOrder()) {
1064 m_proxyModel
->setSortOrder(sortOrder
);
1065 emit
sortOrderChanged(sortOrder
);
1068 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1069 if (info
!= m_fileItemDelegate
->showInformation()) {
1070 m_fileItemDelegate
->setShowInformation(info
);
1071 emit
additionalInfoChanged();
1074 const bool showPreview
= props
.showPreview();
1075 if (showPreview
!= m_showPreview
) {
1076 m_showPreview
= showPreview
;
1077 m_iconManager
->setShowPreview(showPreview
);
1078 emit
showPreviewChanged();
1082 void DolphinView::createView()
1085 Q_ASSERT(m_iconsView
== 0);
1086 Q_ASSERT(m_detailsView
== 0);
1087 Q_ASSERT(m_columnView
== 0);
1089 QAbstractItemView
* view
= 0;
1092 m_iconsView
= new DolphinIconsView(this, m_controller
);
1098 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1099 view
= m_detailsView
;
1103 m_columnView
= new DolphinColumnView(this, m_controller
);
1104 view
= m_columnView
;
1108 Q_ASSERT(view
!= 0);
1109 view
->installEventFilter(this);
1111 m_controller
->setItemView(view
);
1113 m_fileItemDelegate
= new KFileItemDelegate(view
);
1114 view
->setItemDelegate(m_fileItemDelegate
);
1116 view
->setModel(m_proxyModel
);
1117 if (m_selectionModel
!= 0) {
1118 view
->setSelectionModel(m_selectionModel
);
1120 m_selectionModel
= view
->selectionModel();
1123 // reparent the selection model, as it should not be deleted
1124 // when deleting the model
1125 m_selectionModel
->setParent(this);
1127 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1129 new KMimeTypeResolver(view
, m_dolphinModel
);
1130 m_iconManager
= new IconManager(view
, m_proxyModel
);
1131 m_iconManager
->setShowPreview(m_showPreview
);
1133 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1134 m_toolTipManager
= new ToolTipManager(view
, m_proxyModel
);
1137 m_topLayout
->insertWidget(1, view
);
1139 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1140 this, SLOT(emitSelectionChangedSignal()));
1141 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1142 this, SLOT(emitContentsMoved()));
1143 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1144 this, SLOT(emitContentsMoved()));
1147 void DolphinView::deleteView()
1149 QAbstractItemView
* view
= itemView();
1151 m_topLayout
->removeWidget(view
);
1153 view
->deleteLater();
1158 m_fileItemDelegate
= 0;
1160 m_toolTipManager
= 0;
1164 QAbstractItemView
* DolphinView::itemView() const
1166 if (m_detailsView
!= 0) {
1167 return m_detailsView
;
1168 } else if (m_columnView
!= 0) {
1169 return m_columnView
;
1175 bool DolphinView::isCutItem(const KFileItem
& item
) const
1177 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1178 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1180 const KUrl
& itemUrl
= item
.url();
1181 KUrl::List::const_iterator it
= cutUrls
.begin();
1182 const KUrl::List::const_iterator end
= cutUrls
.end();
1184 if (*it
== itemUrl
) {
1193 void DolphinView::pasteToUrl(const KUrl
& url
)
1195 QClipboard
* clipboard
= QApplication::clipboard();
1196 const QMimeData
* mimeData
= clipboard
->mimeData();
1198 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1199 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
1200 KonqOperations::copy(this, KonqOperations::MOVE
, sourceUrls
, url
);
1201 emit
doingOperation(KIO::FileUndoManager::Move
);
1204 KonqOperations::copy(this, KonqOperations::COPY
, sourceUrls
, url
);
1205 emit
doingOperation(KIO::FileUndoManager::Copy
);
1209 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1211 emit
requestUrlChange(url
);
1212 m_controller
->setUrl(url
);
1215 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1217 if (oldUrl
== m_controller
->url()) {
1218 m_controller
->setUrl(newUrl
);
1222 #include "dolphinview.moc"