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 <KActionCollection>
37 #include <KColorScheme>
39 #include <KIconEffect>
41 #include <KFileItemListProperties>
43 #include <kitemviews/kfileitemmodel.h>
44 #include <kitemviews/kfileitemlistview.h>
45 #include <kitemviews/kitemlistcontainer.h>
46 #include <kitemviews/kitemlistheader.h>
47 #include <kitemviews/kitemlistselectionmanager.h>
48 #include <kitemviews/kitemlistview.h>
49 #include <kitemviews/kitemlistcontroller.h>
50 #include <KIO/DeleteJob>
51 #include <KIO/JobUiDelegate>
52 #include <KIO/NetAccess>
53 #include <KIO/PreviewJob>
56 #include <KMessageBox>
57 #include <konq_fileitemcapabilities.h>
58 #include <konq_operations.h>
59 #include <konqmimedata.h>
60 #include <KToggleAction>
63 #include "dolphinnewfilemenuobserver.h"
64 #include "dolphin_detailsmodesettings.h"
65 #include "dolphin_generalsettings.h"
66 #include "dolphinitemlistview.h"
67 #include "draganddrophelper.h"
68 #include "renamedialog.h"
69 #include "versioncontrol/versioncontrolobserver.h"
70 #include "viewmodecontroller.h"
71 #include "viewproperties.h"
72 #include "views/tooltips/tooltipmanager.h"
73 #include "zoomlevelinfo.h"
76 #include <Nepomuk/ResourceManager>
80 const int MaxModeEnum
= DolphinView::CompactView
;
83 DolphinView::DolphinView(const KUrl
& url
, QWidget
* parent
) :
86 m_tabsForFiles(false),
87 m_assureVisibleCurrentIndex(false),
88 m_isFolderWritable(true),
91 m_viewPropertiesContext(),
92 m_mode(DolphinView::IconsView
),
99 m_selectionChangedTimer(0),
101 m_scrollToCurrentItem(false),
102 m_restoredContentsPosition(),
104 m_clearSelectionBeforeSelectingNewItems(false),
105 m_versionControlObserver(0)
107 m_topLayout
= new QVBoxLayout(this);
108 m_topLayout
->setSpacing(0);
109 m_topLayout
->setMargin(0);
111 // When a new item has been created by the "Create New..." menu, the item should
112 // get selected and it must be assured that the item will get visible. As the
113 // creation is done asynchronously, several signals must be checked:
114 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(KUrl
)),
115 this, SLOT(observeCreatedItem(KUrl
)));
117 m_selectionChangedTimer
= new QTimer(this);
118 m_selectionChangedTimer
->setSingleShot(true);
119 m_selectionChangedTimer
->setInterval(300);
120 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
121 this, SLOT(emitSelectionChangedSignal()));
123 m_model
= new KFileItemModel(this);
124 m_view
= new DolphinItemListView();
125 m_view
->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
126 m_view
->setVisibleRoles(QList
<QByteArray
>() << "text");
129 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
130 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
131 controller
->setAutoActivationDelay(delay
);
133 // The EnlargeSmallPreviews setting can only be changed after the model
134 // has been set in the view by KItemListController.
135 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
137 m_container
= new KItemListContainer(controller
, this);
138 m_container
->installEventFilter(this);
139 setFocusProxy(m_container
);
140 connect(m_container
->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip()));
141 connect(m_container
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip()));
143 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
144 connect(controller
, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
145 connect(controller
, SIGNAL(itemsActivated(QSet
<int>)), this, SLOT(slotItemsActivated(QSet
<int>)));
146 connect(controller
, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
147 connect(controller
, SIGNAL(itemContextMenuRequested(int,QPointF
)), this, SLOT(slotItemContextMenuRequested(int,QPointF
)));
148 connect(controller
, SIGNAL(viewContextMenuRequested(QPointF
)), this, SLOT(slotViewContextMenuRequested(QPointF
)));
149 connect(controller
, SIGNAL(headerContextMenuRequested(QPointF
)), this, SLOT(slotHeaderContextMenuRequested(QPointF
)));
150 connect(controller
, SIGNAL(mouseButtonPressed(int,Qt::MouseButtons
)), this, SLOT(slotMouseButtonPressed(int,Qt::MouseButtons
)));
151 connect(controller
, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int)));
152 connect(controller
, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int)));
153 connect(controller
, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent
*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent
*)));
154 connect(controller
, SIGNAL(modelChanged(KItemModelBase
*,KItemModelBase
*)), this, SLOT(slotModelChanged(KItemModelBase
*,KItemModelBase
*)));
156 connect(m_model
, SIGNAL(directoryLoadingStarted()), this, SLOT(slotDirectoryLoadingStarted()));
157 connect(m_model
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
158 connect(m_model
, SIGNAL(directoryLoadingProgress(int)), this, SIGNAL(directoryLoadingProgress(int)));
159 connect(m_model
, SIGNAL(directorySortingProgress(int)), this, SIGNAL(directorySortingProgress(int)));
160 connect(m_model
, SIGNAL(itemsChanged(KItemRangeList
,QSet
<QByteArray
>)),
161 this, SLOT(slotItemsChanged()));
162 connect(m_model
, SIGNAL(itemsRemoved(KItemRangeList
)), this, SIGNAL(itemCountChanged()));
163 connect(m_model
, SIGNAL(itemsInserted(KItemRangeList
)), this, SIGNAL(itemCountChanged()));
164 connect(m_model
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
165 connect(m_model
, SIGNAL(errorMessage(QString
)), this, SIGNAL(errorMessage(QString
)));
166 connect(m_model
, SIGNAL(directoryRedirection(KUrl
,KUrl
)), this, SLOT(slotDirectoryRedirection(KUrl
,KUrl
)));
167 connect(m_model
, SIGNAL(urlIsFileError(KUrl
)), this, SIGNAL(urlIsFileError(KUrl
)));
169 m_view
->installEventFilter(this);
170 connect(m_view
, SIGNAL(sortOrderChanged(Qt::SortOrder
,Qt::SortOrder
)),
171 this, SLOT(slotSortOrderChangedByHeader(Qt::SortOrder
,Qt::SortOrder
)));
172 connect(m_view
, SIGNAL(sortRoleChanged(QByteArray
,QByteArray
)),
173 this, SLOT(slotSortRoleChangedByHeader(QByteArray
,QByteArray
)));
174 connect(m_view
, SIGNAL(visibleRolesChanged(QList
<QByteArray
>,QList
<QByteArray
>)),
175 this, SLOT(slotVisibleRolesChangedByHeader(QList
<QByteArray
>,QList
<QByteArray
>)));
176 connect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
177 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
178 connect(m_view
->header(), SIGNAL(columnWidthChanged(QByteArray
,qreal
,qreal
)),
179 this, SLOT(slotHeaderColumnWidthChanged(QByteArray
,qreal
,qreal
)));
181 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
182 connect(selectionManager
, SIGNAL(selectionChanged(QSet
<int>,QSet
<int>)),
183 this, SLOT(slotSelectionChanged(QSet
<int>,QSet
<int>)));
185 m_toolTipManager
= new ToolTipManager(this);
187 m_versionControlObserver
= new VersionControlObserver(this);
188 m_versionControlObserver
->setModel(m_model
);
189 connect(m_versionControlObserver
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
190 connect(m_versionControlObserver
, SIGNAL(errorMessage(QString
)), this, SIGNAL(errorMessage(QString
)));
191 connect(m_versionControlObserver
, SIGNAL(operationCompletedMessage(QString
)), this, SIGNAL(operationCompletedMessage(QString
)));
193 applyViewProperties();
194 m_topLayout
->addWidget(m_container
);
199 DolphinView::~DolphinView()
203 KUrl
DolphinView::url() const
208 void DolphinView::setActive(bool active
)
210 if (active
== m_active
) {
216 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
221 QWidget
* viewport
= m_container
->viewport();
224 palette
.setColor(viewport
->backgroundRole(), color
);
225 viewport
->setPalette(palette
);
231 m_container
->setFocus();
233 emit
writeStateChanged(m_isFolderWritable
);
237 bool DolphinView::isActive() const
242 void DolphinView::setMode(Mode mode
)
244 if (mode
!= m_mode
) {
245 ViewProperties
props(viewPropertiesUrl());
246 props
.setViewMode(mode
);
249 applyViewProperties();
253 DolphinView::Mode
DolphinView::mode() const
258 void DolphinView::setPreviewsShown(bool show
)
260 if (previewsShown() == show
) {
264 ViewProperties
props(viewPropertiesUrl());
265 props
.setPreviewsShown(show
);
267 const int oldZoomLevel
= m_view
->zoomLevel();
268 m_view
->setPreviewsShown(show
);
269 emit
previewsShownChanged(show
);
271 const int newZoomLevel
= m_view
->zoomLevel();
272 if (newZoomLevel
!= oldZoomLevel
) {
273 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
277 bool DolphinView::previewsShown() const
279 return m_view
->previewsShown();
282 void DolphinView::setHiddenFilesShown(bool show
)
284 if (m_model
->showHiddenFiles() == show
) {
288 const KFileItemList itemList
= selectedItems();
289 m_selectedUrls
.clear();
290 m_selectedUrls
= itemList
.urlList();
292 ViewProperties
props(viewPropertiesUrl());
293 props
.setHiddenFilesShown(show
);
295 m_model
->setShowHiddenFiles(show
);
296 emit
hiddenFilesShownChanged(show
);
299 bool DolphinView::hiddenFilesShown() const
301 return m_model
->showHiddenFiles();
304 void DolphinView::setGroupedSorting(bool grouped
)
306 if (grouped
== groupedSorting()) {
310 ViewProperties
props(viewPropertiesUrl());
311 props
.setGroupedSorting(grouped
);
314 m_container
->controller()->model()->setGroupedSorting(grouped
);
316 emit
groupedSortingChanged(grouped
);
319 bool DolphinView::groupedSorting() const
321 return m_model
->groupedSorting();
324 KFileItemList
DolphinView::items() const
327 const int itemCount
= m_model
->count();
328 list
.reserve(itemCount
);
330 for (int i
= 0; i
< itemCount
; ++i
) {
331 list
.append(m_model
->fileItem(i
));
337 int DolphinView::itemsCount() const
339 return m_model
->count();
342 KFileItemList
DolphinView::selectedItems() const
344 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
345 QList
<int> selectedIndexes
= selectionManager
->selectedItems().toList();
347 qSort(selectedIndexes
);
349 KFileItemList selectedItems
;
350 QListIterator
<int> it(selectedIndexes
);
351 while (it
.hasNext()) {
352 const int index
= it
.next();
353 selectedItems
.append(m_model
->fileItem(index
));
355 return selectedItems
;
358 int DolphinView::selectedItemsCount() const
360 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
361 return selectionManager
->selectedItems().count();
364 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
366 m_selectedUrls
= urls
;
369 void DolphinView::markUrlAsCurrent(const KUrl
& url
)
371 m_currentItemUrl
= url
;
372 m_scrollToCurrentItem
= true;
375 void DolphinView::selectItems(const QRegExp
& pattern
, bool enabled
)
377 const KItemListSelectionManager::SelectionMode mode
= enabled
378 ? KItemListSelectionManager::Select
379 : KItemListSelectionManager::Deselect
;
380 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
382 for (int index
= 0; index
< m_model
->count(); index
++) {
383 const KFileItem item
= m_model
->fileItem(index
);
384 if (pattern
.exactMatch(item
.text())) {
385 // An alternative approach would be to store the matching items in a QSet<int> and
386 // select them in one go after the loop, but we'd need a new function
387 // KItemListSelectionManager::setSelected(QSet<int>, SelectionMode mode)
389 selectionManager
->setSelected(index
, 1, mode
);
394 void DolphinView::setZoomLevel(int level
)
396 const int oldZoomLevel
= zoomLevel();
397 m_view
->setZoomLevel(level
);
398 if (zoomLevel() != oldZoomLevel
) {
400 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
404 int DolphinView::zoomLevel() const
406 return m_view
->zoomLevel();
409 void DolphinView::setSortRole(const QByteArray
& role
)
411 if (role
!= sortRole()) {
412 updateSortRole(role
);
416 QByteArray
DolphinView::sortRole() const
418 const KItemModelBase
* model
= m_container
->controller()->model();
419 return model
->sortRole();
422 void DolphinView::setSortOrder(Qt::SortOrder order
)
424 if (sortOrder() != order
) {
425 updateSortOrder(order
);
429 Qt::SortOrder
DolphinView::sortOrder() const
431 return m_model
->sortOrder();
434 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
436 if (sortFoldersFirst() != foldersFirst
) {
437 updateSortFoldersFirst(foldersFirst
);
441 bool DolphinView::sortFoldersFirst() const
443 return m_model
->sortDirectoriesFirst();
446 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
448 const QList
<QByteArray
> previousRoles
= roles
;
450 ViewProperties
props(viewPropertiesUrl());
451 props
.setVisibleRoles(roles
);
453 m_visibleRoles
= roles
;
454 m_view
->setVisibleRoles(roles
);
456 emit
visibleRolesChanged(m_visibleRoles
, previousRoles
);
459 QList
<QByteArray
> DolphinView::visibleRoles() const
461 return m_visibleRoles
;
464 void DolphinView::reload()
466 QByteArray viewState
;
467 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
468 saveState(saveStream
);
470 const KFileItemList itemList
= selectedItems();
471 m_selectedUrls
.clear();
472 m_selectedUrls
= itemList
.urlList();
475 loadDirectory(url(), true);
477 QDataStream
restoreStream(viewState
);
478 restoreState(restoreStream
);
481 void DolphinView::stopLoading()
483 m_model
->cancelDirectoryLoading();
486 void DolphinView::readSettings()
488 const int oldZoomLevel
= m_view
->zoomLevel();
490 GeneralSettings::self()->readConfig();
491 m_view
->readSettings();
492 applyViewProperties();
494 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
495 m_container
->controller()->setAutoActivationDelay(delay
);
497 const int newZoomLevel
= m_view
->zoomLevel();
498 if (newZoomLevel
!= oldZoomLevel
) {
499 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
503 void DolphinView::writeSettings()
505 GeneralSettings::self()->writeConfig();
506 m_view
->writeSettings();
509 void DolphinView::setNameFilter(const QString
& nameFilter
)
511 m_model
->setNameFilter(nameFilter
);
514 QString
DolphinView::nameFilter() const
516 return m_model
->nameFilter();
519 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
521 return m_model
->setMimeTypeFilters(filters
);
524 QStringList
DolphinView::mimeTypeFilters() const
526 return m_model
->mimeTypeFilters();
529 QString
DolphinView::statusBarText() const
537 KIO::filesize_t totalFileSize
= 0;
539 if (m_container
->controller()->selectionManager()->hasSelection()) {
540 // Give a summary of the status of the selected files
541 const KFileItemList list
= selectedItems();
542 foreach (const KFileItem
& item
, list
) {
547 totalFileSize
+= item
.size();
551 if (folderCount
+ fileCount
== 1) {
552 // If only one item is selected, show the filename
553 filesText
= i18nc("@info:status", "<filename>%1</filename> selected", list
.first().text());
555 // At least 2 items are selected
556 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
557 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
560 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
561 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
562 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
565 if (fileCount
> 0 && folderCount
> 0) {
566 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
567 foldersText
, filesText
,
568 KGlobal::locale()->formatByteSize(totalFileSize
));
569 } else if (fileCount
> 0) {
570 summary
= i18nc("@info:status files (size)", "%1 (%2)",
572 KGlobal::locale()->formatByteSize(totalFileSize
));
573 } else if (folderCount
> 0) {
574 summary
= foldersText
;
576 summary
= i18nc("@info:status", "0 Folders, 0 Files");
582 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
584 QList
<QAction
*> actions
;
586 if (items
.isEmpty()) {
587 const KFileItem item
= m_model
->rootItem();
588 if (!item
.isNull()) {
589 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
592 actions
= m_versionControlObserver
->actions(items
);
598 void DolphinView::setUrl(const KUrl
& url
)
606 emit
urlAboutToBeChanged(url
);
611 // It is important to clear the items from the model before
612 // applying the view properties, otherwise expensive operations
613 // might be done on the existing items although they get cleared
614 // anyhow afterwards by loadDirectory().
616 applyViewProperties();
619 emit
urlChanged(url
);
622 void DolphinView::selectAll()
624 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
625 selectionManager
->setSelected(0, m_model
->count());
628 void DolphinView::invertSelection()
630 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
631 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
634 void DolphinView::clearSelection()
636 m_selectedUrls
.clear();
637 m_container
->controller()->selectionManager()->clearSelection();
640 void DolphinView::renameSelectedItems()
642 const KFileItemList items
= selectedItems();
643 if (items
.isEmpty()) {
647 if (items
.count() == 1 && GeneralSettings::renameInline()) {
648 const int index
= m_model
->index(items
.first());
649 m_view
->editRole(index
, "text");
651 RenameDialog
* dialog
= new RenameDialog(this, items
);
652 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
655 dialog
->activateWindow();
658 // Assure that the current index remains visible when KFileItemModel
659 // will notify the view about changed items (which might result in
660 // a changed sorting).
661 m_assureVisibleCurrentIndex
= true;
664 void DolphinView::trashSelectedItems()
666 const KUrl::List list
= simplifiedSelectedUrls();
667 KonqOperations::del(this, KonqOperations::TRASH
, list
);
670 void DolphinView::deleteSelectedItems()
672 const KUrl::List list
= simplifiedSelectedUrls();
673 const bool del
= KonqOperations::askDeleteConfirmation(list
,
675 KonqOperations::DEFAULT_CONFIRMATION
,
679 KIO::Job
* job
= KIO::del(list
);
681 job
->ui()->setWindow(this);
683 connect(job
, SIGNAL(result(KJob
*)),
684 this, SLOT(slotDeleteFileFinished(KJob
*)));
688 void DolphinView::cutSelectedItems()
690 QMimeData
* mimeData
= selectionMimeData();
691 KonqMimeData::addIsCutSelection(mimeData
, true);
692 QApplication::clipboard()->setMimeData(mimeData
);
695 void DolphinView::copySelectedItems()
697 QMimeData
* mimeData
= selectionMimeData();
698 QApplication::clipboard()->setMimeData(mimeData
);
701 void DolphinView::paste()
706 void DolphinView::pasteIntoFolder()
708 const KFileItemList items
= selectedItems();
709 if ((items
.count() == 1) && items
.first().isDir()) {
710 pasteToUrl(items
.first().url());
714 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
716 switch (event
->type()) {
717 case QEvent::FocusIn
:
718 if (watched
== m_container
) {
723 case QEvent::GraphicsSceneDragEnter
:
724 if (watched
== m_view
) {
729 case QEvent::GraphicsSceneDragLeave
:
730 if (watched
== m_view
) {
735 case QEvent::GraphicsSceneDrop
:
736 if (watched
== m_view
) {
743 return QWidget::eventFilter(watched
, event
);
746 void DolphinView::wheelEvent(QWheelEvent
* event
)
748 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
749 const int numDegrees
= event
->delta() / 8;
750 const int numSteps
= numDegrees
/ 15;
752 setZoomLevel(zoomLevel() + numSteps
);
759 void DolphinView::hideEvent(QHideEvent
* event
)
762 QWidget::hideEvent(event
);
765 bool DolphinView::event(QEvent
* event
)
768 * Dolphin leaves file preview tooltips open even when is not visible.
770 * Hide tool-tip when Dolphin loses focus.
772 if (event
->type() == QEvent::WindowDeactivate
) {
776 return QWidget::event(event
);
779 void DolphinView::activate()
784 void DolphinView::slotItemActivated(int index
)
786 const KFileItem item
= m_model
->fileItem(index
);
787 if (!item
.isNull()) {
788 emit
itemActivated(item
);
792 void DolphinView::slotItemsActivated(const QSet
<int>& indexes
)
794 Q_ASSERT(indexes
.count() >= 2);
798 QSetIterator
<int> it(indexes
);
799 while (it
.hasNext()) {
800 const int index
= it
.next();
801 items
.append(m_model
->fileItem(index
));
804 foreach (const KFileItem
& item
, items
) {
806 emit
tabRequested(item
.url());
808 emit
itemActivated(item
);
813 void DolphinView::slotItemMiddleClicked(int index
)
815 const KFileItem item
= m_model
->fileItem(index
);
816 if (item
.isDir() || isTabsForFilesEnabled()) {
817 emit
tabRequested(item
.url());
821 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
823 const KFileItem item
= m_model
->fileItem(index
);
824 emit
requestContextMenu(pos
.toPoint(), item
, url(), QList
<QAction
*>());
827 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
829 emit
requestContextMenu(pos
.toPoint(), KFileItem(), url(), QList
<QAction
*>());
832 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
834 ViewProperties
props(viewPropertiesUrl());
836 QPointer
<KMenu
> menu
= new KMenu(QApplication::activeWindow());
838 KItemListView
* view
= m_container
->controller()->view();
839 const QSet
<QByteArray
> visibleRolesSet
= view
->visibleRoles().toSet();
841 bool nepomukRunning
= false;
842 bool indexingEnabled
= false;
844 nepomukRunning
= (Nepomuk::ResourceManager::instance()->initialized());
845 if (nepomukRunning
) {
846 KConfig
config("nepomukserverrc");
847 indexingEnabled
= config
.group("Service-nepomukfileindexer").readEntry("autostart", false);
852 QMenu
* groupMenu
= 0;
854 // Add all roles to the menu that can be shown or hidden by the user
855 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
856 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
857 if (info
.role
== "text") {
858 // It should not be possible to hide the "text" role
862 const QString text
= m_model
->roleDescription(info
.role
);
864 if (info
.group
.isEmpty()) {
865 action
= menu
->addAction(text
);
867 if (!groupMenu
|| info
.group
!= groupName
) {
868 groupName
= info
.group
;
869 groupMenu
= menu
->addMenu(groupName
);
872 action
= groupMenu
->addAction(text
);
875 action
->setCheckable(true);
876 action
->setChecked(visibleRolesSet
.contains(info
.role
));
877 action
->setData(info
.role
);
879 const bool enable
= (!info
.requiresNepomuk
&& !info
.requiresIndexer
) ||
880 (info
.requiresNepomuk
&& nepomukRunning
) ||
881 (info
.requiresIndexer
&& indexingEnabled
);
882 action
->setEnabled(enable
);
885 menu
->addSeparator();
887 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
888 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
890 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
891 autoAdjustWidthsAction
->setCheckable(true);
892 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
893 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
895 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
896 customWidthsAction
->setCheckable(true);
897 customWidthsAction
->setChecked(!autoColumnWidths
);
898 customWidthsAction
->setActionGroup(widthsGroup
);
900 QAction
* action
= menu
->exec(pos
.toPoint());
901 if (menu
&& action
) {
902 KItemListHeader
* header
= view
->header();
904 if (action
== autoAdjustWidthsAction
) {
905 // Clear the column-widths from the viewproperties and turn on
906 // the automatic resizing of the columns
907 props
.setHeaderColumnWidths(QList
<int>());
908 header
->setAutomaticColumnResizing(true);
909 } else if (action
== customWidthsAction
) {
910 // Apply the current column-widths as custom column-widths and turn
911 // off the automatic resizing of the columns
912 QList
<int> columnWidths
;
913 foreach (const QByteArray
& role
, view
->visibleRoles()) {
914 columnWidths
.append(header
->columnWidth(role
));
916 props
.setHeaderColumnWidths(columnWidths
);
917 header
->setAutomaticColumnResizing(false);
919 // Show or hide the selected role
920 const QByteArray selectedRole
= action
->data().toByteArray();
922 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
923 if (action
->isChecked()) {
924 visibleRoles
.append(selectedRole
);
926 visibleRoles
.removeOne(selectedRole
);
929 view
->setVisibleRoles(visibleRoles
);
930 props
.setVisibleRoles(visibleRoles
);
932 QList
<int> columnWidths
;
933 if (!header
->automaticColumnResizing()) {
934 foreach (const QByteArray
& role
, view
->visibleRoles()) {
935 columnWidths
.append(header
->columnWidth(role
));
938 props
.setHeaderColumnWidths(columnWidths
);
945 void DolphinView::slotHeaderColumnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
)
949 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
951 ViewProperties
props(viewPropertiesUrl());
952 QList
<int> columnWidths
= props
.headerColumnWidths();
953 if (columnWidths
.count() != visibleRoles
.count()) {
954 columnWidths
.clear();
955 columnWidths
.reserve(visibleRoles
.count());
956 const KItemListHeader
* header
= m_view
->header();
957 foreach (const QByteArray
& role
, visibleRoles
) {
958 const int width
= header
->columnWidth(role
);
959 columnWidths
.append(width
);
963 const int roleIndex
= visibleRoles
.indexOf(role
);
964 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
965 columnWidths
[roleIndex
] = current
;
967 props
.setHeaderColumnWidths(columnWidths
);
970 void DolphinView::slotItemHovered(int index
)
972 const KFileItem item
= m_model
->fileItem(index
);
974 if (GeneralSettings::showToolTips() && !m_dragging
) {
975 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
976 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
977 itemRect
.moveTo(pos
);
979 m_toolTipManager
->showToolTip(item
, itemRect
);
982 emit
requestItemInfo(item
);
985 void DolphinView::slotItemUnhovered(int index
)
989 emit
requestItemInfo(KFileItem());
992 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
995 KFileItem destItem
= m_model
->fileItem(index
);
996 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
997 // Use the URL of the view as drop target if the item is no directory
999 destItem
= m_model
->rootItem();
1002 // The item represents a directory or desktop-file
1003 destUrl
= destItem
.url();
1006 QDropEvent
dropEvent(event
->pos().toPoint(),
1007 event
->possibleActions(),
1010 event
->modifiers());
1012 const QString error
= DragAndDropHelper::dropUrls(destItem
, destUrl
, &dropEvent
);
1013 if (!error
.isEmpty()) {
1014 emit
errorMessage(error
);
1017 if (destUrl
== url()) {
1018 // Mark the dropped urls as selected.
1019 markPastedUrlsAsSelected(event
->mimeData());
1023 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1025 if (previous
!= 0) {
1026 disconnect(previous
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1027 m_versionControlObserver
->setModel(0);
1031 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1032 connect(current
, SIGNAL(loadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1034 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1035 m_versionControlObserver
->setModel(fileItemModel
);
1039 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1043 if (itemIndex
< 0) {
1044 // Trigger the history navigation only when clicking on the viewport:
1045 // Above an item the XButtons provide a simple way to select items in
1046 // the singleClick mode.
1047 if (buttons
& Qt::XButton1
) {
1048 emit
goBackRequested();
1049 } else if (buttons
& Qt::XButton2
) {
1050 emit
goForwardRequested();
1055 void DolphinView::slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
)
1057 const int currentCount
= current
.count();
1058 const int previousCount
= previous
.count();
1059 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1060 (currentCount
> 0 && previousCount
== 0);
1062 // If nothing has been selected before and something got selected (or if something
1063 // was selected before and now nothing is selected) the selectionChangedSignal must
1064 // be emitted asynchronously as fast as possible to update the edit-actions.
1065 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1066 m_selectionChangedTimer
->start();
1069 void DolphinView::emitSelectionChangedSignal()
1071 m_selectionChangedTimer
->stop();
1072 emit
selectionChanged(selectedItems());
1075 void DolphinView::updateSortRole(const QByteArray
& role
)
1077 ViewProperties
props(viewPropertiesUrl());
1078 props
.setSortRole(role
);
1080 KItemModelBase
* model
= m_container
->controller()->model();
1081 model
->setSortRole(role
);
1083 emit
sortRoleChanged(role
);
1086 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1088 ViewProperties
props(viewPropertiesUrl());
1089 props
.setSortOrder(order
);
1091 m_model
->setSortOrder(order
);
1093 emit
sortOrderChanged(order
);
1096 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1098 ViewProperties
props(viewPropertiesUrl());
1099 props
.setSortFoldersFirst(foldersFirst
);
1101 m_model
->setSortDirectoriesFirst(foldersFirst
);
1103 emit
sortFoldersFirstChanged(foldersFirst
);
1106 QPair
<bool, QString
> DolphinView::pasteInfo() const
1108 return KonqOperations::pasteInfo(url());
1111 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1113 m_tabsForFiles
= tabsForFiles
;
1116 bool DolphinView::isTabsForFilesEnabled() const
1118 return m_tabsForFiles
;
1121 bool DolphinView::itemsExpandable() const
1123 return m_mode
== DetailsView
;
1126 void DolphinView::restoreState(QDataStream
& stream
)
1128 // Restore the current item that had the keyboard focus
1129 stream
>> m_currentItemUrl
;
1131 // Restore the view position
1132 stream
>> m_restoredContentsPosition
;
1134 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1137 m_model
->restoreExpandedDirectories(urls
);
1140 void DolphinView::saveState(QDataStream
& stream
)
1142 // Save the current item that has the keyboard focus
1143 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1144 if (currentIndex
!= -1) {
1145 KFileItem item
= m_model
->fileItem(currentIndex
);
1146 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1147 KUrl currentItemUrl
= item
.url();
1148 stream
<< currentItemUrl
;
1153 // Save view position
1154 const qreal x
= m_container
->horizontalScrollBar()->value();
1155 const qreal y
= m_container
->verticalScrollBar()->value();
1156 stream
<< QPoint(x
, y
);
1158 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1159 stream
<< m_model
->expandedDirectories();
1162 KFileItem
DolphinView::rootItem() const
1164 return m_model
->rootItem();
1167 void DolphinView::setViewPropertiesContext(const QString
& context
)
1169 m_viewPropertiesContext
= context
;
1172 QString
DolphinView::viewPropertiesContext() const
1174 return m_viewPropertiesContext
;
1177 void DolphinView::observeCreatedItem(const KUrl
& url
)
1181 markUrlAsCurrent(url
);
1182 markUrlsAsSelected(QList
<KUrl
>() << url
);
1186 void DolphinView::slotDirectoryRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1188 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
1189 emit
redirection(oldUrl
, newUrl
);
1190 m_url
= newUrl
; // #186947
1194 void DolphinView::updateViewState()
1196 if (m_currentItemUrl
!= KUrl()) {
1197 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1198 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1199 if (currentIndex
!= -1) {
1200 selectionManager
->setCurrentItem(currentIndex
);
1202 // scroll to current item and reset the state
1203 if (m_scrollToCurrentItem
) {
1204 m_view
->scrollToItem(currentIndex
);
1205 m_scrollToCurrentItem
= false;
1208 selectionManager
->setCurrentItem(0);
1210 m_currentItemUrl
= KUrl();
1213 if (!m_restoredContentsPosition
.isNull()) {
1214 const int x
= m_restoredContentsPosition
.x();
1215 const int y
= m_restoredContentsPosition
.y();
1216 m_restoredContentsPosition
= QPoint();
1218 m_container
->horizontalScrollBar()->setValue(x
);
1219 m_container
->verticalScrollBar()->setValue(y
);
1222 if (!m_selectedUrls
.isEmpty()) {
1223 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1225 if (m_clearSelectionBeforeSelectingNewItems
) {
1226 selectionManager
->clearSelection();
1227 m_clearSelectionBeforeSelectingNewItems
= false;
1230 QSet
<int> selectedItems
= selectionManager
->selectedItems();
1232 QList
<KUrl
>::iterator it
= m_selectedUrls
.begin();
1233 while (it
!= m_selectedUrls
.end()) {
1234 const int index
= m_model
->index(*it
);
1236 selectedItems
.insert(index
);
1237 it
= m_selectedUrls
.erase(it
);
1243 selectionManager
->setSelectedItems(selectedItems
);
1247 void DolphinView::hideToolTip()
1249 if (GeneralSettings::showToolTips()) {
1250 m_toolTipManager
->hideToolTip();
1254 void DolphinView::calculateItemCount(int& fileCount
,
1256 KIO::filesize_t
& totalFileSize
) const
1258 const int itemCount
= m_model
->count();
1259 for (int i
= 0; i
< itemCount
; ++i
) {
1260 const KFileItem item
= m_model
->fileItem(i
);
1265 totalFileSize
+= item
.size();
1270 void DolphinView::showHoverInformation(const KFileItem
& item
)
1272 emit
requestItemInfo(item
);
1275 void DolphinView::clearHoverInformation()
1277 emit
requestItemInfo(KFileItem());
1280 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1282 if (job
->error() == 0) {
1283 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1284 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1285 emit
errorMessage(job
->errorString());
1289 void DolphinView::slotDirectoryLoadingStarted()
1291 // Disable the writestate temporary until it can be determined in a fast way
1292 // in DolphinView::slotLoadingCompleted()
1293 if (m_isFolderWritable
) {
1294 m_isFolderWritable
= false;
1295 emit
writeStateChanged(m_isFolderWritable
);
1298 emit
directoryLoadingStarted();
1301 void DolphinView::slotDirectoryLoadingCompleted()
1303 // Update the view-state. This has to be done asynchronously
1304 // because the view might not be in its final state yet.
1305 QTimer::singleShot(0, this, SLOT(updateViewState()));
1307 emit
directoryLoadingCompleted();
1309 updateWritableState();
1312 void DolphinView::slotItemsChanged()
1314 m_assureVisibleCurrentIndex
= false;
1317 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1320 Q_ASSERT(m_model
->sortOrder() == current
);
1322 ViewProperties
props(viewPropertiesUrl());
1323 props
.setSortOrder(current
);
1325 emit
sortOrderChanged(current
);
1328 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1331 Q_ASSERT(m_model
->sortRole() == current
);
1333 ViewProperties
props(viewPropertiesUrl());
1334 props
.setSortRole(current
);
1336 emit
sortRoleChanged(current
);
1339 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1340 const QList
<QByteArray
>& previous
)
1343 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1345 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1347 m_visibleRoles
= current
;
1349 ViewProperties
props(viewPropertiesUrl());
1350 props
.setVisibleRoles(m_visibleRoles
);
1352 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1355 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1357 if (index
< 0 || index
>= m_model
->count()) {
1361 if (role
== "text") {
1362 const KFileItem oldItem
= m_model
->fileItem(index
);
1363 const QString newName
= value
.toString();
1364 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1String(".") && newName
!= QLatin1String("..")) {
1365 const KUrl oldUrl
= oldItem
.url();
1367 const KUrl
newUrl(url().path(KUrl::AddTrailingSlash
) + newName
);
1368 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1369 if (!newNameExistsAlready
) {
1370 // Only change the data in the model if no item with the new name
1371 // is in the model yet. If there is an item with the new name
1372 // already, calling KonqOperations::rename() will open a dialog
1373 // asking for a new name, and KFileItemModel will update the
1374 // data when the dir lister signals that the file name has changed.
1375 QHash
<QByteArray
, QVariant
> data
;
1376 data
.insert(role
, value
);
1377 m_model
->setData(index
, data
);
1380 KonqOperations::rename(this, oldUrl
, newName
);
1385 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1387 if (!url
.isValid()) {
1388 const QString
location(url
.pathOrUrl());
1389 if (location
.isEmpty()) {
1390 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1392 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1398 m_model
->refreshDirectory(url
);
1400 m_model
->loadDirectory(url
);
1404 void DolphinView::applyViewProperties()
1406 m_view
->beginTransaction();
1408 const ViewProperties
props(viewPropertiesUrl());
1410 const Mode mode
= props
.viewMode();
1411 if (m_mode
!= mode
) {
1412 const Mode previousMode
= m_mode
;
1415 // Changing the mode might result in changing
1416 // the zoom level. Remember the old zoom level so
1417 // that zoomLevelChanged() can get emitted.
1418 const int oldZoomLevel
= m_view
->zoomLevel();
1421 emit
modeChanged(m_mode
, previousMode
);
1423 if (m_view
->zoomLevel() != oldZoomLevel
) {
1424 emit
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1428 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1429 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1430 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1431 emit
hiddenFilesShownChanged(hiddenFilesShown
);
1434 const bool groupedSorting
= props
.groupedSorting();
1435 if (groupedSorting
!= m_model
->groupedSorting()) {
1436 m_model
->setGroupedSorting(groupedSorting
);
1437 emit
groupedSortingChanged(groupedSorting
);
1440 const QByteArray sortRole
= props
.sortRole();
1441 if (sortRole
!= m_model
->sortRole()) {
1442 m_model
->setSortRole(sortRole
);
1443 emit
sortRoleChanged(sortRole
);
1446 const Qt::SortOrder sortOrder
= props
.sortOrder();
1447 if (sortOrder
!= m_model
->sortOrder()) {
1448 m_model
->setSortOrder(sortOrder
);
1449 emit
sortOrderChanged(sortOrder
);
1452 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1453 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1454 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1455 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1458 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1459 if (visibleRoles
!= m_visibleRoles
) {
1460 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1461 m_visibleRoles
= visibleRoles
;
1462 m_view
->setVisibleRoles(visibleRoles
);
1463 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1466 const bool previewsShown
= props
.previewsShown();
1467 if (previewsShown
!= m_view
->previewsShown()) {
1468 const int oldZoomLevel
= zoomLevel();
1470 m_view
->setPreviewsShown(previewsShown
);
1471 emit
previewsShownChanged(previewsShown
);
1473 // Changing the preview-state might result in a changed zoom-level
1474 if (oldZoomLevel
!= zoomLevel()) {
1475 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1479 KItemListView
* itemListView
= m_container
->controller()->view();
1480 if (itemListView
->isHeaderVisible()) {
1481 KItemListHeader
* header
= itemListView
->header();
1482 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
1483 const int rolesCount
= m_visibleRoles
.count();
1484 if (headerColumnWidths
.count() == rolesCount
) {
1485 header
->setAutomaticColumnResizing(false);
1487 QHash
<QByteArray
, qreal
> columnWidths
;
1488 for (int i
= 0; i
< rolesCount
; ++i
) {
1489 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
1491 header
->setColumnWidths(columnWidths
);
1493 header
->setAutomaticColumnResizing(true);
1497 m_view
->endTransaction();
1500 void DolphinView::applyModeToView()
1503 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
1504 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
1505 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1506 default: Q_ASSERT(false); break;
1510 void DolphinView::pasteToUrl(const KUrl
& url
)
1512 markPastedUrlsAsSelected(QApplication::clipboard()->mimeData());
1513 KonqOperations::doPaste(this, url
);
1516 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1520 const KFileItemList items
= selectedItems();
1521 foreach (const KFileItem
& item
, items
) {
1522 urls
.append(item
.url());
1525 if (itemsExpandable()) {
1526 // TODO: Check if we still need KDirModel for this in KDE 5.0
1527 urls
= KDirModel::simplifiedUrlList(urls
);
1533 QMimeData
* DolphinView::selectionMimeData() const
1535 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1536 const QSet
<int> selectedIndexes
= selectionManager
->selectedItems();
1538 return m_model
->createMimeData(selectedIndexes
);
1541 void DolphinView::markPastedUrlsAsSelected(const QMimeData
* mimeData
)
1543 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1544 KUrl::List destUrls
;
1545 foreach (const KUrl
& source
, sourceUrls
) {
1546 KUrl
destination(url().url() + '/' + source
.fileName());
1547 destUrls
<< destination
;
1549 markUrlsAsSelected(destUrls
);
1550 m_clearSelectionBeforeSelectingNewItems
= true;
1553 void DolphinView::updateWritableState()
1555 const bool wasFolderWritable
= m_isFolderWritable
;
1556 m_isFolderWritable
= true;
1558 const KFileItem item
= m_model
->rootItem();
1559 if (!item
.isNull()) {
1560 KFileItemListProperties
capabilities(KFileItemList() << item
);
1561 m_isFolderWritable
= capabilities
.supportsWriting();
1563 if (m_isFolderWritable
!= wasFolderWritable
) {
1564 emit
writeStateChanged(m_isFolderWritable
);
1568 KUrl
DolphinView::viewPropertiesUrl() const
1570 if (m_viewPropertiesContext
.isEmpty()) {
1575 url
.setProtocol(m_url
.protocol());
1576 url
.setPath(m_viewPropertiesContext
);
1580 #include "dolphinview.moc"