1 /***************************************************************************
2 * Copyright (C) 2006-2009 by Peter Penz <peter.penz19@gmail.com> *
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 <config-baloo.h>
25 #include <QAbstractItemView>
26 #include <QApplication>
30 #include <QGraphicsSceneDragDropEvent>
32 #include <QItemSelection>
38 #include <KDesktopFile>
39 #include <KProtocolManager>
40 #include <KActionCollection>
41 #include <KColorScheme>
43 #include <KIconEffect>
45 #include <KFileItemListProperties>
47 #include <kitemviews/kfileitemmodel.h>
48 #include <kitemviews/kfileitemlistview.h>
49 #include <kitemviews/kitemlistcontainer.h>
50 #include <kitemviews/kitemlistheader.h>
51 #include <kitemviews/kitemlistselectionmanager.h>
52 #include <kitemviews/kitemlistview.h>
53 #include <kitemviews/kitemlistcontroller.h>
54 #include <KIO/DeleteJob>
55 #include <KIO/JobUiDelegate>
56 #include <KIO/NetAccess>
57 #include <KIO/PreviewJob>
61 #include <KMessageBox>
62 #include <KJobWidgets>
63 #include <konq_operations.h>
64 #include <konqmimedata.h>
65 #include <KToggleAction>
68 #include "dolphinnewfilemenuobserver.h"
69 #include "dolphin_detailsmodesettings.h"
70 #include "dolphin_generalsettings.h"
71 #include "dolphinitemlistview.h"
72 #include "draganddrophelper.h"
73 #include "renamedialog.h"
74 #include "versioncontrol/versioncontrolobserver.h"
75 #include "viewmodecontroller.h"
76 #include "viewproperties.h"
77 #include "views/tooltips/tooltipmanager.h"
78 #include "zoomlevelinfo.h"
81 #include <Baloo/IndexerConfig>
85 const int MaxModeEnum
= DolphinView::CompactView
;
88 DolphinView::DolphinView(const KUrl
& url
, QWidget
* parent
) :
91 m_tabsForFiles(false),
92 m_assureVisibleCurrentIndex(false),
93 m_isFolderWritable(true),
96 m_viewPropertiesContext(),
97 m_mode(DolphinView::IconsView
),
104 m_selectionChangedTimer(0),
106 m_scrollToCurrentItem(false),
107 m_restoredContentsPosition(),
109 m_clearSelectionBeforeSelectingNewItems(false),
110 m_markFirstNewlySelectedItemAsCurrent(false),
111 m_versionControlObserver(0)
113 m_topLayout
= new QVBoxLayout(this);
114 m_topLayout
->setSpacing(0);
115 m_topLayout
->setMargin(0);
117 // When a new item has been created by the "Create New..." menu, the item should
118 // get selected and it must be assured that the item will get visible. As the
119 // creation is done asynchronously, several signals must be checked:
120 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::itemCreated
,
121 this, &DolphinView::observeCreatedItem
);
123 m_selectionChangedTimer
= new QTimer(this);
124 m_selectionChangedTimer
->setSingleShot(true);
125 m_selectionChangedTimer
->setInterval(300);
126 connect(m_selectionChangedTimer
, &QTimer::timeout
,
127 this, &DolphinView::emitSelectionChangedSignal
);
129 m_model
= new KFileItemModel(this);
130 m_view
= new DolphinItemListView();
131 m_view
->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
132 m_view
->setVisibleRoles(QList
<QByteArray
>() << "text");
135 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
136 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
137 controller
->setAutoActivationDelay(delay
);
139 // The EnlargeSmallPreviews setting can only be changed after the model
140 // has been set in the view by KItemListController.
141 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
143 m_container
= new KItemListContainer(controller
, this);
144 m_container
->installEventFilter(this);
145 setFocusProxy(m_container
);
146 connect(m_container
->horizontalScrollBar(), &QScrollBar::valueChanged
, this, &DolphinView::hideToolTip
);
147 connect(m_container
->verticalScrollBar(), &QScrollBar::valueChanged
, this, &DolphinView::hideToolTip
);
149 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
150 connect(controller
, &KItemListController::itemActivated
, this, &DolphinView::slotItemActivated
);
151 connect(controller
, &KItemListController::itemsActivated
, this, &DolphinView::slotItemsActivated
);
152 connect(controller
, &KItemListController::itemMiddleClicked
, this, &DolphinView::slotItemMiddleClicked
);
153 connect(controller
, &KItemListController::itemContextMenuRequested
, this, &DolphinView::slotItemContextMenuRequested
);
154 connect(controller
, &KItemListController::viewContextMenuRequested
, this, &DolphinView::slotViewContextMenuRequested
);
155 connect(controller
, &KItemListController::headerContextMenuRequested
, this, &DolphinView::slotHeaderContextMenuRequested
);
156 connect(controller
, &KItemListController::mouseButtonPressed
, this, &DolphinView::slotMouseButtonPressed
);
157 connect(controller
, &KItemListController::itemHovered
, this, &DolphinView::slotItemHovered
);
158 connect(controller
, &KItemListController::itemUnhovered
, this, &DolphinView::slotItemUnhovered
);
159 connect(controller
, &KItemListController::itemDropEvent
, this, &DolphinView::slotItemDropEvent
);
160 connect(controller
, &KItemListController::escapePressed
, this, &DolphinView::stopLoading
);
161 connect(controller
, &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
163 connect(m_model
, &KFileItemModel::directoryLoadingStarted
, this, &DolphinView::slotDirectoryLoadingStarted
);
164 connect(m_model
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
165 connect(m_model
, &KFileItemModel::directoryLoadingCanceled
, this, &DolphinView::directoryLoadingCanceled
);
166 connect(m_model
, &KFileItemModel::directoryLoadingProgress
, this, &DolphinView::directoryLoadingProgress
);
167 connect(m_model
, &KFileItemModel::directorySortingProgress
, this, &DolphinView::directorySortingProgress
);
168 connect(m_model
, &KFileItemModel::itemsChanged
,
169 this, &DolphinView::slotItemsChanged
);
170 connect(m_model
, &KFileItemModel::itemsRemoved
, this, &DolphinView::itemCountChanged
);
171 connect(m_model
, &KFileItemModel::itemsInserted
, this, &DolphinView::itemCountChanged
);
172 connect(m_model
, &KFileItemModel::infoMessage
, this, &DolphinView::infoMessage
);
173 connect(m_model
, &KFileItemModel::errorMessage
, this, &DolphinView::errorMessage
);
174 connect(m_model
, &KFileItemModel::directoryRedirection
, this, &DolphinView::slotDirectoryRedirection
);
175 connect(m_model
, &KFileItemModel::urlIsFileError
, this, &DolphinView::urlIsFileError
);
177 m_view
->installEventFilter(this);
178 connect(m_view
, &DolphinItemListView::sortOrderChanged
,
179 this, &DolphinView::slotSortOrderChangedByHeader
);
180 connect(m_view
, &DolphinItemListView::sortRoleChanged
,
181 this, &DolphinView::slotSortRoleChangedByHeader
);
182 connect(m_view
, &DolphinItemListView::visibleRolesChanged
,
183 this, &DolphinView::slotVisibleRolesChangedByHeader
);
184 connect(m_view
, &DolphinItemListView::roleEditingCanceled
,
185 this, &DolphinView::slotRoleEditingCanceled
);
186 connect(m_view
->header(), &KItemListHeader::columnWidthChanged
,
187 this, &DolphinView::slotHeaderColumnWidthChanged
);
189 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
190 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
,
191 this, &DolphinView::slotSelectionChanged
);
193 m_toolTipManager
= new ToolTipManager(this);
195 m_versionControlObserver
= new VersionControlObserver(this);
196 m_versionControlObserver
->setModel(m_model
);
197 connect(m_versionControlObserver
, &VersionControlObserver::infoMessage
, this, &DolphinView::infoMessage
);
198 connect(m_versionControlObserver
, &VersionControlObserver::errorMessage
, this, &DolphinView::errorMessage
);
199 connect(m_versionControlObserver
, &VersionControlObserver::operationCompletedMessage
, this, &DolphinView::operationCompletedMessage
);
201 applyViewProperties();
202 m_topLayout
->addWidget(m_container
);
207 DolphinView::~DolphinView()
211 KUrl
DolphinView::url() const
216 void DolphinView::setActive(bool active
)
218 if (active
== m_active
) {
224 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
229 QWidget
* viewport
= m_container
->viewport();
232 palette
.setColor(viewport
->backgroundRole(), color
);
233 viewport
->setPalette(palette
);
239 m_container
->setFocus();
241 emit
writeStateChanged(m_isFolderWritable
);
245 bool DolphinView::isActive() const
250 void DolphinView::setMode(Mode mode
)
252 if (mode
!= m_mode
) {
253 ViewProperties
props(viewPropertiesUrl());
254 props
.setViewMode(mode
);
256 // We pass the new ViewProperties to applyViewProperties, rather than
257 // storing them on disk and letting applyViewProperties() read them
258 // from there, to prevent that changing the view mode fails if the
259 // .directory file is not writable (see bug 318534).
260 applyViewProperties(props
);
264 DolphinView::Mode
DolphinView::mode() const
269 void DolphinView::setPreviewsShown(bool show
)
271 if (previewsShown() == show
) {
275 ViewProperties
props(viewPropertiesUrl());
276 props
.setPreviewsShown(show
);
278 const int oldZoomLevel
= m_view
->zoomLevel();
279 m_view
->setPreviewsShown(show
);
280 emit
previewsShownChanged(show
);
282 const int newZoomLevel
= m_view
->zoomLevel();
283 if (newZoomLevel
!= oldZoomLevel
) {
284 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
288 bool DolphinView::previewsShown() const
290 return m_view
->previewsShown();
293 void DolphinView::setHiddenFilesShown(bool show
)
295 if (m_model
->showHiddenFiles() == show
) {
299 const KFileItemList itemList
= selectedItems();
300 m_selectedUrls
.clear();
301 m_selectedUrls
= KUrl::List(itemList
.urlList());
303 ViewProperties
props(viewPropertiesUrl());
304 props
.setHiddenFilesShown(show
);
306 m_model
->setShowHiddenFiles(show
);
307 emit
hiddenFilesShownChanged(show
);
310 bool DolphinView::hiddenFilesShown() const
312 return m_model
->showHiddenFiles();
315 void DolphinView::setGroupedSorting(bool grouped
)
317 if (grouped
== groupedSorting()) {
321 ViewProperties
props(viewPropertiesUrl());
322 props
.setGroupedSorting(grouped
);
325 m_container
->controller()->model()->setGroupedSorting(grouped
);
327 emit
groupedSortingChanged(grouped
);
330 bool DolphinView::groupedSorting() const
332 return m_model
->groupedSorting();
335 KFileItemList
DolphinView::items() const
338 const int itemCount
= m_model
->count();
339 list
.reserve(itemCount
);
341 for (int i
= 0; i
< itemCount
; ++i
) {
342 list
.append(m_model
->fileItem(i
));
348 int DolphinView::itemsCount() const
350 return m_model
->count();
353 KFileItemList
DolphinView::selectedItems() const
355 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
357 KFileItemList selectedItems
;
358 foreach (int index
, selectionManager
->selectedItems()) {
359 selectedItems
.append(m_model
->fileItem(index
));
361 return selectedItems
;
364 int DolphinView::selectedItemsCount() const
366 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
367 return selectionManager
->selectedItems().count();
370 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
372 m_selectedUrls
= urls
;
375 void DolphinView::markUrlAsCurrent(const KUrl
& url
)
377 m_currentItemUrl
= url
;
378 m_scrollToCurrentItem
= true;
381 void DolphinView::selectItems(const QRegExp
& pattern
, bool enabled
)
383 const KItemListSelectionManager::SelectionMode mode
= enabled
384 ? KItemListSelectionManager::Select
385 : KItemListSelectionManager::Deselect
;
386 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
388 for (int index
= 0; index
< m_model
->count(); index
++) {
389 const KFileItem item
= m_model
->fileItem(index
);
390 if (pattern
.exactMatch(item
.text())) {
391 // An alternative approach would be to store the matching items in a KItemSet and
392 // select them in one go after the loop, but we'd need a new function
393 // KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode)
395 selectionManager
->setSelected(index
, 1, mode
);
400 void DolphinView::setZoomLevel(int level
)
402 const int oldZoomLevel
= zoomLevel();
403 m_view
->setZoomLevel(level
);
404 if (zoomLevel() != oldZoomLevel
) {
406 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
410 int DolphinView::zoomLevel() const
412 return m_view
->zoomLevel();
415 void DolphinView::setSortRole(const QByteArray
& role
)
417 if (role
!= sortRole()) {
418 updateSortRole(role
);
422 QByteArray
DolphinView::sortRole() const
424 const KItemModelBase
* model
= m_container
->controller()->model();
425 return model
->sortRole();
428 void DolphinView::setSortOrder(Qt::SortOrder order
)
430 if (sortOrder() != order
) {
431 updateSortOrder(order
);
435 Qt::SortOrder
DolphinView::sortOrder() const
437 return m_model
->sortOrder();
440 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
442 if (sortFoldersFirst() != foldersFirst
) {
443 updateSortFoldersFirst(foldersFirst
);
447 bool DolphinView::sortFoldersFirst() const
449 return m_model
->sortDirectoriesFirst();
452 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
454 const QList
<QByteArray
> previousRoles
= roles
;
456 ViewProperties
props(viewPropertiesUrl());
457 props
.setVisibleRoles(roles
);
459 m_visibleRoles
= roles
;
460 m_view
->setVisibleRoles(roles
);
462 emit
visibleRolesChanged(m_visibleRoles
, previousRoles
);
465 QList
<QByteArray
> DolphinView::visibleRoles() const
467 return m_visibleRoles
;
470 void DolphinView::reload()
472 QByteArray viewState
;
473 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
474 saveState(saveStream
);
476 const KFileItemList itemList
= selectedItems();
477 m_selectedUrls
.clear();
478 m_selectedUrls
= KUrl::List(itemList
.urlList());
481 loadDirectory(url(), true);
483 QDataStream
restoreStream(viewState
);
484 restoreState(restoreStream
);
487 void DolphinView::readSettings()
489 const int oldZoomLevel
= m_view
->zoomLevel();
491 GeneralSettings::self()->readConfig();
492 m_view
->readSettings();
493 applyViewProperties();
495 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
496 m_container
->controller()->setAutoActivationDelay(delay
);
498 const int newZoomLevel
= m_view
->zoomLevel();
499 if (newZoomLevel
!= oldZoomLevel
) {
500 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
504 void DolphinView::writeSettings()
506 GeneralSettings::self()->writeConfig();
507 m_view
->writeSettings();
510 void DolphinView::setNameFilter(const QString
& nameFilter
)
512 m_model
->setNameFilter(nameFilter
);
515 QString
DolphinView::nameFilter() const
517 return m_model
->nameFilter();
520 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
522 return m_model
->setMimeTypeFilters(filters
);
525 QStringList
DolphinView::mimeTypeFilters() const
527 return m_model
->mimeTypeFilters();
530 QString
DolphinView::statusBarText() const
538 KIO::filesize_t totalFileSize
= 0;
540 if (m_container
->controller()->selectionManager()->hasSelection()) {
541 // Give a summary of the status of the selected files
542 const KFileItemList list
= selectedItems();
543 foreach (const KFileItem
& item
, list
) {
548 totalFileSize
+= item
.size();
552 if (folderCount
+ fileCount
== 1) {
553 // If only one item is selected, show info about it
554 return list
.first().getStatusBarInfo();
556 // At least 2 items are selected
557 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
558 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
561 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
562 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
563 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
566 if (fileCount
> 0 && folderCount
> 0) {
567 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
568 foldersText
, filesText
,
569 KGlobal::locale()->formatByteSize(totalFileSize
));
570 } else if (fileCount
> 0) {
571 summary
= i18nc("@info:status files (size)", "%1 (%2)",
573 KGlobal::locale()->formatByteSize(totalFileSize
));
574 } else if (folderCount
> 0) {
575 summary
= foldersText
;
577 summary
= i18nc("@info:status", "0 Folders, 0 Files");
583 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
585 QList
<QAction
*> actions
;
587 if (items
.isEmpty()) {
588 const KFileItem item
= m_model
->rootItem();
589 if (!item
.isNull()) {
590 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
593 actions
= m_versionControlObserver
->actions(items
);
599 void DolphinView::setUrl(const KUrl
& url
)
607 emit
urlAboutToBeChanged(url
);
612 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
613 this, &DolphinView::slotRoleEditingFinished
);
615 // It is important to clear the items from the model before
616 // applying the view properties, otherwise expensive operations
617 // might be done on the existing items although they get cleared
618 // anyhow afterwards by loadDirectory().
620 applyViewProperties();
623 emit
urlChanged(url
);
626 void DolphinView::selectAll()
628 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
629 selectionManager
->setSelected(0, m_model
->count());
632 void DolphinView::invertSelection()
634 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
635 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
638 void DolphinView::clearSelection()
640 m_selectedUrls
.clear();
641 m_container
->controller()->selectionManager()->clearSelection();
644 void DolphinView::renameSelectedItems()
646 const KFileItemList items
= selectedItems();
647 if (items
.isEmpty()) {
651 if (items
.count() == 1 && GeneralSettings::renameInline()) {
652 const int index
= m_model
->index(items
.first());
653 m_view
->editRole(index
, "text");
657 connect(m_view
, &DolphinItemListView::roleEditingFinished
,
658 this, &DolphinView::slotRoleEditingFinished
);
660 RenameDialog
* dialog
= new RenameDialog(this, items
);
661 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
664 dialog
->activateWindow();
667 // Assure that the current index remains visible when KFileItemModel
668 // will notify the view about changed items (which might result in
669 // a changed sorting).
670 m_assureVisibleCurrentIndex
= true;
673 void DolphinView::trashSelectedItems()
675 const KUrl::List list
= simplifiedSelectedUrls();
676 KonqOperations::del(this, KonqOperations::TRASH
, list
);
679 void DolphinView::deleteSelectedItems()
681 const KUrl::List list
= simplifiedSelectedUrls();
682 const bool del
= KonqOperations::askDeleteConfirmation(list
,
684 KonqOperations::DEFAULT_CONFIRMATION
,
688 KIO::Job
* job
= KIO::del(list
);
690 KJobWidgets::setWindow(job
, this);
692 connect(job
, &KIO::Job::result
,
693 this, &DolphinView::slotDeleteFileFinished
);
697 void DolphinView::cutSelectedItems()
699 QMimeData
* mimeData
= selectionMimeData();
700 KonqMimeData::addIsCutSelection(mimeData
, true);
701 QApplication::clipboard()->setMimeData(mimeData
);
704 void DolphinView::copySelectedItems()
706 QMimeData
* mimeData
= selectionMimeData();
707 QApplication::clipboard()->setMimeData(mimeData
);
710 void DolphinView::paste()
715 void DolphinView::pasteIntoFolder()
717 const KFileItemList items
= selectedItems();
718 if ((items
.count() == 1) && items
.first().isDir()) {
719 pasteToUrl(items
.first().url());
723 void DolphinView::stopLoading()
725 m_model
->cancelDirectoryLoading();
728 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
730 switch (event
->type()) {
731 case QEvent::FocusIn
:
732 if (watched
== m_container
) {
737 case QEvent::GraphicsSceneDragEnter
:
738 if (watched
== m_view
) {
743 case QEvent::GraphicsSceneDragLeave
:
744 if (watched
== m_view
) {
749 case QEvent::GraphicsSceneDrop
:
750 if (watched
== m_view
) {
757 return QWidget::eventFilter(watched
, event
);
760 void DolphinView::wheelEvent(QWheelEvent
* event
)
762 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
763 const int numDegrees
= event
->delta() / 8;
764 const int numSteps
= numDegrees
/ 15;
766 setZoomLevel(zoomLevel() + numSteps
);
773 void DolphinView::hideEvent(QHideEvent
* event
)
776 QWidget::hideEvent(event
);
779 bool DolphinView::event(QEvent
* event
)
782 * Dolphin leaves file preview tooltips open even when is not visible.
784 * Hide tool-tip when Dolphin loses focus.
786 if (event
->type() == QEvent::WindowDeactivate
) {
790 return QWidget::event(event
);
793 void DolphinView::activate()
798 void DolphinView::slotItemActivated(int index
)
800 const KFileItem item
= m_model
->fileItem(index
);
801 if (!item
.isNull()) {
802 emit
itemActivated(item
);
806 void DolphinView::slotItemsActivated(const KItemSet
& indexes
)
808 Q_ASSERT(indexes
.count() >= 2);
810 if (indexes
.count() > 5) {
811 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
812 const int answer
= KMessageBox::warningYesNo(this, question
);
813 if (answer
!= KMessageBox::Yes
) {
819 items
.reserve(indexes
.count());
821 foreach (int index
, indexes
) {
822 KFileItem item
= m_model
->fileItem(index
);
823 const KUrl
& url
= openItemAsFolderUrl(item
);
825 if (!url
.isEmpty()) { // Open folders in new tabs
826 emit
tabRequested(url
);
832 if (items
.count() == 1) {
833 emit
itemActivated(items
.first());
834 } else if (items
.count() > 1) {
835 emit
itemsActivated(items
);
839 void DolphinView::slotItemMiddleClicked(int index
)
841 const KFileItem
& item
= m_model
->fileItem(index
);
842 const KUrl
& url
= openItemAsFolderUrl(item
);
843 if (!url
.isEmpty()) {
844 emit
tabRequested(url
);
845 } else if (isTabsForFilesEnabled()) {
846 emit
tabRequested(item
.url());
850 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
852 // Force emit of a selection changed signal before we request the
853 // context menu, to update the edit-actions first. (See Bug 294013)
854 if (m_selectionChangedTimer
->isActive()) {
855 emitSelectionChangedSignal();
858 const KFileItem item
= m_model
->fileItem(index
);
859 emit
requestContextMenu(pos
.toPoint(), item
, url(), QList
<QAction
*>());
862 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
864 emit
requestContextMenu(pos
.toPoint(), KFileItem(), url(), QList
<QAction
*>());
867 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
869 ViewProperties
props(viewPropertiesUrl());
871 QPointer
<KMenu
> menu
= new KMenu(QApplication::activeWindow());
873 KItemListView
* view
= m_container
->controller()->view();
874 const QSet
<QByteArray
> visibleRolesSet
= view
->visibleRoles().toSet();
876 bool indexingEnabled
= false;
878 Baloo::IndexerConfig config
;
879 indexingEnabled
= config
.fileIndexingEnabled();
883 QMenu
* groupMenu
= 0;
885 // Add all roles to the menu that can be shown or hidden by the user
886 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
887 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
888 if (info
.role
== "text") {
889 // It should not be possible to hide the "text" role
893 const QString text
= m_model
->roleDescription(info
.role
);
895 if (info
.group
.isEmpty()) {
896 action
= menu
->addAction(text
);
898 if (!groupMenu
|| info
.group
!= groupName
) {
899 groupName
= info
.group
;
900 groupMenu
= menu
->addMenu(groupName
);
903 action
= groupMenu
->addAction(text
);
906 action
->setCheckable(true);
907 action
->setChecked(visibleRolesSet
.contains(info
.role
));
908 action
->setData(info
.role
);
910 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
911 (info
.requiresBaloo
) ||
912 (info
.requiresIndexer
&& indexingEnabled
);
913 action
->setEnabled(enable
);
916 menu
->addSeparator();
918 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
919 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
921 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
922 autoAdjustWidthsAction
->setCheckable(true);
923 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
924 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
926 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
927 customWidthsAction
->setCheckable(true);
928 customWidthsAction
->setChecked(!autoColumnWidths
);
929 customWidthsAction
->setActionGroup(widthsGroup
);
931 QAction
* action
= menu
->exec(pos
.toPoint());
932 if (menu
&& action
) {
933 KItemListHeader
* header
= view
->header();
935 if (action
== autoAdjustWidthsAction
) {
936 // Clear the column-widths from the viewproperties and turn on
937 // the automatic resizing of the columns
938 props
.setHeaderColumnWidths(QList
<int>());
939 header
->setAutomaticColumnResizing(true);
940 } else if (action
== customWidthsAction
) {
941 // Apply the current column-widths as custom column-widths and turn
942 // off the automatic resizing of the columns
943 QList
<int> columnWidths
;
944 foreach (const QByteArray
& role
, view
->visibleRoles()) {
945 columnWidths
.append(header
->columnWidth(role
));
947 props
.setHeaderColumnWidths(columnWidths
);
948 header
->setAutomaticColumnResizing(false);
950 // Show or hide the selected role
951 const QByteArray selectedRole
= action
->data().toByteArray();
953 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
954 if (action
->isChecked()) {
955 visibleRoles
.append(selectedRole
);
957 visibleRoles
.removeOne(selectedRole
);
960 view
->setVisibleRoles(visibleRoles
);
961 props
.setVisibleRoles(visibleRoles
);
963 QList
<int> columnWidths
;
964 if (!header
->automaticColumnResizing()) {
965 foreach (const QByteArray
& role
, view
->visibleRoles()) {
966 columnWidths
.append(header
->columnWidth(role
));
969 props
.setHeaderColumnWidths(columnWidths
);
976 void DolphinView::slotHeaderColumnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
)
980 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
982 ViewProperties
props(viewPropertiesUrl());
983 QList
<int> columnWidths
= props
.headerColumnWidths();
984 if (columnWidths
.count() != visibleRoles
.count()) {
985 columnWidths
.clear();
986 columnWidths
.reserve(visibleRoles
.count());
987 const KItemListHeader
* header
= m_view
->header();
988 foreach (const QByteArray
& role
, visibleRoles
) {
989 const int width
= header
->columnWidth(role
);
990 columnWidths
.append(width
);
994 const int roleIndex
= visibleRoles
.indexOf(role
);
995 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
996 columnWidths
[roleIndex
] = current
;
998 props
.setHeaderColumnWidths(columnWidths
);
1001 void DolphinView::slotItemHovered(int index
)
1003 const KFileItem item
= m_model
->fileItem(index
);
1005 if (GeneralSettings::showToolTips() && !m_dragging
) {
1006 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1007 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1008 itemRect
.moveTo(pos
);
1010 m_toolTipManager
->showToolTip(item
, itemRect
);
1013 emit
requestItemInfo(item
);
1016 void DolphinView::slotItemUnhovered(int index
)
1020 emit
requestItemInfo(KFileItem());
1023 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1026 KFileItem destItem
= m_model
->fileItem(index
);
1027 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1028 // Use the URL of the view as drop target if the item is no directory
1030 destItem
= m_model
->rootItem();
1033 // The item represents a directory or desktop-file
1034 destUrl
= destItem
.url();
1037 QDropEvent
dropEvent(event
->pos().toPoint(),
1038 event
->possibleActions(),
1041 event
->modifiers());
1044 KonqOperations
* op
= DragAndDropHelper::dropUrls(destItem
, destUrl
, &dropEvent
, error
);
1045 if (!error
.isEmpty()) {
1046 emit
infoMessage(error
);
1049 if (op
&& destUrl
== url()) {
1050 // Mark the dropped urls as selected.
1051 m_clearSelectionBeforeSelectingNewItems
= true;
1052 m_markFirstNewlySelectedItemAsCurrent
= true;
1053 connect(op
, static_cast<void(KonqOperations::*)(const KUrl::List
&)>(&KonqOperations::aboutToCreate
), this, &DolphinView::slotAboutToCreate
);
1059 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1061 if (previous
!= 0) {
1062 Q_ASSERT(qobject_cast
<KFileItemModel
*>(previous
));
1063 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(previous
);
1064 disconnect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1065 m_versionControlObserver
->setModel(0);
1069 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1070 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1071 connect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1072 m_versionControlObserver
->setModel(fileItemModel
);
1076 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1078 Q_UNUSED(itemIndex
);
1082 // TODO: Qt5: Replace Qt::XButton1 by Qt::BackButton and Qt::XButton2 by Qt::ForwardButton
1083 if (buttons
& Qt::XButton1
) {
1084 emit
goBackRequested();
1085 } else if (buttons
& Qt::XButton2
) {
1086 emit
goForwardRequested();
1090 void DolphinView::slotAboutToCreate(const KUrl::List
& urls
)
1092 if (!urls
.isEmpty()) {
1093 if (m_markFirstNewlySelectedItemAsCurrent
) {
1094 markUrlAsCurrent(urls
.first());
1095 m_markFirstNewlySelectedItemAsCurrent
= false;
1097 m_selectedUrls
<< KUrl::List(KDirModel::simplifiedUrlList(urls
));
1101 void DolphinView::slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
)
1103 const int currentCount
= current
.count();
1104 const int previousCount
= previous
.count();
1105 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1106 (currentCount
> 0 && previousCount
== 0);
1108 // If nothing has been selected before and something got selected (or if something
1109 // was selected before and now nothing is selected) the selectionChangedSignal must
1110 // be emitted asynchronously as fast as possible to update the edit-actions.
1111 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1112 m_selectionChangedTimer
->start();
1115 void DolphinView::emitSelectionChangedSignal()
1117 m_selectionChangedTimer
->stop();
1118 emit
selectionChanged(selectedItems());
1121 void DolphinView::updateSortRole(const QByteArray
& role
)
1123 ViewProperties
props(viewPropertiesUrl());
1124 props
.setSortRole(role
);
1126 KItemModelBase
* model
= m_container
->controller()->model();
1127 model
->setSortRole(role
);
1129 emit
sortRoleChanged(role
);
1132 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1134 ViewProperties
props(viewPropertiesUrl());
1135 props
.setSortOrder(order
);
1137 m_model
->setSortOrder(order
);
1139 emit
sortOrderChanged(order
);
1142 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1144 ViewProperties
props(viewPropertiesUrl());
1145 props
.setSortFoldersFirst(foldersFirst
);
1147 m_model
->setSortDirectoriesFirst(foldersFirst
);
1149 emit
sortFoldersFirstChanged(foldersFirst
);
1152 QPair
<bool, QString
> DolphinView::pasteInfo() const
1154 return KonqOperations::pasteInfo(url());
1157 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1159 m_tabsForFiles
= tabsForFiles
;
1162 bool DolphinView::isTabsForFilesEnabled() const
1164 return m_tabsForFiles
;
1167 bool DolphinView::itemsExpandable() const
1169 return m_mode
== DetailsView
;
1172 void DolphinView::restoreState(QDataStream
& stream
)
1174 // Restore the current item that had the keyboard focus
1175 stream
>> m_currentItemUrl
;
1177 // Restore the view position
1178 stream
>> m_restoredContentsPosition
;
1180 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1183 m_model
->restoreExpandedDirectories(urls
);
1186 void DolphinView::saveState(QDataStream
& stream
)
1188 // Save the current item that has the keyboard focus
1189 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1190 if (currentIndex
!= -1) {
1191 KFileItem item
= m_model
->fileItem(currentIndex
);
1192 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1193 KUrl currentItemUrl
= item
.url();
1194 stream
<< currentItemUrl
;
1199 // Save view position
1200 const qreal x
= m_container
->horizontalScrollBar()->value();
1201 const qreal y
= m_container
->verticalScrollBar()->value();
1202 stream
<< QPoint(x
, y
);
1204 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1205 stream
<< m_model
->expandedDirectories();
1208 KFileItem
DolphinView::rootItem() const
1210 return m_model
->rootItem();
1213 void DolphinView::setViewPropertiesContext(const QString
& context
)
1215 m_viewPropertiesContext
= context
;
1218 QString
DolphinView::viewPropertiesContext() const
1220 return m_viewPropertiesContext
;
1223 KUrl
DolphinView::openItemAsFolderUrl(const KFileItem
& item
, const bool browseThroughArchives
)
1225 if (item
.isNull()) {
1229 KUrl url
= item
.targetUrl();
1235 if (item
.isMimeTypeKnown()) {
1236 const QString
& mimetype
= item
.mimetype();
1238 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1239 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1240 // zip:/<path>/ when clicking on a zip file, etc.
1241 // The .protocol file specifies the mimetype that the kioslave handles.
1242 // Note that we don't use mimetype inheritance since we don't want to
1243 // open OpenDocument files as zip folders...
1244 const QString
& protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1245 if (!protocol
.isEmpty()) {
1246 url
.setProtocol(protocol
);
1251 if (mimetype
== QLatin1String("application/x-desktop")) {
1252 // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
1253 KDesktopFile
desktopFile(url
.toLocalFile());
1254 if (desktopFile
.hasLinkType()) {
1255 const QString linkUrl
= desktopFile
.readUrl();
1256 if (!linkUrl
.startsWith(QLatin1String("http"))) {
1266 void DolphinView::observeCreatedItem(const KUrl
& url
)
1270 markUrlAsCurrent(url
);
1271 markUrlsAsSelected(QList
<KUrl
>() << url
);
1275 void DolphinView::slotDirectoryRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1277 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
1278 emit
redirection(oldUrl
, newUrl
);
1279 m_url
= newUrl
; // #186947
1283 void DolphinView::updateViewState()
1285 if (m_currentItemUrl
!= KUrl()) {
1286 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1287 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1288 if (currentIndex
!= -1) {
1289 selectionManager
->setCurrentItem(currentIndex
);
1291 // scroll to current item and reset the state
1292 if (m_scrollToCurrentItem
) {
1293 m_view
->scrollToItem(currentIndex
);
1294 m_scrollToCurrentItem
= false;
1297 m_currentItemUrl
= KUrl();
1299 selectionManager
->setCurrentItem(0);
1303 if (!m_restoredContentsPosition
.isNull()) {
1304 const int x
= m_restoredContentsPosition
.x();
1305 const int y
= m_restoredContentsPosition
.y();
1306 m_restoredContentsPosition
= QPoint();
1308 m_container
->horizontalScrollBar()->setValue(x
);
1309 m_container
->verticalScrollBar()->setValue(y
);
1312 if (!m_selectedUrls
.isEmpty()) {
1313 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1315 if (m_clearSelectionBeforeSelectingNewItems
) {
1316 selectionManager
->clearSelection();
1317 m_clearSelectionBeforeSelectingNewItems
= false;
1320 KItemSet selectedItems
= selectionManager
->selectedItems();
1322 QList
<KUrl
>::iterator it
= m_selectedUrls
.begin();
1323 while (it
!= m_selectedUrls
.end()) {
1324 const int index
= m_model
->index(*it
);
1326 selectedItems
.insert(index
);
1327 it
= m_selectedUrls
.erase(it
);
1333 selectionManager
->setSelectedItems(selectedItems
);
1337 void DolphinView::hideToolTip()
1339 if (GeneralSettings::showToolTips()) {
1340 m_toolTipManager
->hideToolTip();
1344 void DolphinView::calculateItemCount(int& fileCount
,
1346 KIO::filesize_t
& totalFileSize
) const
1348 const int itemCount
= m_model
->count();
1349 for (int i
= 0; i
< itemCount
; ++i
) {
1350 const KFileItem item
= m_model
->fileItem(i
);
1355 totalFileSize
+= item
.size();
1360 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1362 if (job
->error() == 0) {
1363 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1364 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1365 emit
errorMessage(job
->errorString());
1369 void DolphinView::slotRenamingFailed(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1371 const int index
= m_model
->index(newUrl
);
1373 QHash
<QByteArray
, QVariant
> data
;
1374 data
.insert("text", oldUrl
.fileName());
1375 m_model
->setData(index
, data
);
1379 void DolphinView::slotDirectoryLoadingStarted()
1381 // Disable the writestate temporary until it can be determined in a fast way
1382 // in DolphinView::slotLoadingCompleted()
1383 if (m_isFolderWritable
) {
1384 m_isFolderWritable
= false;
1385 emit
writeStateChanged(m_isFolderWritable
);
1388 emit
directoryLoadingStarted();
1391 void DolphinView::slotDirectoryLoadingCompleted()
1393 // Update the view-state. This has to be done asynchronously
1394 // because the view might not be in its final state yet.
1395 QTimer::singleShot(0, this, SLOT(updateViewState()));
1397 emit
directoryLoadingCompleted();
1399 updateWritableState();
1402 void DolphinView::slotItemsChanged()
1404 m_assureVisibleCurrentIndex
= false;
1407 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1410 Q_ASSERT(m_model
->sortOrder() == current
);
1412 ViewProperties
props(viewPropertiesUrl());
1413 props
.setSortOrder(current
);
1415 emit
sortOrderChanged(current
);
1418 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1421 Q_ASSERT(m_model
->sortRole() == current
);
1423 ViewProperties
props(viewPropertiesUrl());
1424 props
.setSortRole(current
);
1426 emit
sortRoleChanged(current
);
1429 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1430 const QList
<QByteArray
>& previous
)
1433 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1435 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1437 m_visibleRoles
= current
;
1439 ViewProperties
props(viewPropertiesUrl());
1440 props
.setVisibleRoles(m_visibleRoles
);
1442 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1445 void DolphinView::slotRoleEditingCanceled()
1447 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1448 this, &DolphinView::slotRoleEditingFinished
);
1451 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1453 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1454 this, &DolphinView::slotRoleEditingFinished
);
1456 if (index
< 0 || index
>= m_model
->count()) {
1460 if (role
== "text") {
1461 const KFileItem oldItem
= m_model
->fileItem(index
);
1462 const QString newName
= value
.toString();
1463 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1String(".") && newName
!= QLatin1String("..")) {
1464 const KUrl oldUrl
= oldItem
.url();
1466 const KUrl
newUrl(url().path(KUrl::AddTrailingSlash
) + newName
);
1467 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1468 if (!newNameExistsAlready
) {
1469 // Only change the data in the model if no item with the new name
1470 // is in the model yet. If there is an item with the new name
1471 // already, calling KonqOperations::rename() will open a dialog
1472 // asking for a new name, and KFileItemModel will update the
1473 // data when the dir lister signals that the file name has changed.
1474 QHash
<QByteArray
, QVariant
> data
;
1475 data
.insert(role
, value
);
1476 m_model
->setData(index
, data
);
1479 KonqOperations
* op
= KonqOperations::renameV2(this, oldUrl
, newName
);
1480 if (op
&& !newNameExistsAlready
) {
1481 // Only connect the renamingFailed signal if there is no item with the new name
1482 // in the model yet, see bug 328262.
1483 connect(op
, &KonqOperations::renamingFailed
, this, &DolphinView::slotRenamingFailed
);
1489 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1491 if (!url
.isValid()) {
1492 const QString
location(url
.pathOrUrl());
1493 if (location
.isEmpty()) {
1494 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1496 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1502 m_model
->refreshDirectory(url
);
1504 m_model
->loadDirectory(url
);
1508 void DolphinView::applyViewProperties()
1510 const ViewProperties
props(viewPropertiesUrl());
1511 applyViewProperties(props
);
1514 void DolphinView::applyViewProperties(const ViewProperties
& props
)
1516 m_view
->beginTransaction();
1518 const Mode mode
= props
.viewMode();
1519 if (m_mode
!= mode
) {
1520 const Mode previousMode
= m_mode
;
1523 // Changing the mode might result in changing
1524 // the zoom level. Remember the old zoom level so
1525 // that zoomLevelChanged() can get emitted.
1526 const int oldZoomLevel
= m_view
->zoomLevel();
1529 emit
modeChanged(m_mode
, previousMode
);
1531 if (m_view
->zoomLevel() != oldZoomLevel
) {
1532 emit
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1536 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1537 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1538 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1539 emit
hiddenFilesShownChanged(hiddenFilesShown
);
1542 const bool groupedSorting
= props
.groupedSorting();
1543 if (groupedSorting
!= m_model
->groupedSorting()) {
1544 m_model
->setGroupedSorting(groupedSorting
);
1545 emit
groupedSortingChanged(groupedSorting
);
1548 const QByteArray sortRole
= props
.sortRole();
1549 if (sortRole
!= m_model
->sortRole()) {
1550 m_model
->setSortRole(sortRole
);
1551 emit
sortRoleChanged(sortRole
);
1554 const Qt::SortOrder sortOrder
= props
.sortOrder();
1555 if (sortOrder
!= m_model
->sortOrder()) {
1556 m_model
->setSortOrder(sortOrder
);
1557 emit
sortOrderChanged(sortOrder
);
1560 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1561 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1562 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1563 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1566 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1567 if (visibleRoles
!= m_visibleRoles
) {
1568 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1569 m_visibleRoles
= visibleRoles
;
1570 m_view
->setVisibleRoles(visibleRoles
);
1571 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1574 const bool previewsShown
= props
.previewsShown();
1575 if (previewsShown
!= m_view
->previewsShown()) {
1576 const int oldZoomLevel
= zoomLevel();
1578 m_view
->setPreviewsShown(previewsShown
);
1579 emit
previewsShownChanged(previewsShown
);
1581 // Changing the preview-state might result in a changed zoom-level
1582 if (oldZoomLevel
!= zoomLevel()) {
1583 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1587 KItemListView
* itemListView
= m_container
->controller()->view();
1588 if (itemListView
->isHeaderVisible()) {
1589 KItemListHeader
* header
= itemListView
->header();
1590 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
1591 const int rolesCount
= m_visibleRoles
.count();
1592 if (headerColumnWidths
.count() == rolesCount
) {
1593 header
->setAutomaticColumnResizing(false);
1595 QHash
<QByteArray
, qreal
> columnWidths
;
1596 for (int i
= 0; i
< rolesCount
; ++i
) {
1597 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
1599 header
->setColumnWidths(columnWidths
);
1601 header
->setAutomaticColumnResizing(true);
1605 m_view
->endTransaction();
1608 void DolphinView::applyModeToView()
1611 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
1612 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
1613 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1614 default: Q_ASSERT(false); break;
1618 void DolphinView::pasteToUrl(const KUrl
& url
)
1620 KonqOperations
* op
= KonqOperations::doPasteV2(this, url
);
1622 m_clearSelectionBeforeSelectingNewItems
= true;
1623 m_markFirstNewlySelectedItemAsCurrent
= true;
1624 connect(op
, static_cast<void(KonqOperations::*)(const KUrl::List
&)>(&KonqOperations::aboutToCreate
), this, &DolphinView::slotAboutToCreate
);
1628 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1632 const KFileItemList items
= selectedItems();
1633 foreach (const KFileItem
& item
, items
) {
1634 urls
.append(item
.url());
1637 if (itemsExpandable()) {
1638 // TODO: Check if we still need KDirModel for this in KDE 5.0
1639 urls
= KDirModel::simplifiedUrlList(urls
);
1645 QMimeData
* DolphinView::selectionMimeData() const
1647 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1648 const KItemSet selectedIndexes
= selectionManager
->selectedItems();
1650 return m_model
->createMimeData(selectedIndexes
);
1653 void DolphinView::updateWritableState()
1655 const bool wasFolderWritable
= m_isFolderWritable
;
1656 m_isFolderWritable
= false;
1658 KFileItem item
= m_model
->rootItem();
1659 if (item
.isNull()) {
1660 // Try to find out if the URL is writable even if the "root item" is
1661 // null, see https://bugs.kde.org/show_bug.cgi?id=330001
1662 item
= KFileItem(KFileItem::Unknown
, KFileItem::Unknown
, url(), true);
1665 KFileItemListProperties
capabilities(KFileItemList() << item
);
1666 m_isFolderWritable
= capabilities
.supportsWriting();
1668 if (m_isFolderWritable
!= wasFolderWritable
) {
1669 emit
writeStateChanged(m_isFolderWritable
);
1673 KUrl
DolphinView::viewPropertiesUrl() const
1675 if (m_viewPropertiesContext
.isEmpty()) {
1680 url
.setProtocol(m_url
.protocol());
1681 url
.setPath(m_viewPropertiesContext
);