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 <Nepomuk2/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(directoryLoadingCanceled()), this, SIGNAL(directoryLoadingCanceled()));
159 connect(m_model
, SIGNAL(directoryLoadingProgress(int)), this, SIGNAL(directoryLoadingProgress(int)));
160 connect(m_model
, SIGNAL(directorySortingProgress(int)), this, SIGNAL(directorySortingProgress(int)));
161 connect(m_model
, SIGNAL(itemsChanged(KItemRangeList
,QSet
<QByteArray
>)),
162 this, SLOT(slotItemsChanged()));
163 connect(m_model
, SIGNAL(itemsRemoved(KItemRangeList
)), this, SIGNAL(itemCountChanged()));
164 connect(m_model
, SIGNAL(itemsInserted(KItemRangeList
)), this, SIGNAL(itemCountChanged()));
165 connect(m_model
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
166 connect(m_model
, SIGNAL(errorMessage(QString
)), this, SIGNAL(errorMessage(QString
)));
167 connect(m_model
, SIGNAL(directoryRedirection(KUrl
,KUrl
)), this, SLOT(slotDirectoryRedirection(KUrl
,KUrl
)));
168 connect(m_model
, SIGNAL(urlIsFileError(KUrl
)), this, SIGNAL(urlIsFileError(KUrl
)));
170 m_view
->installEventFilter(this);
171 connect(m_view
, SIGNAL(sortOrderChanged(Qt::SortOrder
,Qt::SortOrder
)),
172 this, SLOT(slotSortOrderChangedByHeader(Qt::SortOrder
,Qt::SortOrder
)));
173 connect(m_view
, SIGNAL(sortRoleChanged(QByteArray
,QByteArray
)),
174 this, SLOT(slotSortRoleChangedByHeader(QByteArray
,QByteArray
)));
175 connect(m_view
, SIGNAL(visibleRolesChanged(QList
<QByteArray
>,QList
<QByteArray
>)),
176 this, SLOT(slotVisibleRolesChangedByHeader(QList
<QByteArray
>,QList
<QByteArray
>)));
177 connect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
178 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
179 connect(m_view
->header(), SIGNAL(columnWidthChanged(QByteArray
,qreal
,qreal
)),
180 this, SLOT(slotHeaderColumnWidthChanged(QByteArray
,qreal
,qreal
)));
182 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
183 connect(selectionManager
, SIGNAL(selectionChanged(QSet
<int>,QSet
<int>)),
184 this, SLOT(slotSelectionChanged(QSet
<int>,QSet
<int>)));
186 m_toolTipManager
= new ToolTipManager(this);
188 m_versionControlObserver
= new VersionControlObserver(this);
189 m_versionControlObserver
->setModel(m_model
);
190 connect(m_versionControlObserver
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
191 connect(m_versionControlObserver
, SIGNAL(errorMessage(QString
)), this, SIGNAL(errorMessage(QString
)));
192 connect(m_versionControlObserver
, SIGNAL(operationCompletedMessage(QString
)), this, SIGNAL(operationCompletedMessage(QString
)));
194 applyViewProperties();
195 m_topLayout
->addWidget(m_container
);
200 DolphinView::~DolphinView()
204 KUrl
DolphinView::url() const
209 void DolphinView::setActive(bool active
)
211 if (active
== m_active
) {
217 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
222 QWidget
* viewport
= m_container
->viewport();
225 palette
.setColor(viewport
->backgroundRole(), color
);
226 viewport
->setPalette(palette
);
232 m_container
->setFocus();
234 emit
writeStateChanged(m_isFolderWritable
);
238 bool DolphinView::isActive() const
243 void DolphinView::setMode(Mode mode
)
245 if (mode
!= m_mode
) {
246 ViewProperties
props(viewPropertiesUrl());
247 props
.setViewMode(mode
);
250 applyViewProperties();
254 DolphinView::Mode
DolphinView::mode() const
259 void DolphinView::setPreviewsShown(bool show
)
261 if (previewsShown() == show
) {
265 ViewProperties
props(viewPropertiesUrl());
266 props
.setPreviewsShown(show
);
268 const int oldZoomLevel
= m_view
->zoomLevel();
269 m_view
->setPreviewsShown(show
);
270 emit
previewsShownChanged(show
);
272 const int newZoomLevel
= m_view
->zoomLevel();
273 if (newZoomLevel
!= oldZoomLevel
) {
274 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
278 bool DolphinView::previewsShown() const
280 return m_view
->previewsShown();
283 void DolphinView::setHiddenFilesShown(bool show
)
285 if (m_model
->showHiddenFiles() == show
) {
289 const KFileItemList itemList
= selectedItems();
290 m_selectedUrls
.clear();
291 m_selectedUrls
= itemList
.urlList();
293 ViewProperties
props(viewPropertiesUrl());
294 props
.setHiddenFilesShown(show
);
296 m_model
->setShowHiddenFiles(show
);
297 emit
hiddenFilesShownChanged(show
);
300 bool DolphinView::hiddenFilesShown() const
302 return m_model
->showHiddenFiles();
305 void DolphinView::setGroupedSorting(bool grouped
)
307 if (grouped
== groupedSorting()) {
311 ViewProperties
props(viewPropertiesUrl());
312 props
.setGroupedSorting(grouped
);
315 m_container
->controller()->model()->setGroupedSorting(grouped
);
317 emit
groupedSortingChanged(grouped
);
320 bool DolphinView::groupedSorting() const
322 return m_model
->groupedSorting();
325 KFileItemList
DolphinView::items() const
328 const int itemCount
= m_model
->count();
329 list
.reserve(itemCount
);
331 for (int i
= 0; i
< itemCount
; ++i
) {
332 list
.append(m_model
->fileItem(i
));
338 int DolphinView::itemsCount() const
340 return m_model
->count();
343 KFileItemList
DolphinView::selectedItems() const
345 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
346 const QSet
<int> selectedIndexes
= selectionManager
->selectedItems();
348 KFileItemList selectedItems
;
349 QSetIterator
<int> it(selectedIndexes
);
350 while (it
.hasNext()) {
351 const int index
= it
.next();
352 selectedItems
.append(m_model
->fileItem(index
));
354 return selectedItems
;
357 int DolphinView::selectedItemsCount() const
359 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
360 return selectionManager
->selectedItems().count();
363 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
365 m_selectedUrls
= urls
;
368 void DolphinView::markUrlAsCurrent(const KUrl
& url
)
370 m_currentItemUrl
= url
;
371 m_scrollToCurrentItem
= true;
374 void DolphinView::selectItems(const QRegExp
& pattern
, bool enabled
)
376 const KItemListSelectionManager::SelectionMode mode
= enabled
377 ? KItemListSelectionManager::Select
378 : KItemListSelectionManager::Deselect
;
379 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
381 for (int index
= 0; index
< m_model
->count(); index
++) {
382 const KFileItem item
= m_model
->fileItem(index
);
383 if (pattern
.exactMatch(item
.text())) {
384 // An alternative approach would be to store the matching items in a QSet<int> and
385 // select them in one go after the loop, but we'd need a new function
386 // KItemListSelectionManager::setSelected(QSet<int>, SelectionMode mode)
388 selectionManager
->setSelected(index
, 1, mode
);
393 void DolphinView::setZoomLevel(int level
)
395 const int oldZoomLevel
= zoomLevel();
396 m_view
->setZoomLevel(level
);
397 if (zoomLevel() != oldZoomLevel
) {
399 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
403 int DolphinView::zoomLevel() const
405 return m_view
->zoomLevel();
408 void DolphinView::setSortRole(const QByteArray
& role
)
410 if (role
!= sortRole()) {
411 updateSortRole(role
);
415 QByteArray
DolphinView::sortRole() const
417 const KItemModelBase
* model
= m_container
->controller()->model();
418 return model
->sortRole();
421 void DolphinView::setSortOrder(Qt::SortOrder order
)
423 if (sortOrder() != order
) {
424 updateSortOrder(order
);
428 Qt::SortOrder
DolphinView::sortOrder() const
430 return m_model
->sortOrder();
433 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
435 if (sortFoldersFirst() != foldersFirst
) {
436 updateSortFoldersFirst(foldersFirst
);
440 bool DolphinView::sortFoldersFirst() const
442 return m_model
->sortDirectoriesFirst();
445 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
447 const QList
<QByteArray
> previousRoles
= roles
;
449 ViewProperties
props(viewPropertiesUrl());
450 props
.setVisibleRoles(roles
);
452 m_visibleRoles
= roles
;
453 m_view
->setVisibleRoles(roles
);
455 emit
visibleRolesChanged(m_visibleRoles
, previousRoles
);
458 QList
<QByteArray
> DolphinView::visibleRoles() const
460 return m_visibleRoles
;
463 void DolphinView::reload()
465 QByteArray viewState
;
466 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
467 saveState(saveStream
);
469 const KFileItemList itemList
= selectedItems();
470 m_selectedUrls
.clear();
471 m_selectedUrls
= itemList
.urlList();
474 loadDirectory(url(), true);
476 QDataStream
restoreStream(viewState
);
477 restoreState(restoreStream
);
480 void DolphinView::stopLoading()
482 m_model
->cancelDirectoryLoading();
485 void DolphinView::readSettings()
487 const int oldZoomLevel
= m_view
->zoomLevel();
489 GeneralSettings::self()->readConfig();
490 m_view
->readSettings();
491 applyViewProperties();
493 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
494 m_container
->controller()->setAutoActivationDelay(delay
);
496 const int newZoomLevel
= m_view
->zoomLevel();
497 if (newZoomLevel
!= oldZoomLevel
) {
498 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
502 void DolphinView::writeSettings()
504 GeneralSettings::self()->writeConfig();
505 m_view
->writeSettings();
508 void DolphinView::setNameFilter(const QString
& nameFilter
)
510 m_model
->setNameFilter(nameFilter
);
513 QString
DolphinView::nameFilter() const
515 return m_model
->nameFilter();
518 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
520 return m_model
->setMimeTypeFilters(filters
);
523 QStringList
DolphinView::mimeTypeFilters() const
525 return m_model
->mimeTypeFilters();
528 QString
DolphinView::statusBarText() const
536 KIO::filesize_t totalFileSize
= 0;
538 if (m_container
->controller()->selectionManager()->hasSelection()) {
539 // Give a summary of the status of the selected files
540 const KFileItemList list
= selectedItems();
541 foreach (const KFileItem
& item
, list
) {
546 totalFileSize
+= item
.size();
550 if (folderCount
+ fileCount
== 1) {
551 // If only one item is selected, show the filename
552 filesText
= i18nc("@info:status", "<filename>%1</filename> selected", list
.first().text());
554 // At least 2 items are selected
555 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
556 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
559 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
560 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
561 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
564 if (fileCount
> 0 && folderCount
> 0) {
565 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
566 foldersText
, filesText
,
567 KGlobal::locale()->formatByteSize(totalFileSize
));
568 } else if (fileCount
> 0) {
569 summary
= i18nc("@info:status files (size)", "%1 (%2)",
571 KGlobal::locale()->formatByteSize(totalFileSize
));
572 } else if (folderCount
> 0) {
573 summary
= foldersText
;
575 summary
= i18nc("@info:status", "0 Folders, 0 Files");
581 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
583 QList
<QAction
*> actions
;
585 if (items
.isEmpty()) {
586 const KFileItem item
= m_model
->rootItem();
587 if (!item
.isNull()) {
588 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
591 actions
= m_versionControlObserver
->actions(items
);
597 void DolphinView::setUrl(const KUrl
& url
)
605 emit
urlAboutToBeChanged(url
);
610 // It is important to clear the items from the model before
611 // applying the view properties, otherwise expensive operations
612 // might be done on the existing items although they get cleared
613 // anyhow afterwards by loadDirectory().
615 applyViewProperties();
618 emit
urlChanged(url
);
621 void DolphinView::selectAll()
623 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
624 selectionManager
->setSelected(0, m_model
->count());
627 void DolphinView::invertSelection()
629 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
630 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
633 void DolphinView::clearSelection()
635 m_selectedUrls
.clear();
636 m_container
->controller()->selectionManager()->clearSelection();
639 void DolphinView::renameSelectedItems()
641 const KFileItemList items
= selectedItems();
642 if (items
.isEmpty()) {
646 if (items
.count() == 1 && GeneralSettings::renameInline()) {
647 const int index
= m_model
->index(items
.first());
648 m_view
->editRole(index
, "text");
650 RenameDialog
* dialog
= new RenameDialog(this, items
);
651 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
654 dialog
->activateWindow();
657 // Assure that the current index remains visible when KFileItemModel
658 // will notify the view about changed items (which might result in
659 // a changed sorting).
660 m_assureVisibleCurrentIndex
= true;
663 void DolphinView::trashSelectedItems()
665 const KUrl::List list
= simplifiedSelectedUrls();
666 KonqOperations::del(this, KonqOperations::TRASH
, list
);
669 void DolphinView::deleteSelectedItems()
671 const KUrl::List list
= simplifiedSelectedUrls();
672 const bool del
= KonqOperations::askDeleteConfirmation(list
,
674 KonqOperations::DEFAULT_CONFIRMATION
,
678 KIO::Job
* job
= KIO::del(list
);
680 job
->ui()->setWindow(this);
682 connect(job
, SIGNAL(result(KJob
*)),
683 this, SLOT(slotDeleteFileFinished(KJob
*)));
687 void DolphinView::cutSelectedItems()
689 QMimeData
* mimeData
= selectionMimeData();
690 KonqMimeData::addIsCutSelection(mimeData
, true);
691 QApplication::clipboard()->setMimeData(mimeData
);
694 void DolphinView::copySelectedItems()
696 QMimeData
* mimeData
= selectionMimeData();
697 QApplication::clipboard()->setMimeData(mimeData
);
700 void DolphinView::paste()
705 void DolphinView::pasteIntoFolder()
707 const KFileItemList items
= selectedItems();
708 if ((items
.count() == 1) && items
.first().isDir()) {
709 pasteToUrl(items
.first().url());
713 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
715 switch (event
->type()) {
716 case QEvent::FocusIn
:
717 if (watched
== m_container
) {
722 case QEvent::GraphicsSceneDragEnter
:
723 if (watched
== m_view
) {
728 case QEvent::GraphicsSceneDragLeave
:
729 if (watched
== m_view
) {
734 case QEvent::GraphicsSceneDrop
:
735 if (watched
== m_view
) {
742 return QWidget::eventFilter(watched
, event
);
745 void DolphinView::wheelEvent(QWheelEvent
* event
)
747 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
748 const int numDegrees
= event
->delta() / 8;
749 const int numSteps
= numDegrees
/ 15;
751 setZoomLevel(zoomLevel() + numSteps
);
758 void DolphinView::hideEvent(QHideEvent
* event
)
761 QWidget::hideEvent(event
);
764 bool DolphinView::event(QEvent
* event
)
767 * Dolphin leaves file preview tooltips open even when is not visible.
769 * Hide tool-tip when Dolphin loses focus.
771 if (event
->type() == QEvent::WindowDeactivate
) {
775 return QWidget::event(event
);
778 void DolphinView::activate()
783 void DolphinView::slotItemActivated(int index
)
785 const KFileItem item
= m_model
->fileItem(index
);
786 if (!item
.isNull()) {
787 emit
itemActivated(item
);
791 void DolphinView::slotItemsActivated(const QSet
<int>& indexes
)
793 Q_ASSERT(indexes
.count() >= 2);
795 if (indexes
.count() > 5) {
796 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
797 const int answer
= KMessageBox::warningYesNo(this, question
);
798 if (answer
!= KMessageBox::Yes
) {
804 items
.reserve(indexes
.count());
806 QSetIterator
<int> it(indexes
);
807 while (it
.hasNext()) {
808 const int index
= it
.next();
809 KFileItem item
= m_model
->fileItem(index
);
811 if (item
.isDir()) { // Open folders in new tabs
812 emit
tabRequested(item
.url());
818 if (items
.count() == 1) {
819 emit
itemActivated(items
.first());
820 } else if (items
.count() > 1) {
821 emit
itemsActivated(items
);
825 void DolphinView::slotItemMiddleClicked(int index
)
827 const KFileItem item
= m_model
->fileItem(index
);
828 if (item
.isDir() || isTabsForFilesEnabled()) {
829 emit
tabRequested(item
.url());
833 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
835 const KFileItem item
= m_model
->fileItem(index
);
836 emit
requestContextMenu(pos
.toPoint(), item
, url(), QList
<QAction
*>());
839 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
841 emit
requestContextMenu(pos
.toPoint(), KFileItem(), url(), QList
<QAction
*>());
844 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
846 ViewProperties
props(viewPropertiesUrl());
848 QPointer
<KMenu
> menu
= new KMenu(QApplication::activeWindow());
850 KItemListView
* view
= m_container
->controller()->view();
851 const QSet
<QByteArray
> visibleRolesSet
= view
->visibleRoles().toSet();
853 bool nepomukRunning
= false;
854 bool indexingEnabled
= false;
856 nepomukRunning
= (Nepomuk2::ResourceManager::instance()->initialized());
857 if (nepomukRunning
) {
858 KConfig
config("nepomukserverrc");
859 indexingEnabled
= config
.group("Service-nepomukfileindexer").readEntry("autostart", true);
864 QMenu
* groupMenu
= 0;
866 // Add all roles to the menu that can be shown or hidden by the user
867 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
868 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
869 if (info
.role
== "text") {
870 // It should not be possible to hide the "text" role
874 const QString text
= m_model
->roleDescription(info
.role
);
876 if (info
.group
.isEmpty()) {
877 action
= menu
->addAction(text
);
879 if (!groupMenu
|| info
.group
!= groupName
) {
880 groupName
= info
.group
;
881 groupMenu
= menu
->addMenu(groupName
);
884 action
= groupMenu
->addAction(text
);
887 action
->setCheckable(true);
888 action
->setChecked(visibleRolesSet
.contains(info
.role
));
889 action
->setData(info
.role
);
891 const bool enable
= (!info
.requiresNepomuk
&& !info
.requiresIndexer
) ||
892 (info
.requiresNepomuk
&& nepomukRunning
) ||
893 (info
.requiresIndexer
&& indexingEnabled
);
894 action
->setEnabled(enable
);
897 menu
->addSeparator();
899 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
900 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
902 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
903 autoAdjustWidthsAction
->setCheckable(true);
904 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
905 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
907 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
908 customWidthsAction
->setCheckable(true);
909 customWidthsAction
->setChecked(!autoColumnWidths
);
910 customWidthsAction
->setActionGroup(widthsGroup
);
912 QAction
* action
= menu
->exec(pos
.toPoint());
913 if (menu
&& action
) {
914 KItemListHeader
* header
= view
->header();
916 if (action
== autoAdjustWidthsAction
) {
917 // Clear the column-widths from the viewproperties and turn on
918 // the automatic resizing of the columns
919 props
.setHeaderColumnWidths(QList
<int>());
920 header
->setAutomaticColumnResizing(true);
921 } else if (action
== customWidthsAction
) {
922 // Apply the current column-widths as custom column-widths and turn
923 // off the automatic resizing of the columns
924 QList
<int> columnWidths
;
925 foreach (const QByteArray
& role
, view
->visibleRoles()) {
926 columnWidths
.append(header
->columnWidth(role
));
928 props
.setHeaderColumnWidths(columnWidths
);
929 header
->setAutomaticColumnResizing(false);
931 // Show or hide the selected role
932 const QByteArray selectedRole
= action
->data().toByteArray();
934 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
935 if (action
->isChecked()) {
936 visibleRoles
.append(selectedRole
);
938 visibleRoles
.removeOne(selectedRole
);
941 view
->setVisibleRoles(visibleRoles
);
942 props
.setVisibleRoles(visibleRoles
);
944 QList
<int> columnWidths
;
945 if (!header
->automaticColumnResizing()) {
946 foreach (const QByteArray
& role
, view
->visibleRoles()) {
947 columnWidths
.append(header
->columnWidth(role
));
950 props
.setHeaderColumnWidths(columnWidths
);
957 void DolphinView::slotHeaderColumnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
)
961 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
963 ViewProperties
props(viewPropertiesUrl());
964 QList
<int> columnWidths
= props
.headerColumnWidths();
965 if (columnWidths
.count() != visibleRoles
.count()) {
966 columnWidths
.clear();
967 columnWidths
.reserve(visibleRoles
.count());
968 const KItemListHeader
* header
= m_view
->header();
969 foreach (const QByteArray
& role
, visibleRoles
) {
970 const int width
= header
->columnWidth(role
);
971 columnWidths
.append(width
);
975 const int roleIndex
= visibleRoles
.indexOf(role
);
976 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
977 columnWidths
[roleIndex
] = current
;
979 props
.setHeaderColumnWidths(columnWidths
);
982 void DolphinView::slotItemHovered(int index
)
984 const KFileItem item
= m_model
->fileItem(index
);
986 if (GeneralSettings::showToolTips() && !m_dragging
) {
987 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
988 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
989 itemRect
.moveTo(pos
);
991 m_toolTipManager
->showToolTip(item
, itemRect
);
994 emit
requestItemInfo(item
);
997 void DolphinView::slotItemUnhovered(int index
)
1001 emit
requestItemInfo(KFileItem());
1004 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1007 KFileItem destItem
= m_model
->fileItem(index
);
1008 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1009 // Use the URL of the view as drop target if the item is no directory
1011 destItem
= m_model
->rootItem();
1014 // The item represents a directory or desktop-file
1015 destUrl
= destItem
.url();
1018 QDropEvent
dropEvent(event
->pos().toPoint(),
1019 event
->possibleActions(),
1022 event
->modifiers());
1024 const QString error
= DragAndDropHelper::dropUrls(destItem
, destUrl
, &dropEvent
);
1025 if (!error
.isEmpty()) {
1026 emit
errorMessage(error
);
1029 if (destUrl
== url()) {
1030 // Mark the dropped urls as selected.
1031 markPastedUrlsAsSelected(event
->mimeData());
1035 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1037 if (previous
!= 0) {
1038 disconnect(previous
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1039 m_versionControlObserver
->setModel(0);
1043 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1044 connect(current
, SIGNAL(loadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1046 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1047 m_versionControlObserver
->setModel(fileItemModel
);
1051 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1055 if (itemIndex
< 0) {
1056 // Trigger the history navigation only when clicking on the viewport:
1057 // Above an item the XButtons provide a simple way to select items in
1058 // the singleClick mode.
1059 if (buttons
& Qt::XButton1
) {
1060 emit
goBackRequested();
1061 } else if (buttons
& Qt::XButton2
) {
1062 emit
goForwardRequested();
1067 void DolphinView::slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
)
1069 const int currentCount
= current
.count();
1070 const int previousCount
= previous
.count();
1071 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1072 (currentCount
> 0 && previousCount
== 0);
1074 // If nothing has been selected before and something got selected (or if something
1075 // was selected before and now nothing is selected) the selectionChangedSignal must
1076 // be emitted asynchronously as fast as possible to update the edit-actions.
1077 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1078 m_selectionChangedTimer
->start();
1081 void DolphinView::emitSelectionChangedSignal()
1083 m_selectionChangedTimer
->stop();
1084 emit
selectionChanged(selectedItems());
1087 void DolphinView::updateSortRole(const QByteArray
& role
)
1089 ViewProperties
props(viewPropertiesUrl());
1090 props
.setSortRole(role
);
1092 KItemModelBase
* model
= m_container
->controller()->model();
1093 model
->setSortRole(role
);
1095 emit
sortRoleChanged(role
);
1098 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1100 ViewProperties
props(viewPropertiesUrl());
1101 props
.setSortOrder(order
);
1103 m_model
->setSortOrder(order
);
1105 emit
sortOrderChanged(order
);
1108 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1110 ViewProperties
props(viewPropertiesUrl());
1111 props
.setSortFoldersFirst(foldersFirst
);
1113 m_model
->setSortDirectoriesFirst(foldersFirst
);
1115 emit
sortFoldersFirstChanged(foldersFirst
);
1118 QPair
<bool, QString
> DolphinView::pasteInfo() const
1120 return KonqOperations::pasteInfo(url());
1123 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1125 m_tabsForFiles
= tabsForFiles
;
1128 bool DolphinView::isTabsForFilesEnabled() const
1130 return m_tabsForFiles
;
1133 bool DolphinView::itemsExpandable() const
1135 return m_mode
== DetailsView
;
1138 void DolphinView::restoreState(QDataStream
& stream
)
1140 // Restore the current item that had the keyboard focus
1141 stream
>> m_currentItemUrl
;
1143 // Restore the view position
1144 stream
>> m_restoredContentsPosition
;
1146 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1149 m_model
->restoreExpandedDirectories(urls
);
1152 void DolphinView::saveState(QDataStream
& stream
)
1154 // Save the current item that has the keyboard focus
1155 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1156 if (currentIndex
!= -1) {
1157 KFileItem item
= m_model
->fileItem(currentIndex
);
1158 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1159 KUrl currentItemUrl
= item
.url();
1160 stream
<< currentItemUrl
;
1165 // Save view position
1166 const qreal x
= m_container
->horizontalScrollBar()->value();
1167 const qreal y
= m_container
->verticalScrollBar()->value();
1168 stream
<< QPoint(x
, y
);
1170 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1171 stream
<< m_model
->expandedDirectories();
1174 KFileItem
DolphinView::rootItem() const
1176 return m_model
->rootItem();
1179 void DolphinView::setViewPropertiesContext(const QString
& context
)
1181 m_viewPropertiesContext
= context
;
1184 QString
DolphinView::viewPropertiesContext() const
1186 return m_viewPropertiesContext
;
1189 void DolphinView::observeCreatedItem(const KUrl
& url
)
1193 markUrlAsCurrent(url
);
1194 markUrlsAsSelected(QList
<KUrl
>() << url
);
1198 void DolphinView::slotDirectoryRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1200 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
1201 emit
redirection(oldUrl
, newUrl
);
1202 m_url
= newUrl
; // #186947
1206 void DolphinView::updateViewState()
1208 if (m_currentItemUrl
!= KUrl()) {
1209 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1210 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1211 if (currentIndex
!= -1) {
1212 selectionManager
->setCurrentItem(currentIndex
);
1214 // scroll to current item and reset the state
1215 if (m_scrollToCurrentItem
) {
1216 m_view
->scrollToItem(currentIndex
);
1217 m_scrollToCurrentItem
= false;
1220 selectionManager
->setCurrentItem(0);
1222 m_currentItemUrl
= KUrl();
1225 if (!m_restoredContentsPosition
.isNull()) {
1226 const int x
= m_restoredContentsPosition
.x();
1227 const int y
= m_restoredContentsPosition
.y();
1228 m_restoredContentsPosition
= QPoint();
1230 m_container
->horizontalScrollBar()->setValue(x
);
1231 m_container
->verticalScrollBar()->setValue(y
);
1234 if (!m_selectedUrls
.isEmpty()) {
1235 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1237 if (m_clearSelectionBeforeSelectingNewItems
) {
1238 selectionManager
->clearSelection();
1239 m_clearSelectionBeforeSelectingNewItems
= false;
1242 QSet
<int> selectedItems
= selectionManager
->selectedItems();
1244 QList
<KUrl
>::iterator it
= m_selectedUrls
.begin();
1245 while (it
!= m_selectedUrls
.end()) {
1246 const int index
= m_model
->index(*it
);
1248 selectedItems
.insert(index
);
1249 it
= m_selectedUrls
.erase(it
);
1255 selectionManager
->setSelectedItems(selectedItems
);
1259 void DolphinView::hideToolTip()
1261 if (GeneralSettings::showToolTips()) {
1262 m_toolTipManager
->hideToolTip();
1266 void DolphinView::calculateItemCount(int& fileCount
,
1268 KIO::filesize_t
& totalFileSize
) const
1270 const int itemCount
= m_model
->count();
1271 for (int i
= 0; i
< itemCount
; ++i
) {
1272 const KFileItem item
= m_model
->fileItem(i
);
1277 totalFileSize
+= item
.size();
1282 void DolphinView::showHoverInformation(const KFileItem
& item
)
1284 emit
requestItemInfo(item
);
1287 void DolphinView::clearHoverInformation()
1289 emit
requestItemInfo(KFileItem());
1292 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1294 if (job
->error() == 0) {
1295 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1296 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1297 emit
errorMessage(job
->errorString());
1301 void DolphinView::slotDirectoryLoadingStarted()
1303 // Disable the writestate temporary until it can be determined in a fast way
1304 // in DolphinView::slotLoadingCompleted()
1305 if (m_isFolderWritable
) {
1306 m_isFolderWritable
= false;
1307 emit
writeStateChanged(m_isFolderWritable
);
1310 emit
directoryLoadingStarted();
1313 void DolphinView::slotDirectoryLoadingCompleted()
1315 // Update the view-state. This has to be done asynchronously
1316 // because the view might not be in its final state yet.
1317 QTimer::singleShot(0, this, SLOT(updateViewState()));
1319 emit
directoryLoadingCompleted();
1321 updateWritableState();
1324 void DolphinView::slotItemsChanged()
1326 m_assureVisibleCurrentIndex
= false;
1329 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1332 Q_ASSERT(m_model
->sortOrder() == current
);
1334 ViewProperties
props(viewPropertiesUrl());
1335 props
.setSortOrder(current
);
1337 emit
sortOrderChanged(current
);
1340 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1343 Q_ASSERT(m_model
->sortRole() == current
);
1345 ViewProperties
props(viewPropertiesUrl());
1346 props
.setSortRole(current
);
1348 emit
sortRoleChanged(current
);
1351 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1352 const QList
<QByteArray
>& previous
)
1355 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1357 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1359 m_visibleRoles
= current
;
1361 ViewProperties
props(viewPropertiesUrl());
1362 props
.setVisibleRoles(m_visibleRoles
);
1364 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1367 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1369 if (index
< 0 || index
>= m_model
->count()) {
1373 if (role
== "text") {
1374 const KFileItem oldItem
= m_model
->fileItem(index
);
1375 const QString newName
= value
.toString();
1376 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1String(".") && newName
!= QLatin1String("..")) {
1377 const KUrl oldUrl
= oldItem
.url();
1379 const KUrl
newUrl(url().path(KUrl::AddTrailingSlash
) + newName
);
1380 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1381 if (!newNameExistsAlready
) {
1382 // Only change the data in the model if no item with the new name
1383 // is in the model yet. If there is an item with the new name
1384 // already, calling KonqOperations::rename() will open a dialog
1385 // asking for a new name, and KFileItemModel will update the
1386 // data when the dir lister signals that the file name has changed.
1387 QHash
<QByteArray
, QVariant
> data
;
1388 data
.insert(role
, value
);
1389 m_model
->setData(index
, data
);
1392 KonqOperations::rename(this, oldUrl
, newName
);
1397 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1399 if (!url
.isValid()) {
1400 const QString
location(url
.pathOrUrl());
1401 if (location
.isEmpty()) {
1402 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1404 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1410 m_model
->refreshDirectory(url
);
1412 m_model
->loadDirectory(url
);
1416 void DolphinView::applyViewProperties()
1418 m_view
->beginTransaction();
1420 const ViewProperties
props(viewPropertiesUrl());
1422 const Mode mode
= props
.viewMode();
1423 if (m_mode
!= mode
) {
1424 const Mode previousMode
= m_mode
;
1427 // Changing the mode might result in changing
1428 // the zoom level. Remember the old zoom level so
1429 // that zoomLevelChanged() can get emitted.
1430 const int oldZoomLevel
= m_view
->zoomLevel();
1433 emit
modeChanged(m_mode
, previousMode
);
1435 if (m_view
->zoomLevel() != oldZoomLevel
) {
1436 emit
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1440 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1441 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1442 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1443 emit
hiddenFilesShownChanged(hiddenFilesShown
);
1446 const bool groupedSorting
= props
.groupedSorting();
1447 if (groupedSorting
!= m_model
->groupedSorting()) {
1448 m_model
->setGroupedSorting(groupedSorting
);
1449 emit
groupedSortingChanged(groupedSorting
);
1452 const QByteArray sortRole
= props
.sortRole();
1453 if (sortRole
!= m_model
->sortRole()) {
1454 m_model
->setSortRole(sortRole
);
1455 emit
sortRoleChanged(sortRole
);
1458 const Qt::SortOrder sortOrder
= props
.sortOrder();
1459 if (sortOrder
!= m_model
->sortOrder()) {
1460 m_model
->setSortOrder(sortOrder
);
1461 emit
sortOrderChanged(sortOrder
);
1464 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1465 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1466 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1467 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1470 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1471 if (visibleRoles
!= m_visibleRoles
) {
1472 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1473 m_visibleRoles
= visibleRoles
;
1474 m_view
->setVisibleRoles(visibleRoles
);
1475 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1478 const bool previewsShown
= props
.previewsShown();
1479 if (previewsShown
!= m_view
->previewsShown()) {
1480 const int oldZoomLevel
= zoomLevel();
1482 m_view
->setPreviewsShown(previewsShown
);
1483 emit
previewsShownChanged(previewsShown
);
1485 // Changing the preview-state might result in a changed zoom-level
1486 if (oldZoomLevel
!= zoomLevel()) {
1487 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1491 KItemListView
* itemListView
= m_container
->controller()->view();
1492 if (itemListView
->isHeaderVisible()) {
1493 KItemListHeader
* header
= itemListView
->header();
1494 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
1495 const int rolesCount
= m_visibleRoles
.count();
1496 if (headerColumnWidths
.count() == rolesCount
) {
1497 header
->setAutomaticColumnResizing(false);
1499 QHash
<QByteArray
, qreal
> columnWidths
;
1500 for (int i
= 0; i
< rolesCount
; ++i
) {
1501 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
1503 header
->setColumnWidths(columnWidths
);
1505 header
->setAutomaticColumnResizing(true);
1509 m_view
->endTransaction();
1512 void DolphinView::applyModeToView()
1515 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
1516 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
1517 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1518 default: Q_ASSERT(false); break;
1522 void DolphinView::pasteToUrl(const KUrl
& url
)
1524 markPastedUrlsAsSelected(QApplication::clipboard()->mimeData());
1525 KonqOperations::doPaste(this, url
);
1528 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1532 const KFileItemList items
= selectedItems();
1533 foreach (const KFileItem
& item
, items
) {
1534 urls
.append(item
.url());
1537 if (itemsExpandable()) {
1538 // TODO: Check if we still need KDirModel for this in KDE 5.0
1539 urls
= KDirModel::simplifiedUrlList(urls
);
1545 QMimeData
* DolphinView::selectionMimeData() const
1547 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1548 const QSet
<int> selectedIndexes
= selectionManager
->selectedItems();
1550 return m_model
->createMimeData(selectedIndexes
);
1553 void DolphinView::markPastedUrlsAsSelected(const QMimeData
* mimeData
)
1555 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1556 KUrl::List destUrls
;
1557 foreach (const KUrl
& source
, sourceUrls
) {
1558 KUrl
destination(url().url() + '/' + source
.fileName());
1559 destUrls
<< destination
;
1561 markUrlsAsSelected(destUrls
);
1562 m_clearSelectionBeforeSelectingNewItems
= true;
1565 void DolphinView::updateWritableState()
1567 const bool wasFolderWritable
= m_isFolderWritable
;
1568 m_isFolderWritable
= true;
1570 const KFileItem item
= m_model
->rootItem();
1571 if (!item
.isNull()) {
1572 KFileItemListProperties
capabilities(KFileItemList() << item
);
1573 m_isFolderWritable
= capabilities
.supportsWriting();
1575 if (m_isFolderWritable
!= wasFolderWritable
) {
1576 emit
writeStateChanged(m_isFolderWritable
);
1580 KUrl
DolphinView::viewPropertiesUrl() const
1582 if (m_viewPropertiesContext
.isEmpty()) {
1587 url
.setProtocol(m_url
.protocol());
1588 url
.setPath(m_viewPropertiesContext
);
1592 #include "dolphinview.moc"