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-nepomuk.h>
25 #include <QAbstractItemView>
26 #include <QApplication>
30 #include <QGraphicsSceneDragDropEvent>
32 #include <QItemSelection>
36 #include <KDesktopFile>
37 #include <KProtocolManager>
38 #include <KActionCollection>
39 #include <KColorScheme>
41 #include <KIconEffect>
43 #include <KFileItemListProperties>
45 #include <kitemviews/kfileitemmodel.h>
46 #include <kitemviews/kfileitemlistview.h>
47 #include <kitemviews/kitemlistcontainer.h>
48 #include <kitemviews/kitemlistheader.h>
49 #include <kitemviews/kitemlistselectionmanager.h>
50 #include <kitemviews/kitemlistview.h>
51 #include <kitemviews/kitemlistcontroller.h>
52 #include <KIO/DeleteJob>
53 #include <KIO/JobUiDelegate>
54 #include <KIO/NetAccess>
55 #include <KIO/PreviewJob>
58 #include <KMessageBox>
59 #include <konq_fileitemcapabilities.h>
60 #include <konq_operations.h>
61 #include <konqmimedata.h>
62 #include <KToggleAction>
65 #include "dolphinnewfilemenuobserver.h"
66 #include "dolphin_detailsmodesettings.h"
67 #include "dolphin_generalsettings.h"
68 #include "dolphinitemlistview.h"
69 #include "draganddrophelper.h"
70 #include "renamedialog.h"
71 #include "versioncontrol/versioncontrolobserver.h"
72 #include "viewmodecontroller.h"
73 #include "viewproperties.h"
74 #include "views/tooltips/tooltipmanager.h"
75 #include "zoomlevelinfo.h"
78 #include <Nepomuk2/ResourceManager>
82 const int MaxModeEnum
= DolphinView::CompactView
;
85 DolphinView::DolphinView(const KUrl
& url
, QWidget
* parent
) :
88 m_tabsForFiles(false),
89 m_assureVisibleCurrentIndex(false),
90 m_isFolderWritable(true),
93 m_viewPropertiesContext(),
94 m_mode(DolphinView::IconsView
),
101 m_selectionChangedTimer(0),
103 m_scrollToCurrentItem(false),
104 m_restoredContentsPosition(),
106 m_clearSelectionBeforeSelectingNewItems(false),
107 m_markFirstNewlySelectedItemAsCurrent(false),
108 m_versionControlObserver(0)
110 m_topLayout
= new QVBoxLayout(this);
111 m_topLayout
->setSpacing(0);
112 m_topLayout
->setMargin(0);
114 // When a new item has been created by the "Create New..." menu, the item should
115 // get selected and it must be assured that the item will get visible. As the
116 // creation is done asynchronously, several signals must be checked:
117 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(KUrl
)),
118 this, SLOT(observeCreatedItem(KUrl
)));
120 m_selectionChangedTimer
= new QTimer(this);
121 m_selectionChangedTimer
->setSingleShot(true);
122 m_selectionChangedTimer
->setInterval(300);
123 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
124 this, SLOT(emitSelectionChangedSignal()));
126 m_model
= new KFileItemModel(this);
127 m_view
= new DolphinItemListView();
128 m_view
->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
129 m_view
->setVisibleRoles(QList
<QByteArray
>() << "text");
132 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
133 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
134 controller
->setAutoActivationDelay(delay
);
136 // The EnlargeSmallPreviews setting can only be changed after the model
137 // has been set in the view by KItemListController.
138 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
140 m_container
= new KItemListContainer(controller
, this);
141 m_container
->installEventFilter(this);
142 setFocusProxy(m_container
);
143 connect(m_container
->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip()));
144 connect(m_container
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip()));
146 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
147 connect(controller
, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
148 connect(controller
, SIGNAL(itemsActivated(QSet
<int>)), this, SLOT(slotItemsActivated(QSet
<int>)));
149 connect(controller
, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
150 connect(controller
, SIGNAL(itemContextMenuRequested(int,QPointF
)), this, SLOT(slotItemContextMenuRequested(int,QPointF
)));
151 connect(controller
, SIGNAL(viewContextMenuRequested(QPointF
)), this, SLOT(slotViewContextMenuRequested(QPointF
)));
152 connect(controller
, SIGNAL(headerContextMenuRequested(QPointF
)), this, SLOT(slotHeaderContextMenuRequested(QPointF
)));
153 connect(controller
, SIGNAL(mouseButtonPressed(int,Qt::MouseButtons
)), this, SLOT(slotMouseButtonPressed(int,Qt::MouseButtons
)));
154 connect(controller
, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int)));
155 connect(controller
, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int)));
156 connect(controller
, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent
*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent
*)));
157 connect(controller
, SIGNAL(modelChanged(KItemModelBase
*,KItemModelBase
*)), this, SLOT(slotModelChanged(KItemModelBase
*,KItemModelBase
*)));
159 connect(m_model
, SIGNAL(directoryLoadingStarted()), this, SLOT(slotDirectoryLoadingStarted()));
160 connect(m_model
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
161 connect(m_model
, SIGNAL(directoryLoadingCanceled()), this, SIGNAL(directoryLoadingCanceled()));
162 connect(m_model
, SIGNAL(directoryLoadingProgress(int)), this, SIGNAL(directoryLoadingProgress(int)));
163 connect(m_model
, SIGNAL(directorySortingProgress(int)), this, SIGNAL(directorySortingProgress(int)));
164 connect(m_model
, SIGNAL(itemsChanged(KItemRangeList
,QSet
<QByteArray
>)),
165 this, SLOT(slotItemsChanged()));
166 connect(m_model
, SIGNAL(itemsRemoved(KItemRangeList
)), this, SIGNAL(itemCountChanged()));
167 connect(m_model
, SIGNAL(itemsInserted(KItemRangeList
)), this, SIGNAL(itemCountChanged()));
168 connect(m_model
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
169 connect(m_model
, SIGNAL(errorMessage(QString
)), this, SIGNAL(errorMessage(QString
)));
170 connect(m_model
, SIGNAL(directoryRedirection(KUrl
,KUrl
)), this, SLOT(slotDirectoryRedirection(KUrl
,KUrl
)));
171 connect(m_model
, SIGNAL(urlIsFileError(KUrl
)), this, SIGNAL(urlIsFileError(KUrl
)));
173 m_view
->installEventFilter(this);
174 connect(m_view
, SIGNAL(sortOrderChanged(Qt::SortOrder
,Qt::SortOrder
)),
175 this, SLOT(slotSortOrderChangedByHeader(Qt::SortOrder
,Qt::SortOrder
)));
176 connect(m_view
, SIGNAL(sortRoleChanged(QByteArray
,QByteArray
)),
177 this, SLOT(slotSortRoleChangedByHeader(QByteArray
,QByteArray
)));
178 connect(m_view
, SIGNAL(visibleRolesChanged(QList
<QByteArray
>,QList
<QByteArray
>)),
179 this, SLOT(slotVisibleRolesChangedByHeader(QList
<QByteArray
>,QList
<QByteArray
>)));
180 connect(m_view
, SIGNAL(roleEditingCanceled(int,QByteArray
,QVariant
)),
181 this, SLOT(slotRoleEditingCanceled()));
182 connect(m_view
->header(), SIGNAL(columnWidthChanged(QByteArray
,qreal
,qreal
)),
183 this, SLOT(slotHeaderColumnWidthChanged(QByteArray
,qreal
,qreal
)));
185 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
186 connect(selectionManager
, SIGNAL(selectionChanged(QSet
<int>,QSet
<int>)),
187 this, SLOT(slotSelectionChanged(QSet
<int>,QSet
<int>)));
189 m_toolTipManager
= new ToolTipManager(this);
191 m_versionControlObserver
= new VersionControlObserver(this);
192 m_versionControlObserver
->setModel(m_model
);
193 connect(m_versionControlObserver
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
194 connect(m_versionControlObserver
, SIGNAL(errorMessage(QString
)), this, SIGNAL(errorMessage(QString
)));
195 connect(m_versionControlObserver
, SIGNAL(operationCompletedMessage(QString
)), this, SIGNAL(operationCompletedMessage(QString
)));
197 applyViewProperties();
198 m_topLayout
->addWidget(m_container
);
203 DolphinView::~DolphinView()
207 KUrl
DolphinView::url() const
212 void DolphinView::setActive(bool active
)
214 if (active
== m_active
) {
220 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
225 QWidget
* viewport
= m_container
->viewport();
228 palette
.setColor(viewport
->backgroundRole(), color
);
229 viewport
->setPalette(palette
);
235 m_container
->setFocus();
237 emit
writeStateChanged(m_isFolderWritable
);
241 bool DolphinView::isActive() const
246 void DolphinView::setMode(Mode mode
)
248 if (mode
!= m_mode
) {
249 ViewProperties
props(viewPropertiesUrl());
250 props
.setViewMode(mode
);
252 // We pass the new ViewProperties to applyViewProperties, rather than
253 // storing them on disk and letting applyViewProperties() read them
254 // from there, to prevent that changing the view mode fails if the
255 // .directory file is not writable (see bug 318534).
256 applyViewProperties(props
);
260 DolphinView::Mode
DolphinView::mode() const
265 void DolphinView::setPreviewsShown(bool show
)
267 if (previewsShown() == show
) {
271 ViewProperties
props(viewPropertiesUrl());
272 props
.setPreviewsShown(show
);
274 const int oldZoomLevel
= m_view
->zoomLevel();
275 m_view
->setPreviewsShown(show
);
276 emit
previewsShownChanged(show
);
278 const int newZoomLevel
= m_view
->zoomLevel();
279 if (newZoomLevel
!= oldZoomLevel
) {
280 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
284 bool DolphinView::previewsShown() const
286 return m_view
->previewsShown();
289 void DolphinView::setHiddenFilesShown(bool show
)
291 if (m_model
->showHiddenFiles() == show
) {
295 const KFileItemList itemList
= selectedItems();
296 m_selectedUrls
.clear();
297 m_selectedUrls
= itemList
.urlList();
299 ViewProperties
props(viewPropertiesUrl());
300 props
.setHiddenFilesShown(show
);
302 m_model
->setShowHiddenFiles(show
);
303 emit
hiddenFilesShownChanged(show
);
306 bool DolphinView::hiddenFilesShown() const
308 return m_model
->showHiddenFiles();
311 void DolphinView::setGroupedSorting(bool grouped
)
313 if (grouped
== groupedSorting()) {
317 ViewProperties
props(viewPropertiesUrl());
318 props
.setGroupedSorting(grouped
);
321 m_container
->controller()->model()->setGroupedSorting(grouped
);
323 emit
groupedSortingChanged(grouped
);
326 bool DolphinView::groupedSorting() const
328 return m_model
->groupedSorting();
331 KFileItemList
DolphinView::items() const
334 const int itemCount
= m_model
->count();
335 list
.reserve(itemCount
);
337 for (int i
= 0; i
< itemCount
; ++i
) {
338 list
.append(m_model
->fileItem(i
));
344 int DolphinView::itemsCount() const
346 return m_model
->count();
349 KFileItemList
DolphinView::selectedItems() const
351 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
352 QList
<int> selectedIndexes
= selectionManager
->selectedItems().toList();
354 qSort(selectedIndexes
);
356 KFileItemList selectedItems
;
357 QListIterator
<int> it(selectedIndexes
);
358 while (it
.hasNext()) {
359 const int index
= it
.next();
360 selectedItems
.append(m_model
->fileItem(index
));
362 return selectedItems
;
365 int DolphinView::selectedItemsCount() const
367 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
368 return selectionManager
->selectedItems().count();
371 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
373 m_selectedUrls
= urls
;
376 void DolphinView::markUrlAsCurrent(const KUrl
& url
)
378 m_currentItemUrl
= url
;
379 m_scrollToCurrentItem
= true;
382 void DolphinView::selectItems(const QRegExp
& pattern
, bool enabled
)
384 const KItemListSelectionManager::SelectionMode mode
= enabled
385 ? KItemListSelectionManager::Select
386 : KItemListSelectionManager::Deselect
;
387 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
389 for (int index
= 0; index
< m_model
->count(); index
++) {
390 const KFileItem item
= m_model
->fileItem(index
);
391 if (pattern
.exactMatch(item
.text())) {
392 // An alternative approach would be to store the matching items in a QSet<int> and
393 // select them in one go after the loop, but we'd need a new function
394 // KItemListSelectionManager::setSelected(QSet<int>, SelectionMode mode)
396 selectionManager
->setSelected(index
, 1, mode
);
401 void DolphinView::setZoomLevel(int level
)
403 const int oldZoomLevel
= zoomLevel();
404 m_view
->setZoomLevel(level
);
405 if (zoomLevel() != oldZoomLevel
) {
407 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
411 int DolphinView::zoomLevel() const
413 return m_view
->zoomLevel();
416 void DolphinView::setSortRole(const QByteArray
& role
)
418 if (role
!= sortRole()) {
419 updateSortRole(role
);
423 QByteArray
DolphinView::sortRole() const
425 const KItemModelBase
* model
= m_container
->controller()->model();
426 return model
->sortRole();
429 void DolphinView::setSortOrder(Qt::SortOrder order
)
431 if (sortOrder() != order
) {
432 updateSortOrder(order
);
436 Qt::SortOrder
DolphinView::sortOrder() const
438 return m_model
->sortOrder();
441 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
443 if (sortFoldersFirst() != foldersFirst
) {
444 updateSortFoldersFirst(foldersFirst
);
448 bool DolphinView::sortFoldersFirst() const
450 return m_model
->sortDirectoriesFirst();
453 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
455 const QList
<QByteArray
> previousRoles
= roles
;
457 ViewProperties
props(viewPropertiesUrl());
458 props
.setVisibleRoles(roles
);
460 m_visibleRoles
= roles
;
461 m_view
->setVisibleRoles(roles
);
463 emit
visibleRolesChanged(m_visibleRoles
, previousRoles
);
466 QList
<QByteArray
> DolphinView::visibleRoles() const
468 return m_visibleRoles
;
471 void DolphinView::reload()
473 QByteArray viewState
;
474 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
475 saveState(saveStream
);
477 const KFileItemList itemList
= selectedItems();
478 m_selectedUrls
.clear();
479 m_selectedUrls
= itemList
.urlList();
482 loadDirectory(url(), true);
484 QDataStream
restoreStream(viewState
);
485 restoreState(restoreStream
);
488 void DolphinView::stopLoading()
490 m_model
->cancelDirectoryLoading();
493 void DolphinView::readSettings()
495 const int oldZoomLevel
= m_view
->zoomLevel();
497 GeneralSettings::self()->readConfig();
498 m_view
->readSettings();
499 applyViewProperties();
501 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
502 m_container
->controller()->setAutoActivationDelay(delay
);
504 const int newZoomLevel
= m_view
->zoomLevel();
505 if (newZoomLevel
!= oldZoomLevel
) {
506 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
510 void DolphinView::writeSettings()
512 GeneralSettings::self()->writeConfig();
513 m_view
->writeSettings();
516 void DolphinView::setNameFilter(const QString
& nameFilter
)
518 m_model
->setNameFilter(nameFilter
);
521 QString
DolphinView::nameFilter() const
523 return m_model
->nameFilter();
526 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
528 return m_model
->setMimeTypeFilters(filters
);
531 QStringList
DolphinView::mimeTypeFilters() const
533 return m_model
->mimeTypeFilters();
536 QString
DolphinView::statusBarText() const
544 KIO::filesize_t totalFileSize
= 0;
546 if (m_container
->controller()->selectionManager()->hasSelection()) {
547 // Give a summary of the status of the selected files
548 const KFileItemList list
= selectedItems();
549 foreach (const KFileItem
& item
, list
) {
554 totalFileSize
+= item
.size();
558 if (folderCount
+ fileCount
== 1) {
559 // If only one item is selected, show the filename
560 filesText
= i18nc("@info:status", "<filename>%1</filename> selected", list
.first().text());
562 // At least 2 items are selected
563 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
564 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
567 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
568 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
569 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
572 if (fileCount
> 0 && folderCount
> 0) {
573 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
574 foldersText
, filesText
,
575 KGlobal::locale()->formatByteSize(totalFileSize
));
576 } else if (fileCount
> 0) {
577 summary
= i18nc("@info:status files (size)", "%1 (%2)",
579 KGlobal::locale()->formatByteSize(totalFileSize
));
580 } else if (folderCount
> 0) {
581 summary
= foldersText
;
583 summary
= i18nc("@info:status", "0 Folders, 0 Files");
589 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
591 QList
<QAction
*> actions
;
593 if (items
.isEmpty()) {
594 const KFileItem item
= m_model
->rootItem();
595 if (!item
.isNull()) {
596 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
599 actions
= m_versionControlObserver
->actions(items
);
605 void DolphinView::setUrl(const KUrl
& url
)
613 emit
urlAboutToBeChanged(url
);
618 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
619 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
621 // It is important to clear the items from the model before
622 // applying the view properties, otherwise expensive operations
623 // might be done on the existing items although they get cleared
624 // anyhow afterwards by loadDirectory().
626 applyViewProperties();
629 emit
urlChanged(url
);
632 void DolphinView::selectAll()
634 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
635 selectionManager
->setSelected(0, m_model
->count());
638 void DolphinView::invertSelection()
640 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
641 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
644 void DolphinView::clearSelection()
646 m_selectedUrls
.clear();
647 m_container
->controller()->selectionManager()->clearSelection();
650 void DolphinView::renameSelectedItems()
652 const KFileItemList items
= selectedItems();
653 if (items
.isEmpty()) {
657 if (items
.count() == 1 && GeneralSettings::renameInline()) {
658 const int index
= m_model
->index(items
.first());
659 m_view
->editRole(index
, "text");
661 connect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
662 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
664 RenameDialog
* dialog
= new RenameDialog(this, items
);
665 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
668 dialog
->activateWindow();
671 // Assure that the current index remains visible when KFileItemModel
672 // will notify the view about changed items (which might result in
673 // a changed sorting).
674 m_assureVisibleCurrentIndex
= true;
677 void DolphinView::trashSelectedItems()
679 const KUrl::List list
= simplifiedSelectedUrls();
680 KonqOperations::del(this, KonqOperations::TRASH
, list
);
683 void DolphinView::deleteSelectedItems()
685 const KUrl::List list
= simplifiedSelectedUrls();
686 const bool del
= KonqOperations::askDeleteConfirmation(list
,
688 KonqOperations::DEFAULT_CONFIRMATION
,
692 KIO::Job
* job
= KIO::del(list
);
694 job
->ui()->setWindow(this);
696 connect(job
, SIGNAL(result(KJob
*)),
697 this, SLOT(slotDeleteFileFinished(KJob
*)));
701 void DolphinView::cutSelectedItems()
703 QMimeData
* mimeData
= selectionMimeData();
704 KonqMimeData::addIsCutSelection(mimeData
, true);
705 QApplication::clipboard()->setMimeData(mimeData
);
708 void DolphinView::copySelectedItems()
710 QMimeData
* mimeData
= selectionMimeData();
711 QApplication::clipboard()->setMimeData(mimeData
);
714 void DolphinView::paste()
719 void DolphinView::pasteIntoFolder()
721 const KFileItemList items
= selectedItems();
722 if ((items
.count() == 1) && items
.first().isDir()) {
723 pasteToUrl(items
.first().url());
727 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
729 switch (event
->type()) {
730 case QEvent::FocusIn
:
731 if (watched
== m_container
) {
736 case QEvent::GraphicsSceneDragEnter
:
737 if (watched
== m_view
) {
742 case QEvent::GraphicsSceneDragLeave
:
743 if (watched
== m_view
) {
748 case QEvent::GraphicsSceneDrop
:
749 if (watched
== m_view
) {
756 return QWidget::eventFilter(watched
, event
);
759 void DolphinView::wheelEvent(QWheelEvent
* event
)
761 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
762 const int numDegrees
= event
->delta() / 8;
763 const int numSteps
= numDegrees
/ 15;
765 setZoomLevel(zoomLevel() + numSteps
);
772 void DolphinView::hideEvent(QHideEvent
* event
)
775 QWidget::hideEvent(event
);
778 bool DolphinView::event(QEvent
* event
)
781 * Dolphin leaves file preview tooltips open even when is not visible.
783 * Hide tool-tip when Dolphin loses focus.
785 if (event
->type() == QEvent::WindowDeactivate
) {
789 return QWidget::event(event
);
792 void DolphinView::activate()
797 void DolphinView::slotItemActivated(int index
)
799 const KFileItem item
= m_model
->fileItem(index
);
800 if (!item
.isNull()) {
801 emit
itemActivated(item
);
805 void DolphinView::slotItemsActivated(const QSet
<int>& indexes
)
807 Q_ASSERT(indexes
.count() >= 2);
809 if (indexes
.count() > 5) {
810 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
811 const int answer
= KMessageBox::warningYesNo(this, question
);
812 if (answer
!= KMessageBox::Yes
) {
818 items
.reserve(indexes
.count());
820 QSetIterator
<int> it(indexes
);
821 while (it
.hasNext()) {
822 const int index
= it
.next();
823 KFileItem item
= m_model
->fileItem(index
);
824 const KUrl
& url
= openItemAsFolderUrl(item
);
826 if (!url
.isEmpty()) { // Open folders in new tabs
827 emit
tabRequested(url
);
833 if (items
.count() == 1) {
834 emit
itemActivated(items
.first());
835 } else if (items
.count() > 1) {
836 emit
itemsActivated(items
);
840 void DolphinView::slotItemMiddleClicked(int index
)
842 const KFileItem
& item
= m_model
->fileItem(index
);
843 const KUrl
& url
= openItemAsFolderUrl(item
);
844 if (!url
.isEmpty()) {
845 emit
tabRequested(url
);
846 } else if (isTabsForFilesEnabled()) {
847 emit
tabRequested(item
.url());
851 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
853 const KFileItem item
= m_model
->fileItem(index
);
854 emit
requestContextMenu(pos
.toPoint(), item
, url(), QList
<QAction
*>());
857 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
859 emit
requestContextMenu(pos
.toPoint(), KFileItem(), url(), QList
<QAction
*>());
862 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
864 ViewProperties
props(viewPropertiesUrl());
866 QPointer
<KMenu
> menu
= new KMenu(QApplication::activeWindow());
868 KItemListView
* view
= m_container
->controller()->view();
869 const QSet
<QByteArray
> visibleRolesSet
= view
->visibleRoles().toSet();
871 bool nepomukRunning
= false;
872 bool indexingEnabled
= false;
874 nepomukRunning
= (Nepomuk2::ResourceManager::instance()->initialized());
875 if (nepomukRunning
) {
876 KConfig
config("nepomukserverrc");
877 indexingEnabled
= config
.group("Service-nepomukfileindexer").readEntry("autostart", true);
882 QMenu
* groupMenu
= 0;
884 // Add all roles to the menu that can be shown or hidden by the user
885 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
886 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
887 if (info
.role
== "text") {
888 // It should not be possible to hide the "text" role
892 const QString text
= m_model
->roleDescription(info
.role
);
894 if (info
.group
.isEmpty()) {
895 action
= menu
->addAction(text
);
897 if (!groupMenu
|| info
.group
!= groupName
) {
898 groupName
= info
.group
;
899 groupMenu
= menu
->addMenu(groupName
);
902 action
= groupMenu
->addAction(text
);
905 action
->setCheckable(true);
906 action
->setChecked(visibleRolesSet
.contains(info
.role
));
907 action
->setData(info
.role
);
909 const bool enable
= (!info
.requiresNepomuk
&& !info
.requiresIndexer
) ||
910 (info
.requiresNepomuk
&& nepomukRunning
) ||
911 (info
.requiresIndexer
&& indexingEnabled
);
912 action
->setEnabled(enable
);
915 menu
->addSeparator();
917 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
918 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
920 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
921 autoAdjustWidthsAction
->setCheckable(true);
922 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
923 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
925 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
926 customWidthsAction
->setCheckable(true);
927 customWidthsAction
->setChecked(!autoColumnWidths
);
928 customWidthsAction
->setActionGroup(widthsGroup
);
930 QAction
* action
= menu
->exec(pos
.toPoint());
931 if (menu
&& action
) {
932 KItemListHeader
* header
= view
->header();
934 if (action
== autoAdjustWidthsAction
) {
935 // Clear the column-widths from the viewproperties and turn on
936 // the automatic resizing of the columns
937 props
.setHeaderColumnWidths(QList
<int>());
938 header
->setAutomaticColumnResizing(true);
939 } else if (action
== customWidthsAction
) {
940 // Apply the current column-widths as custom column-widths and turn
941 // off the automatic resizing of the columns
942 QList
<int> columnWidths
;
943 foreach (const QByteArray
& role
, view
->visibleRoles()) {
944 columnWidths
.append(header
->columnWidth(role
));
946 props
.setHeaderColumnWidths(columnWidths
);
947 header
->setAutomaticColumnResizing(false);
949 // Show or hide the selected role
950 const QByteArray selectedRole
= action
->data().toByteArray();
952 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
953 if (action
->isChecked()) {
954 visibleRoles
.append(selectedRole
);
956 visibleRoles
.removeOne(selectedRole
);
959 view
->setVisibleRoles(visibleRoles
);
960 props
.setVisibleRoles(visibleRoles
);
962 QList
<int> columnWidths
;
963 if (!header
->automaticColumnResizing()) {
964 foreach (const QByteArray
& role
, view
->visibleRoles()) {
965 columnWidths
.append(header
->columnWidth(role
));
968 props
.setHeaderColumnWidths(columnWidths
);
975 void DolphinView::slotHeaderColumnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
)
979 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
981 ViewProperties
props(viewPropertiesUrl());
982 QList
<int> columnWidths
= props
.headerColumnWidths();
983 if (columnWidths
.count() != visibleRoles
.count()) {
984 columnWidths
.clear();
985 columnWidths
.reserve(visibleRoles
.count());
986 const KItemListHeader
* header
= m_view
->header();
987 foreach (const QByteArray
& role
, visibleRoles
) {
988 const int width
= header
->columnWidth(role
);
989 columnWidths
.append(width
);
993 const int roleIndex
= visibleRoles
.indexOf(role
);
994 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
995 columnWidths
[roleIndex
] = current
;
997 props
.setHeaderColumnWidths(columnWidths
);
1000 void DolphinView::slotItemHovered(int index
)
1002 const KFileItem item
= m_model
->fileItem(index
);
1004 if (GeneralSettings::showToolTips() && !m_dragging
) {
1005 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1006 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1007 itemRect
.moveTo(pos
);
1009 m_toolTipManager
->showToolTip(item
, itemRect
);
1012 emit
requestItemInfo(item
);
1015 void DolphinView::slotItemUnhovered(int index
)
1019 emit
requestItemInfo(KFileItem());
1022 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1025 KFileItem destItem
= m_model
->fileItem(index
);
1026 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1027 // Use the URL of the view as drop target if the item is no directory
1029 destItem
= m_model
->rootItem();
1032 // The item represents a directory or desktop-file
1033 destUrl
= destItem
.url();
1036 QDropEvent
dropEvent(event
->pos().toPoint(),
1037 event
->possibleActions(),
1040 event
->modifiers());
1043 KonqOperations
* op
= DragAndDropHelper::dropUrls(destItem
, destUrl
, &dropEvent
, error
);
1044 if (!error
.isEmpty()) {
1045 emit
infoMessage(error
);
1048 if (op
&& destUrl
== url()) {
1049 // Mark the dropped urls as selected.
1050 m_clearSelectionBeforeSelectingNewItems
= true;
1051 connect(op
, SIGNAL(urlPasted(KUrl
)), this, SLOT(slotUrlPasted(KUrl
)));
1057 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1059 if (previous
!= 0) {
1060 disconnect(previous
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1061 m_versionControlObserver
->setModel(0);
1065 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1066 connect(current
, SIGNAL(loadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1068 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1069 m_versionControlObserver
->setModel(fileItemModel
);
1073 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1077 if (itemIndex
< 0) {
1078 // Trigger the history navigation only when clicking on the viewport:
1079 // Above an item the XButtons provide a simple way to select items in
1080 // the singleClick mode.
1081 if (buttons
& Qt::XButton1
) {
1082 emit
goBackRequested();
1083 } else if (buttons
& Qt::XButton2
) {
1084 emit
goForwardRequested();
1089 void DolphinView::slotAboutToCreate(const KUrl::List
& urls
)
1091 if (!urls
.isEmpty()) {
1092 if (m_markFirstNewlySelectedItemAsCurrent
) {
1093 markUrlAsCurrent(urls
.first());
1094 m_markFirstNewlySelectedItemAsCurrent
= false;
1096 m_selectedUrls
<< urls
;
1100 void DolphinView::slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
)
1102 const int currentCount
= current
.count();
1103 const int previousCount
= previous
.count();
1104 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1105 (currentCount
> 0 && previousCount
== 0);
1107 // If nothing has been selected before and something got selected (or if something
1108 // was selected before and now nothing is selected) the selectionChangedSignal must
1109 // be emitted asynchronously as fast as possible to update the edit-actions.
1110 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1111 m_selectionChangedTimer
->start();
1114 void DolphinView::emitSelectionChangedSignal()
1116 m_selectionChangedTimer
->stop();
1117 emit
selectionChanged(selectedItems());
1120 void DolphinView::updateSortRole(const QByteArray
& role
)
1122 ViewProperties
props(viewPropertiesUrl());
1123 props
.setSortRole(role
);
1125 KItemModelBase
* model
= m_container
->controller()->model();
1126 model
->setSortRole(role
);
1128 emit
sortRoleChanged(role
);
1131 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1133 ViewProperties
props(viewPropertiesUrl());
1134 props
.setSortOrder(order
);
1136 m_model
->setSortOrder(order
);
1138 emit
sortOrderChanged(order
);
1141 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1143 ViewProperties
props(viewPropertiesUrl());
1144 props
.setSortFoldersFirst(foldersFirst
);
1146 m_model
->setSortDirectoriesFirst(foldersFirst
);
1148 emit
sortFoldersFirstChanged(foldersFirst
);
1151 QPair
<bool, QString
> DolphinView::pasteInfo() const
1153 return KonqOperations::pasteInfo(url());
1156 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1158 m_tabsForFiles
= tabsForFiles
;
1161 bool DolphinView::isTabsForFilesEnabled() const
1163 return m_tabsForFiles
;
1166 bool DolphinView::itemsExpandable() const
1168 return m_mode
== DetailsView
;
1171 void DolphinView::restoreState(QDataStream
& stream
)
1173 // Restore the current item that had the keyboard focus
1174 stream
>> m_currentItemUrl
;
1176 // Restore the view position
1177 stream
>> m_restoredContentsPosition
;
1179 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1182 m_model
->restoreExpandedDirectories(urls
);
1185 void DolphinView::saveState(QDataStream
& stream
)
1187 // Save the current item that has the keyboard focus
1188 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1189 if (currentIndex
!= -1) {
1190 KFileItem item
= m_model
->fileItem(currentIndex
);
1191 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1192 KUrl currentItemUrl
= item
.url();
1193 stream
<< currentItemUrl
;
1198 // Save view position
1199 const qreal x
= m_container
->horizontalScrollBar()->value();
1200 const qreal y
= m_container
->verticalScrollBar()->value();
1201 stream
<< QPoint(x
, y
);
1203 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1204 stream
<< m_model
->expandedDirectories();
1207 KFileItem
DolphinView::rootItem() const
1209 return m_model
->rootItem();
1212 void DolphinView::setViewPropertiesContext(const QString
& context
)
1214 m_viewPropertiesContext
= context
;
1217 QString
DolphinView::viewPropertiesContext() const
1219 return m_viewPropertiesContext
;
1222 KUrl
DolphinView::openItemAsFolderUrl(const KFileItem
& item
, const bool browseThroughArchives
)
1224 if (item
.isNull()) {
1228 KUrl url
= item
.targetUrl();
1234 if (item
.isMimeTypeKnown()) {
1235 const QString
& mimetype
= item
.mimetype();
1237 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1238 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1239 // zip:/<path>/ when clicking on a zip file, etc.
1240 // The .protocol file specifies the mimetype that the kioslave handles.
1241 // Note that we don't use mimetype inheritance since we don't want to
1242 // open OpenDocument files as zip folders...
1243 const QString
& protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1244 if (!protocol
.isEmpty()) {
1245 url
.setProtocol(protocol
);
1250 if (mimetype
== QLatin1String("application/x-desktop")) {
1251 // Redirect to the URL in Type=Link desktop files
1252 KDesktopFile
desktopFile(url
.toLocalFile());
1253 if (desktopFile
.hasLinkType()) {
1254 return desktopFile
.readUrl();
1262 void DolphinView::observeCreatedItem(const KUrl
& url
)
1266 markUrlAsCurrent(url
);
1267 markUrlsAsSelected(QList
<KUrl
>() << url
);
1271 void DolphinView::slotDirectoryRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1273 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
1274 emit
redirection(oldUrl
, newUrl
);
1275 m_url
= newUrl
; // #186947
1279 void DolphinView::updateViewState()
1281 if (m_currentItemUrl
!= KUrl()) {
1282 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1283 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1284 if (currentIndex
!= -1) {
1285 selectionManager
->setCurrentItem(currentIndex
);
1287 // scroll to current item and reset the state
1288 if (m_scrollToCurrentItem
) {
1289 m_view
->scrollToItem(currentIndex
);
1290 m_scrollToCurrentItem
= false;
1293 m_currentItemUrl
= KUrl();
1295 selectionManager
->setCurrentItem(0);
1299 if (!m_restoredContentsPosition
.isNull()) {
1300 const int x
= m_restoredContentsPosition
.x();
1301 const int y
= m_restoredContentsPosition
.y();
1302 m_restoredContentsPosition
= QPoint();
1304 m_container
->horizontalScrollBar()->setValue(x
);
1305 m_container
->verticalScrollBar()->setValue(y
);
1308 if (!m_selectedUrls
.isEmpty()) {
1309 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1311 if (m_clearSelectionBeforeSelectingNewItems
) {
1312 selectionManager
->clearSelection();
1313 m_clearSelectionBeforeSelectingNewItems
= false;
1316 QSet
<int> selectedItems
= selectionManager
->selectedItems();
1318 QList
<KUrl
>::iterator it
= m_selectedUrls
.begin();
1319 while (it
!= m_selectedUrls
.end()) {
1320 const int index
= m_model
->index(*it
);
1322 selectedItems
.insert(index
);
1323 it
= m_selectedUrls
.erase(it
);
1329 selectionManager
->setSelectedItems(selectedItems
);
1333 void DolphinView::hideToolTip()
1335 if (GeneralSettings::showToolTips()) {
1336 m_toolTipManager
->hideToolTip();
1340 void DolphinView::calculateItemCount(int& fileCount
,
1342 KIO::filesize_t
& totalFileSize
) const
1344 const int itemCount
= m_model
->count();
1345 for (int i
= 0; i
< itemCount
; ++i
) {
1346 const KFileItem item
= m_model
->fileItem(i
);
1351 totalFileSize
+= item
.size();
1356 void DolphinView::showHoverInformation(const KFileItem
& item
)
1358 emit
requestItemInfo(item
);
1361 void DolphinView::clearHoverInformation()
1363 emit
requestItemInfo(KFileItem());
1366 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1368 if (job
->error() == 0) {
1369 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1370 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1371 emit
errorMessage(job
->errorString());
1375 void DolphinView::slotRenamingFailed(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1377 const int index
= m_model
->index(newUrl
);
1379 QHash
<QByteArray
, QVariant
> data
;
1380 data
.insert("text", oldUrl
.fileName());
1381 m_model
->setData(index
, data
);
1385 void DolphinView::slotDirectoryLoadingStarted()
1387 // Disable the writestate temporary until it can be determined in a fast way
1388 // in DolphinView::slotLoadingCompleted()
1389 if (m_isFolderWritable
) {
1390 m_isFolderWritable
= false;
1391 emit
writeStateChanged(m_isFolderWritable
);
1394 emit
directoryLoadingStarted();
1397 void DolphinView::slotDirectoryLoadingCompleted()
1399 // Update the view-state. This has to be done asynchronously
1400 // because the view might not be in its final state yet.
1401 QTimer::singleShot(0, this, SLOT(updateViewState()));
1403 emit
directoryLoadingCompleted();
1405 updateWritableState();
1408 void DolphinView::slotItemsChanged()
1410 m_assureVisibleCurrentIndex
= false;
1413 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1416 Q_ASSERT(m_model
->sortOrder() == current
);
1418 ViewProperties
props(viewPropertiesUrl());
1419 props
.setSortOrder(current
);
1421 emit
sortOrderChanged(current
);
1424 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1427 Q_ASSERT(m_model
->sortRole() == current
);
1429 ViewProperties
props(viewPropertiesUrl());
1430 props
.setSortRole(current
);
1432 emit
sortRoleChanged(current
);
1435 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1436 const QList
<QByteArray
>& previous
)
1439 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1441 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1443 m_visibleRoles
= current
;
1445 ViewProperties
props(viewPropertiesUrl());
1446 props
.setVisibleRoles(m_visibleRoles
);
1448 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1451 void DolphinView::slotRoleEditingCanceled()
1453 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
1454 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
1457 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1459 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
1460 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
1462 if (index
< 0 || index
>= m_model
->count()) {
1466 if (role
== "text") {
1467 const KFileItem oldItem
= m_model
->fileItem(index
);
1468 const QString newName
= value
.toString();
1469 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1String(".") && newName
!= QLatin1String("..")) {
1470 const KUrl oldUrl
= oldItem
.url();
1472 const KUrl
newUrl(url().path(KUrl::AddTrailingSlash
) + newName
);
1473 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1474 if (!newNameExistsAlready
) {
1475 // Only change the data in the model if no item with the new name
1476 // is in the model yet. If there is an item with the new name
1477 // already, calling KonqOperations::rename() will open a dialog
1478 // asking for a new name, and KFileItemModel will update the
1479 // data when the dir lister signals that the file name has changed.
1480 QHash
<QByteArray
, QVariant
> data
;
1481 data
.insert(role
, value
);
1482 m_model
->setData(index
, data
);
1485 KonqOperations
* op
= KonqOperations::renameV2(this, oldUrl
, newName
);
1487 connect(op
, SIGNAL(renamingFailed(KUrl
,KUrl
)), SLOT(slotRenamingFailed(KUrl
,KUrl
)));
1493 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1495 if (!url
.isValid()) {
1496 const QString
location(url
.pathOrUrl());
1497 if (location
.isEmpty()) {
1498 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1500 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1506 m_model
->refreshDirectory(url
);
1508 m_model
->loadDirectory(url
);
1512 void DolphinView::applyViewProperties()
1514 const ViewProperties
props(viewPropertiesUrl());
1515 applyViewProperties(props
);
1518 void DolphinView::applyViewProperties(const ViewProperties
& props
)
1520 m_view
->beginTransaction();
1522 const Mode mode
= props
.viewMode();
1523 if (m_mode
!= mode
) {
1524 const Mode previousMode
= m_mode
;
1527 // Changing the mode might result in changing
1528 // the zoom level. Remember the old zoom level so
1529 // that zoomLevelChanged() can get emitted.
1530 const int oldZoomLevel
= m_view
->zoomLevel();
1533 emit
modeChanged(m_mode
, previousMode
);
1535 if (m_view
->zoomLevel() != oldZoomLevel
) {
1536 emit
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1540 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1541 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1542 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1543 emit
hiddenFilesShownChanged(hiddenFilesShown
);
1546 const bool groupedSorting
= props
.groupedSorting();
1547 if (groupedSorting
!= m_model
->groupedSorting()) {
1548 m_model
->setGroupedSorting(groupedSorting
);
1549 emit
groupedSortingChanged(groupedSorting
);
1552 const QByteArray sortRole
= props
.sortRole();
1553 if (sortRole
!= m_model
->sortRole()) {
1554 m_model
->setSortRole(sortRole
);
1555 emit
sortRoleChanged(sortRole
);
1558 const Qt::SortOrder sortOrder
= props
.sortOrder();
1559 if (sortOrder
!= m_model
->sortOrder()) {
1560 m_model
->setSortOrder(sortOrder
);
1561 emit
sortOrderChanged(sortOrder
);
1564 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1565 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1566 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1567 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1570 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1571 if (visibleRoles
!= m_visibleRoles
) {
1572 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1573 m_visibleRoles
= visibleRoles
;
1574 m_view
->setVisibleRoles(visibleRoles
);
1575 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1578 const bool previewsShown
= props
.previewsShown();
1579 if (previewsShown
!= m_view
->previewsShown()) {
1580 const int oldZoomLevel
= zoomLevel();
1582 m_view
->setPreviewsShown(previewsShown
);
1583 emit
previewsShownChanged(previewsShown
);
1585 // Changing the preview-state might result in a changed zoom-level
1586 if (oldZoomLevel
!= zoomLevel()) {
1587 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1591 KItemListView
* itemListView
= m_container
->controller()->view();
1592 if (itemListView
->isHeaderVisible()) {
1593 KItemListHeader
* header
= itemListView
->header();
1594 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
1595 const int rolesCount
= m_visibleRoles
.count();
1596 if (headerColumnWidths
.count() == rolesCount
) {
1597 header
->setAutomaticColumnResizing(false);
1599 QHash
<QByteArray
, qreal
> columnWidths
;
1600 for (int i
= 0; i
< rolesCount
; ++i
) {
1601 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
1603 header
->setColumnWidths(columnWidths
);
1605 header
->setAutomaticColumnResizing(true);
1609 m_view
->endTransaction();
1612 void DolphinView::applyModeToView()
1615 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
1616 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
1617 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1618 default: Q_ASSERT(false); break;
1622 void DolphinView::pasteToUrl(const KUrl
& url
)
1624 KonqOperations
* op
= KonqOperations::doPasteV2(this, url
);
1626 m_clearSelectionBeforeSelectingNewItems
= true;
1627 m_markFirstNewlySelectedItemAsCurrent
= true;
1628 connect(op
, SIGNAL(aboutToCreate(KUrl::List
)), this, SLOT(slotAboutToCreate(KUrl::List
)));
1632 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1636 const KFileItemList items
= selectedItems();
1637 foreach (const KFileItem
& item
, items
) {
1638 urls
.append(item
.url());
1641 if (itemsExpandable()) {
1642 // TODO: Check if we still need KDirModel for this in KDE 5.0
1643 urls
= KDirModel::simplifiedUrlList(urls
);
1649 QMimeData
* DolphinView::selectionMimeData() const
1651 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1652 const QSet
<int> selectedIndexes
= selectionManager
->selectedItems();
1654 return m_model
->createMimeData(selectedIndexes
);
1657 void DolphinView::updateWritableState()
1659 const bool wasFolderWritable
= m_isFolderWritable
;
1660 m_isFolderWritable
= true;
1662 const KFileItem item
= m_model
->rootItem();
1663 if (!item
.isNull()) {
1664 KFileItemListProperties
capabilities(KFileItemList() << item
);
1665 m_isFolderWritable
= capabilities
.supportsWriting();
1667 if (m_isFolderWritable
!= wasFolderWritable
) {
1668 emit
writeStateChanged(m_isFolderWritable
);
1672 KUrl
DolphinView::viewPropertiesUrl() const
1674 if (m_viewPropertiesContext
.isEmpty()) {
1679 url
.setProtocol(m_url
.protocol());
1680 url
.setPath(m_viewPropertiesContext
);
1684 #include "dolphinview.moc"