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_fileitemcapabilities.h>
64 #include <konq_operations.h>
65 #include <konqmimedata.h>
66 #include <KToggleAction>
69 #include "dolphinnewfilemenuobserver.h"
70 #include "dolphin_detailsmodesettings.h"
71 #include "dolphin_generalsettings.h"
72 #include "dolphinitemlistview.h"
73 #include "draganddrophelper.h"
74 #include "renamedialog.h"
75 #include "versioncontrol/versioncontrolobserver.h"
76 #include "viewmodecontroller.h"
77 #include "viewproperties.h"
78 #include "views/tooltips/tooltipmanager.h"
79 #include "zoomlevelinfo.h"
82 #include <baloo/indexerconfig.h>
86 const int MaxModeEnum
= DolphinView::CompactView
;
89 DolphinView::DolphinView(const KUrl
& url
, QWidget
* parent
) :
92 m_tabsForFiles(false),
93 m_assureVisibleCurrentIndex(false),
94 m_isFolderWritable(true),
97 m_viewPropertiesContext(),
98 m_mode(DolphinView::IconsView
),
105 m_selectionChangedTimer(0),
107 m_scrollToCurrentItem(false),
108 m_restoredContentsPosition(),
110 m_clearSelectionBeforeSelectingNewItems(false),
111 m_markFirstNewlySelectedItemAsCurrent(false),
112 m_versionControlObserver(0)
114 m_topLayout
= new QVBoxLayout(this);
115 m_topLayout
->setSpacing(0);
116 m_topLayout
->setMargin(0);
118 // When a new item has been created by the "Create New..." menu, the item should
119 // get selected and it must be assured that the item will get visible. As the
120 // creation is done asynchronously, several signals must be checked:
121 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(KUrl
)),
122 this, SLOT(observeCreatedItem(KUrl
)));
124 m_selectionChangedTimer
= new QTimer(this);
125 m_selectionChangedTimer
->setSingleShot(true);
126 m_selectionChangedTimer
->setInterval(300);
127 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
128 this, SLOT(emitSelectionChangedSignal()));
130 m_model
= new KFileItemModel(this);
131 m_view
= new DolphinItemListView();
132 m_view
->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
133 m_view
->setVisibleRoles(QList
<QByteArray
>() << "text");
136 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
137 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
138 controller
->setAutoActivationDelay(delay
);
140 // The EnlargeSmallPreviews setting can only be changed after the model
141 // has been set in the view by KItemListController.
142 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
144 m_container
= new KItemListContainer(controller
, this);
145 m_container
->installEventFilter(this);
146 setFocusProxy(m_container
);
147 connect(m_container
->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip()));
148 connect(m_container
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip()));
150 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
151 connect(controller
, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
152 connect(controller
, SIGNAL(itemsActivated(KItemSet
)), this, SLOT(slotItemsActivated(KItemSet
)));
153 connect(controller
, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
154 connect(controller
, SIGNAL(itemContextMenuRequested(int,QPointF
)), this, SLOT(slotItemContextMenuRequested(int,QPointF
)));
155 connect(controller
, SIGNAL(viewContextMenuRequested(QPointF
)), this, SLOT(slotViewContextMenuRequested(QPointF
)));
156 connect(controller
, SIGNAL(headerContextMenuRequested(QPointF
)), this, SLOT(slotHeaderContextMenuRequested(QPointF
)));
157 connect(controller
, SIGNAL(mouseButtonPressed(int,Qt::MouseButtons
)), this, SLOT(slotMouseButtonPressed(int,Qt::MouseButtons
)));
158 connect(controller
, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int)));
159 connect(controller
, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int)));
160 connect(controller
, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent
*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent
*)));
161 connect(controller
, SIGNAL(escapePressed()), this, SLOT(stopLoading()));
162 connect(controller
, SIGNAL(modelChanged(KItemModelBase
*,KItemModelBase
*)), this, SLOT(slotModelChanged(KItemModelBase
*,KItemModelBase
*)));
164 connect(m_model
, SIGNAL(directoryLoadingStarted()), this, SLOT(slotDirectoryLoadingStarted()));
165 connect(m_model
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
166 connect(m_model
, SIGNAL(directoryLoadingCanceled()), this, SIGNAL(directoryLoadingCanceled()));
167 connect(m_model
, SIGNAL(directoryLoadingProgress(int)), this, SIGNAL(directoryLoadingProgress(int)));
168 connect(m_model
, SIGNAL(directorySortingProgress(int)), this, SIGNAL(directorySortingProgress(int)));
169 connect(m_model
, SIGNAL(itemsChanged(KItemRangeList
,QSet
<QByteArray
>)),
170 this, SLOT(slotItemsChanged()));
171 connect(m_model
, SIGNAL(itemsRemoved(KItemRangeList
)), this, SIGNAL(itemCountChanged()));
172 connect(m_model
, SIGNAL(itemsInserted(KItemRangeList
)), this, SIGNAL(itemCountChanged()));
173 connect(m_model
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
174 connect(m_model
, SIGNAL(errorMessage(QString
)), this, SIGNAL(errorMessage(QString
)));
175 connect(m_model
, SIGNAL(directoryRedirection(KUrl
,KUrl
)), this, SLOT(slotDirectoryRedirection(KUrl
,KUrl
)));
176 connect(m_model
, SIGNAL(urlIsFileError(KUrl
)), this, SIGNAL(urlIsFileError(KUrl
)));
178 m_view
->installEventFilter(this);
179 connect(m_view
, SIGNAL(sortOrderChanged(Qt::SortOrder
,Qt::SortOrder
)),
180 this, SLOT(slotSortOrderChangedByHeader(Qt::SortOrder
,Qt::SortOrder
)));
181 connect(m_view
, SIGNAL(sortRoleChanged(QByteArray
,QByteArray
)),
182 this, SLOT(slotSortRoleChangedByHeader(QByteArray
,QByteArray
)));
183 connect(m_view
, SIGNAL(visibleRolesChanged(QList
<QByteArray
>,QList
<QByteArray
>)),
184 this, SLOT(slotVisibleRolesChangedByHeader(QList
<QByteArray
>,QList
<QByteArray
>)));
185 connect(m_view
, SIGNAL(roleEditingCanceled(int,QByteArray
,QVariant
)),
186 this, SLOT(slotRoleEditingCanceled()));
187 connect(m_view
->header(), SIGNAL(columnWidthChanged(QByteArray
,qreal
,qreal
)),
188 this, SLOT(slotHeaderColumnWidthChanged(QByteArray
,qreal
,qreal
)));
190 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
191 connect(selectionManager
, SIGNAL(selectionChanged(KItemSet
,KItemSet
)),
192 this, SLOT(slotSelectionChanged(KItemSet
,KItemSet
)));
194 m_toolTipManager
= new ToolTipManager(this);
196 m_versionControlObserver
= new VersionControlObserver(this);
197 m_versionControlObserver
->setModel(m_model
);
198 connect(m_versionControlObserver
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
199 connect(m_versionControlObserver
, SIGNAL(errorMessage(QString
)), this, SIGNAL(errorMessage(QString
)));
200 connect(m_versionControlObserver
, SIGNAL(operationCompletedMessage(QString
)), this, SIGNAL(operationCompletedMessage(QString
)));
202 applyViewProperties();
203 m_topLayout
->addWidget(m_container
);
208 DolphinView::~DolphinView()
212 KUrl
DolphinView::url() const
217 void DolphinView::setActive(bool active
)
219 if (active
== m_active
) {
225 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
230 QWidget
* viewport
= m_container
->viewport();
233 palette
.setColor(viewport
->backgroundRole(), color
);
234 viewport
->setPalette(palette
);
240 m_container
->setFocus();
242 emit
writeStateChanged(m_isFolderWritable
);
246 bool DolphinView::isActive() const
251 void DolphinView::setMode(Mode mode
)
253 if (mode
!= m_mode
) {
254 ViewProperties
props(viewPropertiesUrl());
255 props
.setViewMode(mode
);
257 // We pass the new ViewProperties to applyViewProperties, rather than
258 // storing them on disk and letting applyViewProperties() read them
259 // from there, to prevent that changing the view mode fails if the
260 // .directory file is not writable (see bug 318534).
261 applyViewProperties(props
);
265 DolphinView::Mode
DolphinView::mode() const
270 void DolphinView::setPreviewsShown(bool show
)
272 if (previewsShown() == show
) {
276 ViewProperties
props(viewPropertiesUrl());
277 props
.setPreviewsShown(show
);
279 const int oldZoomLevel
= m_view
->zoomLevel();
280 m_view
->setPreviewsShown(show
);
281 emit
previewsShownChanged(show
);
283 const int newZoomLevel
= m_view
->zoomLevel();
284 if (newZoomLevel
!= oldZoomLevel
) {
285 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
289 bool DolphinView::previewsShown() const
291 return m_view
->previewsShown();
294 void DolphinView::setHiddenFilesShown(bool show
)
296 if (m_model
->showHiddenFiles() == show
) {
300 const KFileItemList itemList
= selectedItems();
301 m_selectedUrls
.clear();
302 m_selectedUrls
= KUrl::List(itemList
.urlList());
304 ViewProperties
props(viewPropertiesUrl());
305 props
.setHiddenFilesShown(show
);
307 m_model
->setShowHiddenFiles(show
);
308 emit
hiddenFilesShownChanged(show
);
311 bool DolphinView::hiddenFilesShown() const
313 return m_model
->showHiddenFiles();
316 void DolphinView::setGroupedSorting(bool grouped
)
318 if (grouped
== groupedSorting()) {
322 ViewProperties
props(viewPropertiesUrl());
323 props
.setGroupedSorting(grouped
);
326 m_container
->controller()->model()->setGroupedSorting(grouped
);
328 emit
groupedSortingChanged(grouped
);
331 bool DolphinView::groupedSorting() const
333 return m_model
->groupedSorting();
336 KFileItemList
DolphinView::items() const
339 const int itemCount
= m_model
->count();
340 list
.reserve(itemCount
);
342 for (int i
= 0; i
< itemCount
; ++i
) {
343 list
.append(m_model
->fileItem(i
));
349 int DolphinView::itemsCount() const
351 return m_model
->count();
354 KFileItemList
DolphinView::selectedItems() const
356 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
358 KFileItemList selectedItems
;
359 foreach (int index
, selectionManager
->selectedItems()) {
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 KItemSet and
393 // select them in one go after the loop, but we'd need a new function
394 // KItemListSelectionManager::setSelected(KItemSet, 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
= KUrl::List(itemList
.urlList());
482 loadDirectory(url(), true);
484 QDataStream
restoreStream(viewState
);
485 restoreState(restoreStream
);
488 void DolphinView::readSettings()
490 const int oldZoomLevel
= m_view
->zoomLevel();
492 GeneralSettings::self()->readConfig();
493 m_view
->readSettings();
494 applyViewProperties();
496 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
497 m_container
->controller()->setAutoActivationDelay(delay
);
499 const int newZoomLevel
= m_view
->zoomLevel();
500 if (newZoomLevel
!= oldZoomLevel
) {
501 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
505 void DolphinView::writeSettings()
507 GeneralSettings::self()->writeConfig();
508 m_view
->writeSettings();
511 void DolphinView::setNameFilter(const QString
& nameFilter
)
513 m_model
->setNameFilter(nameFilter
);
516 QString
DolphinView::nameFilter() const
518 return m_model
->nameFilter();
521 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
523 return m_model
->setMimeTypeFilters(filters
);
526 QStringList
DolphinView::mimeTypeFilters() const
528 return m_model
->mimeTypeFilters();
531 QString
DolphinView::statusBarText() const
539 KIO::filesize_t totalFileSize
= 0;
541 if (m_container
->controller()->selectionManager()->hasSelection()) {
542 // Give a summary of the status of the selected files
543 const KFileItemList list
= selectedItems();
544 foreach (const KFileItem
& item
, list
) {
549 totalFileSize
+= item
.size();
553 if (folderCount
+ fileCount
== 1) {
554 // If only one item is selected, show info about it
555 return list
.first().getStatusBarInfo();
557 // At least 2 items are selected
558 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
559 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
562 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
563 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
564 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
567 if (fileCount
> 0 && folderCount
> 0) {
568 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
569 foldersText
, filesText
,
570 KGlobal::locale()->formatByteSize(totalFileSize
));
571 } else if (fileCount
> 0) {
572 summary
= i18nc("@info:status files (size)", "%1 (%2)",
574 KGlobal::locale()->formatByteSize(totalFileSize
));
575 } else if (folderCount
> 0) {
576 summary
= foldersText
;
578 summary
= i18nc("@info:status", "0 Folders, 0 Files");
584 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
586 QList
<QAction
*> actions
;
588 if (items
.isEmpty()) {
589 const KFileItem item
= m_model
->rootItem();
590 if (!item
.isNull()) {
591 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
594 actions
= m_versionControlObserver
->actions(items
);
600 void DolphinView::setUrl(const KUrl
& url
)
608 emit
urlAboutToBeChanged(url
);
613 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
614 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
616 // It is important to clear the items from the model before
617 // applying the view properties, otherwise expensive operations
618 // might be done on the existing items although they get cleared
619 // anyhow afterwards by loadDirectory().
621 applyViewProperties();
624 emit
urlChanged(url
);
627 void DolphinView::selectAll()
629 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
630 selectionManager
->setSelected(0, m_model
->count());
633 void DolphinView::invertSelection()
635 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
636 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
639 void DolphinView::clearSelection()
641 m_selectedUrls
.clear();
642 m_container
->controller()->selectionManager()->clearSelection();
645 void DolphinView::renameSelectedItems()
647 const KFileItemList items
= selectedItems();
648 if (items
.isEmpty()) {
652 if (items
.count() == 1 && GeneralSettings::renameInline()) {
653 const int index
= m_model
->index(items
.first());
654 m_view
->editRole(index
, "text");
658 connect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
659 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
661 RenameDialog
* dialog
= new RenameDialog(this, items
);
662 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
665 dialog
->activateWindow();
668 // Assure that the current index remains visible when KFileItemModel
669 // will notify the view about changed items (which might result in
670 // a changed sorting).
671 m_assureVisibleCurrentIndex
= true;
674 void DolphinView::trashSelectedItems()
676 const KUrl::List list
= simplifiedSelectedUrls();
677 KonqOperations::del(this, KonqOperations::TRASH
, list
);
680 void DolphinView::deleteSelectedItems()
682 const KUrl::List list
= simplifiedSelectedUrls();
683 const bool del
= KonqOperations::askDeleteConfirmation(list
,
685 KonqOperations::DEFAULT_CONFIRMATION
,
689 KIO::Job
* job
= KIO::del(list
);
691 KJobWidgets::setWindow(job
, this);
693 connect(job
, SIGNAL(result(KJob
*)),
694 this, SLOT(slotDeleteFileFinished(KJob
*)));
698 void DolphinView::cutSelectedItems()
700 QMimeData
* mimeData
= selectionMimeData();
701 KonqMimeData::addIsCutSelection(mimeData
, true);
702 QApplication::clipboard()->setMimeData(mimeData
);
705 void DolphinView::copySelectedItems()
707 QMimeData
* mimeData
= selectionMimeData();
708 QApplication::clipboard()->setMimeData(mimeData
);
711 void DolphinView::paste()
716 void DolphinView::pasteIntoFolder()
718 const KFileItemList items
= selectedItems();
719 if ((items
.count() == 1) && items
.first().isDir()) {
720 pasteToUrl(items
.first().url());
724 void DolphinView::stopLoading()
726 m_model
->cancelDirectoryLoading();
729 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
731 switch (event
->type()) {
732 case QEvent::FocusIn
:
733 if (watched
== m_container
) {
738 case QEvent::GraphicsSceneDragEnter
:
739 if (watched
== m_view
) {
744 case QEvent::GraphicsSceneDragLeave
:
745 if (watched
== m_view
) {
750 case QEvent::GraphicsSceneDrop
:
751 if (watched
== m_view
) {
758 return QWidget::eventFilter(watched
, event
);
761 void DolphinView::wheelEvent(QWheelEvent
* event
)
763 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
764 const int numDegrees
= event
->delta() / 8;
765 const int numSteps
= numDegrees
/ 15;
767 setZoomLevel(zoomLevel() + numSteps
);
774 void DolphinView::hideEvent(QHideEvent
* event
)
777 QWidget::hideEvent(event
);
780 bool DolphinView::event(QEvent
* event
)
783 * Dolphin leaves file preview tooltips open even when is not visible.
785 * Hide tool-tip when Dolphin loses focus.
787 if (event
->type() == QEvent::WindowDeactivate
) {
791 return QWidget::event(event
);
794 void DolphinView::activate()
799 void DolphinView::slotItemActivated(int index
)
801 const KFileItem item
= m_model
->fileItem(index
);
802 if (!item
.isNull()) {
803 emit
itemActivated(item
);
807 void DolphinView::slotItemsActivated(const KItemSet
& indexes
)
809 Q_ASSERT(indexes
.count() >= 2);
811 if (indexes
.count() > 5) {
812 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
813 const int answer
= KMessageBox::warningYesNo(this, question
);
814 if (answer
!= KMessageBox::Yes
) {
820 items
.reserve(indexes
.count());
822 foreach (int index
, indexes
) {
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 // Force emit of a selection changed signal before we request the
854 // context menu, to update the edit-actions first. (See Bug 294013)
855 if (m_selectionChangedTimer
->isActive()) {
856 emitSelectionChangedSignal();
859 const KFileItem item
= m_model
->fileItem(index
);
860 emit
requestContextMenu(pos
.toPoint(), item
, url(), QList
<QAction
*>());
863 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
865 emit
requestContextMenu(pos
.toPoint(), KFileItem(), url(), QList
<QAction
*>());
868 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
870 ViewProperties
props(viewPropertiesUrl());
872 QPointer
<KMenu
> menu
= new KMenu(QApplication::activeWindow());
874 KItemListView
* view
= m_container
->controller()->view();
875 const QSet
<QByteArray
> visibleRolesSet
= view
->visibleRoles().toSet();
877 bool indexingEnabled
= false;
879 Baloo::IndexerConfig config
;
880 indexingEnabled
= config
.fileIndexingEnabled();
884 QMenu
* groupMenu
= 0;
886 // Add all roles to the menu that can be shown or hidden by the user
887 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
888 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
889 if (info
.role
== "text") {
890 // It should not be possible to hide the "text" role
894 const QString text
= m_model
->roleDescription(info
.role
);
896 if (info
.group
.isEmpty()) {
897 action
= menu
->addAction(text
);
899 if (!groupMenu
|| info
.group
!= groupName
) {
900 groupName
= info
.group
;
901 groupMenu
= menu
->addMenu(groupName
);
904 action
= groupMenu
->addAction(text
);
907 action
->setCheckable(true);
908 action
->setChecked(visibleRolesSet
.contains(info
.role
));
909 action
->setData(info
.role
);
911 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
912 (info
.requiresBaloo
) ||
913 (info
.requiresIndexer
&& indexingEnabled
);
914 action
->setEnabled(enable
);
917 menu
->addSeparator();
919 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
920 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
922 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
923 autoAdjustWidthsAction
->setCheckable(true);
924 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
925 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
927 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
928 customWidthsAction
->setCheckable(true);
929 customWidthsAction
->setChecked(!autoColumnWidths
);
930 customWidthsAction
->setActionGroup(widthsGroup
);
932 QAction
* action
= menu
->exec(pos
.toPoint());
933 if (menu
&& action
) {
934 KItemListHeader
* header
= view
->header();
936 if (action
== autoAdjustWidthsAction
) {
937 // Clear the column-widths from the viewproperties and turn on
938 // the automatic resizing of the columns
939 props
.setHeaderColumnWidths(QList
<int>());
940 header
->setAutomaticColumnResizing(true);
941 } else if (action
== customWidthsAction
) {
942 // Apply the current column-widths as custom column-widths and turn
943 // off the automatic resizing of the columns
944 QList
<int> columnWidths
;
945 foreach (const QByteArray
& role
, view
->visibleRoles()) {
946 columnWidths
.append(header
->columnWidth(role
));
948 props
.setHeaderColumnWidths(columnWidths
);
949 header
->setAutomaticColumnResizing(false);
951 // Show or hide the selected role
952 const QByteArray selectedRole
= action
->data().toByteArray();
954 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
955 if (action
->isChecked()) {
956 visibleRoles
.append(selectedRole
);
958 visibleRoles
.removeOne(selectedRole
);
961 view
->setVisibleRoles(visibleRoles
);
962 props
.setVisibleRoles(visibleRoles
);
964 QList
<int> columnWidths
;
965 if (!header
->automaticColumnResizing()) {
966 foreach (const QByteArray
& role
, view
->visibleRoles()) {
967 columnWidths
.append(header
->columnWidth(role
));
970 props
.setHeaderColumnWidths(columnWidths
);
977 void DolphinView::slotHeaderColumnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
)
981 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
983 ViewProperties
props(viewPropertiesUrl());
984 QList
<int> columnWidths
= props
.headerColumnWidths();
985 if (columnWidths
.count() != visibleRoles
.count()) {
986 columnWidths
.clear();
987 columnWidths
.reserve(visibleRoles
.count());
988 const KItemListHeader
* header
= m_view
->header();
989 foreach (const QByteArray
& role
, visibleRoles
) {
990 const int width
= header
->columnWidth(role
);
991 columnWidths
.append(width
);
995 const int roleIndex
= visibleRoles
.indexOf(role
);
996 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
997 columnWidths
[roleIndex
] = current
;
999 props
.setHeaderColumnWidths(columnWidths
);
1002 void DolphinView::slotItemHovered(int index
)
1004 const KFileItem item
= m_model
->fileItem(index
);
1006 if (GeneralSettings::showToolTips() && !m_dragging
) {
1007 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1008 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1009 itemRect
.moveTo(pos
);
1011 m_toolTipManager
->showToolTip(item
, itemRect
);
1014 emit
requestItemInfo(item
);
1017 void DolphinView::slotItemUnhovered(int index
)
1021 emit
requestItemInfo(KFileItem());
1024 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1027 KFileItem destItem
= m_model
->fileItem(index
);
1028 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1029 // Use the URL of the view as drop target if the item is no directory
1031 destItem
= m_model
->rootItem();
1034 // The item represents a directory or desktop-file
1035 destUrl
= destItem
.url();
1038 QDropEvent
dropEvent(event
->pos().toPoint(),
1039 event
->possibleActions(),
1042 event
->modifiers());
1045 KonqOperations
* op
= DragAndDropHelper::dropUrls(destItem
, destUrl
, &dropEvent
, error
);
1046 if (!error
.isEmpty()) {
1047 emit
infoMessage(error
);
1050 if (op
&& destUrl
== url()) {
1051 // Mark the dropped urls as selected.
1052 m_clearSelectionBeforeSelectingNewItems
= true;
1053 connect(op
, SIGNAL(aboutToCreate(KUrl::List
)), this, SLOT(slotAboutToCreate(KUrl::List
)));
1059 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1061 if (previous
!= 0) {
1062 disconnect(previous
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1063 m_versionControlObserver
->setModel(0);
1067 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1068 connect(current
, SIGNAL(loadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1070 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1071 m_versionControlObserver
->setModel(fileItemModel
);
1075 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1079 if (itemIndex
< 0) {
1080 // Trigger the history navigation only when clicking on the viewport:
1081 // Above an item the XButtons provide a simple way to select items in
1082 // the singleClick mode.
1083 if (buttons
& Qt::XButton1
) {
1084 emit
goBackRequested();
1085 } else if (buttons
& Qt::XButton2
) {
1086 emit
goForwardRequested();
1091 void DolphinView::slotAboutToCreate(const KUrl::List
& urls
)
1093 if (!urls
.isEmpty()) {
1094 if (m_markFirstNewlySelectedItemAsCurrent
) {
1095 markUrlAsCurrent(urls
.first());
1096 m_markFirstNewlySelectedItemAsCurrent
= false;
1098 m_selectedUrls
<< KUrl::List(KDirModel::simplifiedUrlList(urls
));
1102 void DolphinView::slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
)
1104 const int currentCount
= current
.count();
1105 const int previousCount
= previous
.count();
1106 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1107 (currentCount
> 0 && previousCount
== 0);
1109 // If nothing has been selected before and something got selected (or if something
1110 // was selected before and now nothing is selected) the selectionChangedSignal must
1111 // be emitted asynchronously as fast as possible to update the edit-actions.
1112 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1113 m_selectionChangedTimer
->start();
1116 void DolphinView::emitSelectionChangedSignal()
1118 m_selectionChangedTimer
->stop();
1119 emit
selectionChanged(selectedItems());
1122 void DolphinView::updateSortRole(const QByteArray
& role
)
1124 ViewProperties
props(viewPropertiesUrl());
1125 props
.setSortRole(role
);
1127 KItemModelBase
* model
= m_container
->controller()->model();
1128 model
->setSortRole(role
);
1130 emit
sortRoleChanged(role
);
1133 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1135 ViewProperties
props(viewPropertiesUrl());
1136 props
.setSortOrder(order
);
1138 m_model
->setSortOrder(order
);
1140 emit
sortOrderChanged(order
);
1143 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1145 ViewProperties
props(viewPropertiesUrl());
1146 props
.setSortFoldersFirst(foldersFirst
);
1148 m_model
->setSortDirectoriesFirst(foldersFirst
);
1150 emit
sortFoldersFirstChanged(foldersFirst
);
1153 QPair
<bool, QString
> DolphinView::pasteInfo() const
1155 return KonqOperations::pasteInfo(url());
1158 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1160 m_tabsForFiles
= tabsForFiles
;
1163 bool DolphinView::isTabsForFilesEnabled() const
1165 return m_tabsForFiles
;
1168 bool DolphinView::itemsExpandable() const
1170 return m_mode
== DetailsView
;
1173 void DolphinView::restoreState(QDataStream
& stream
)
1175 // Restore the current item that had the keyboard focus
1176 stream
>> m_currentItemUrl
;
1178 // Restore the view position
1179 stream
>> m_restoredContentsPosition
;
1181 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1184 m_model
->restoreExpandedDirectories(urls
);
1187 void DolphinView::saveState(QDataStream
& stream
)
1189 // Save the current item that has the keyboard focus
1190 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1191 if (currentIndex
!= -1) {
1192 KFileItem item
= m_model
->fileItem(currentIndex
);
1193 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1194 KUrl currentItemUrl
= item
.url();
1195 stream
<< currentItemUrl
;
1200 // Save view position
1201 const qreal x
= m_container
->horizontalScrollBar()->value();
1202 const qreal y
= m_container
->verticalScrollBar()->value();
1203 stream
<< QPoint(x
, y
);
1205 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1206 stream
<< m_model
->expandedDirectories();
1209 KFileItem
DolphinView::rootItem() const
1211 return m_model
->rootItem();
1214 void DolphinView::setViewPropertiesContext(const QString
& context
)
1216 m_viewPropertiesContext
= context
;
1219 QString
DolphinView::viewPropertiesContext() const
1221 return m_viewPropertiesContext
;
1224 KUrl
DolphinView::openItemAsFolderUrl(const KFileItem
& item
, const bool browseThroughArchives
)
1226 if (item
.isNull()) {
1230 KUrl url
= item
.targetUrl();
1236 if (item
.isMimeTypeKnown()) {
1237 const QString
& mimetype
= item
.mimetype();
1239 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1240 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1241 // zip:/<path>/ when clicking on a zip file, etc.
1242 // The .protocol file specifies the mimetype that the kioslave handles.
1243 // Note that we don't use mimetype inheritance since we don't want to
1244 // open OpenDocument files as zip folders...
1245 const QString
& protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1246 if (!protocol
.isEmpty()) {
1247 url
.setProtocol(protocol
);
1252 if (mimetype
== QLatin1String("application/x-desktop")) {
1253 // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
1254 KDesktopFile
desktopFile(url
.toLocalFile());
1255 if (desktopFile
.hasLinkType()) {
1256 const QString linkUrl
= desktopFile
.readUrl();
1257 if (!linkUrl
.startsWith(QLatin1String("http"))) {
1267 void DolphinView::observeCreatedItem(const KUrl
& url
)
1271 markUrlAsCurrent(url
);
1272 markUrlsAsSelected(QList
<KUrl
>() << url
);
1276 void DolphinView::slotDirectoryRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1278 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
1279 emit
redirection(oldUrl
, newUrl
);
1280 m_url
= newUrl
; // #186947
1284 void DolphinView::updateViewState()
1286 if (m_currentItemUrl
!= KUrl()) {
1287 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1288 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1289 if (currentIndex
!= -1) {
1290 selectionManager
->setCurrentItem(currentIndex
);
1292 // scroll to current item and reset the state
1293 if (m_scrollToCurrentItem
) {
1294 m_view
->scrollToItem(currentIndex
);
1295 m_scrollToCurrentItem
= false;
1298 m_currentItemUrl
= KUrl();
1300 selectionManager
->setCurrentItem(0);
1304 if (!m_restoredContentsPosition
.isNull()) {
1305 const int x
= m_restoredContentsPosition
.x();
1306 const int y
= m_restoredContentsPosition
.y();
1307 m_restoredContentsPosition
= QPoint();
1309 m_container
->horizontalScrollBar()->setValue(x
);
1310 m_container
->verticalScrollBar()->setValue(y
);
1313 if (!m_selectedUrls
.isEmpty()) {
1314 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1316 if (m_clearSelectionBeforeSelectingNewItems
) {
1317 selectionManager
->clearSelection();
1318 m_clearSelectionBeforeSelectingNewItems
= false;
1321 KItemSet selectedItems
= selectionManager
->selectedItems();
1323 QList
<KUrl
>::iterator it
= m_selectedUrls
.begin();
1324 while (it
!= m_selectedUrls
.end()) {
1325 const int index
= m_model
->index(*it
);
1327 selectedItems
.insert(index
);
1328 it
= m_selectedUrls
.erase(it
);
1334 selectionManager
->setSelectedItems(selectedItems
);
1338 void DolphinView::hideToolTip()
1340 if (GeneralSettings::showToolTips()) {
1341 m_toolTipManager
->hideToolTip();
1345 void DolphinView::calculateItemCount(int& fileCount
,
1347 KIO::filesize_t
& totalFileSize
) const
1349 const int itemCount
= m_model
->count();
1350 for (int i
= 0; i
< itemCount
; ++i
) {
1351 const KFileItem item
= m_model
->fileItem(i
);
1356 totalFileSize
+= item
.size();
1361 void DolphinView::showHoverInformation(const KFileItem
& item
)
1363 emit
requestItemInfo(item
);
1366 void DolphinView::clearHoverInformation()
1368 emit
requestItemInfo(KFileItem());
1371 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1373 if (job
->error() == 0) {
1374 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1375 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1376 emit
errorMessage(job
->errorString());
1380 void DolphinView::slotRenamingFailed(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1382 const int index
= m_model
->index(newUrl
);
1384 QHash
<QByteArray
, QVariant
> data
;
1385 data
.insert("text", oldUrl
.fileName());
1386 m_model
->setData(index
, data
);
1390 void DolphinView::slotDirectoryLoadingStarted()
1392 // Disable the writestate temporary until it can be determined in a fast way
1393 // in DolphinView::slotLoadingCompleted()
1394 if (m_isFolderWritable
) {
1395 m_isFolderWritable
= false;
1396 emit
writeStateChanged(m_isFolderWritable
);
1399 emit
directoryLoadingStarted();
1402 void DolphinView::slotDirectoryLoadingCompleted()
1404 // Update the view-state. This has to be done asynchronously
1405 // because the view might not be in its final state yet.
1406 QTimer::singleShot(0, this, SLOT(updateViewState()));
1408 emit
directoryLoadingCompleted();
1410 updateWritableState();
1413 void DolphinView::slotItemsChanged()
1415 m_assureVisibleCurrentIndex
= false;
1418 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1421 Q_ASSERT(m_model
->sortOrder() == current
);
1423 ViewProperties
props(viewPropertiesUrl());
1424 props
.setSortOrder(current
);
1426 emit
sortOrderChanged(current
);
1429 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1432 Q_ASSERT(m_model
->sortRole() == current
);
1434 ViewProperties
props(viewPropertiesUrl());
1435 props
.setSortRole(current
);
1437 emit
sortRoleChanged(current
);
1440 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1441 const QList
<QByteArray
>& previous
)
1444 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1446 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1448 m_visibleRoles
= current
;
1450 ViewProperties
props(viewPropertiesUrl());
1451 props
.setVisibleRoles(m_visibleRoles
);
1453 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1456 void DolphinView::slotRoleEditingCanceled()
1458 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
1459 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
1462 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1464 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
1465 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
1467 if (index
< 0 || index
>= m_model
->count()) {
1471 if (role
== "text") {
1472 const KFileItem oldItem
= m_model
->fileItem(index
);
1473 const QString newName
= value
.toString();
1474 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1String(".") && newName
!= QLatin1String("..")) {
1475 const KUrl oldUrl
= oldItem
.url();
1477 const KUrl
newUrl(url().path(KUrl::AddTrailingSlash
) + newName
);
1478 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1479 if (!newNameExistsAlready
) {
1480 // Only change the data in the model if no item with the new name
1481 // is in the model yet. If there is an item with the new name
1482 // already, calling KonqOperations::rename() will open a dialog
1483 // asking for a new name, and KFileItemModel will update the
1484 // data when the dir lister signals that the file name has changed.
1485 QHash
<QByteArray
, QVariant
> data
;
1486 data
.insert(role
, value
);
1487 m_model
->setData(index
, data
);
1490 KonqOperations
* op
= KonqOperations::renameV2(this, oldUrl
, newName
);
1491 if (op
&& !newNameExistsAlready
) {
1492 // Only connect the renamingFailed signal if there is no item with the new name
1493 // in the model yet, see bug 328262.
1494 connect(op
, SIGNAL(renamingFailed(KUrl
,KUrl
)), SLOT(slotRenamingFailed(KUrl
,KUrl
)));
1500 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1502 if (!url
.isValid()) {
1503 const QString
location(url
.pathOrUrl());
1504 if (location
.isEmpty()) {
1505 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1507 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1513 m_model
->refreshDirectory(url
);
1515 m_model
->loadDirectory(url
);
1519 void DolphinView::applyViewProperties()
1521 const ViewProperties
props(viewPropertiesUrl());
1522 applyViewProperties(props
);
1525 void DolphinView::applyViewProperties(const ViewProperties
& props
)
1527 m_view
->beginTransaction();
1529 const Mode mode
= props
.viewMode();
1530 if (m_mode
!= mode
) {
1531 const Mode previousMode
= m_mode
;
1534 // Changing the mode might result in changing
1535 // the zoom level. Remember the old zoom level so
1536 // that zoomLevelChanged() can get emitted.
1537 const int oldZoomLevel
= m_view
->zoomLevel();
1540 emit
modeChanged(m_mode
, previousMode
);
1542 if (m_view
->zoomLevel() != oldZoomLevel
) {
1543 emit
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1547 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1548 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1549 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1550 emit
hiddenFilesShownChanged(hiddenFilesShown
);
1553 const bool groupedSorting
= props
.groupedSorting();
1554 if (groupedSorting
!= m_model
->groupedSorting()) {
1555 m_model
->setGroupedSorting(groupedSorting
);
1556 emit
groupedSortingChanged(groupedSorting
);
1559 const QByteArray sortRole
= props
.sortRole();
1560 if (sortRole
!= m_model
->sortRole()) {
1561 m_model
->setSortRole(sortRole
);
1562 emit
sortRoleChanged(sortRole
);
1565 const Qt::SortOrder sortOrder
= props
.sortOrder();
1566 if (sortOrder
!= m_model
->sortOrder()) {
1567 m_model
->setSortOrder(sortOrder
);
1568 emit
sortOrderChanged(sortOrder
);
1571 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1572 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1573 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1574 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1577 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1578 if (visibleRoles
!= m_visibleRoles
) {
1579 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1580 m_visibleRoles
= visibleRoles
;
1581 m_view
->setVisibleRoles(visibleRoles
);
1582 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1585 const bool previewsShown
= props
.previewsShown();
1586 if (previewsShown
!= m_view
->previewsShown()) {
1587 const int oldZoomLevel
= zoomLevel();
1589 m_view
->setPreviewsShown(previewsShown
);
1590 emit
previewsShownChanged(previewsShown
);
1592 // Changing the preview-state might result in a changed zoom-level
1593 if (oldZoomLevel
!= zoomLevel()) {
1594 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1598 KItemListView
* itemListView
= m_container
->controller()->view();
1599 if (itemListView
->isHeaderVisible()) {
1600 KItemListHeader
* header
= itemListView
->header();
1601 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
1602 const int rolesCount
= m_visibleRoles
.count();
1603 if (headerColumnWidths
.count() == rolesCount
) {
1604 header
->setAutomaticColumnResizing(false);
1606 QHash
<QByteArray
, qreal
> columnWidths
;
1607 for (int i
= 0; i
< rolesCount
; ++i
) {
1608 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
1610 header
->setColumnWidths(columnWidths
);
1612 header
->setAutomaticColumnResizing(true);
1616 m_view
->endTransaction();
1619 void DolphinView::applyModeToView()
1622 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
1623 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
1624 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1625 default: Q_ASSERT(false); break;
1629 void DolphinView::pasteToUrl(const KUrl
& url
)
1631 KonqOperations
* op
= KonqOperations::doPasteV2(this, url
);
1633 m_clearSelectionBeforeSelectingNewItems
= true;
1634 m_markFirstNewlySelectedItemAsCurrent
= true;
1635 connect(op
, SIGNAL(aboutToCreate(KUrl::List
)), this, SLOT(slotAboutToCreate(KUrl::List
)));
1639 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1643 const KFileItemList items
= selectedItems();
1644 foreach (const KFileItem
& item
, items
) {
1645 urls
.append(item
.url());
1648 if (itemsExpandable()) {
1649 // TODO: Check if we still need KDirModel for this in KDE 5.0
1650 urls
= KDirModel::simplifiedUrlList(urls
);
1656 QMimeData
* DolphinView::selectionMimeData() const
1658 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1659 const KItemSet selectedIndexes
= selectionManager
->selectedItems();
1661 return m_model
->createMimeData(selectedIndexes
);
1664 void DolphinView::updateWritableState()
1666 const bool wasFolderWritable
= m_isFolderWritable
;
1667 m_isFolderWritable
= false;
1669 KFileItem item
= m_model
->rootItem();
1670 if (item
.isNull()) {
1671 // Try to find out if the URL is writable even if the "root item" is
1672 // null, see https://bugs.kde.org/show_bug.cgi?id=330001
1673 item
= KFileItem(KFileItem::Unknown
, KFileItem::Unknown
, url(), true);
1676 KFileItemListProperties
capabilities(KFileItemList() << item
);
1677 m_isFolderWritable
= capabilities
.supportsWriting();
1679 if (m_isFolderWritable
!= wasFolderWritable
) {
1680 emit
writeStateChanged(m_isFolderWritable
);
1684 KUrl
DolphinView::viewPropertiesUrl() const
1686 if (m_viewPropertiesContext
.isEmpty()) {
1691 url
.setProtocol(m_url
.protocol());
1692 url
.setPath(m_viewPropertiesContext
);
1696 #include "dolphinview.moc"