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 const QSet
<int> selectedIndexes
= selectionManager
->selectedItems();
347 KFileItemList selectedItems
;
348 QSetIterator
<int> it(selectedIndexes
);
349 while (it
.hasNext()) {
350 const int index
= it
.next();
351 selectedItems
.append(m_model
->fileItem(index
));
353 return selectedItems
;
356 int DolphinView::selectedItemsCount() const
358 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
359 return selectionManager
->selectedItems().count();
362 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
364 m_selectedUrls
= urls
;
367 void DolphinView::markUrlAsCurrent(const KUrl
& url
)
369 m_currentItemUrl
= url
;
370 m_scrollToCurrentItem
= true;
373 void DolphinView::selectItems(const QRegExp
& pattern
, bool enabled
)
375 const KItemListSelectionManager::SelectionMode mode
= enabled
376 ? KItemListSelectionManager::Select
377 : KItemListSelectionManager::Deselect
;
378 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
380 for (int index
= 0; index
< m_model
->count(); index
++) {
381 const KFileItem item
= m_model
->fileItem(index
);
382 if (pattern
.exactMatch(item
.text())) {
383 // An alternative approach would be to store the matching items in a QSet<int> and
384 // select them in one go after the loop, but we'd need a new function
385 // KItemListSelectionManager::setSelected(QSet<int>, SelectionMode mode)
387 selectionManager
->setSelected(index
, 1, mode
);
392 void DolphinView::setZoomLevel(int level
)
394 const int oldZoomLevel
= zoomLevel();
395 m_view
->setZoomLevel(level
);
396 if (zoomLevel() != oldZoomLevel
) {
398 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
402 int DolphinView::zoomLevel() const
404 return m_view
->zoomLevel();
407 void DolphinView::setSortRole(const QByteArray
& role
)
409 if (role
!= sortRole()) {
410 updateSortRole(role
);
414 QByteArray
DolphinView::sortRole() const
416 const KItemModelBase
* model
= m_container
->controller()->model();
417 return model
->sortRole();
420 void DolphinView::setSortOrder(Qt::SortOrder order
)
422 if (sortOrder() != order
) {
423 updateSortOrder(order
);
427 Qt::SortOrder
DolphinView::sortOrder() const
429 return m_model
->sortOrder();
432 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
434 if (sortFoldersFirst() != foldersFirst
) {
435 updateSortFoldersFirst(foldersFirst
);
439 bool DolphinView::sortFoldersFirst() const
441 return m_model
->sortDirectoriesFirst();
444 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
446 const QList
<QByteArray
> previousRoles
= roles
;
448 ViewProperties
props(viewPropertiesUrl());
449 props
.setVisibleRoles(roles
);
451 m_visibleRoles
= roles
;
452 m_view
->setVisibleRoles(roles
);
454 emit
visibleRolesChanged(m_visibleRoles
, previousRoles
);
457 QList
<QByteArray
> DolphinView::visibleRoles() const
459 return m_visibleRoles
;
462 void DolphinView::reload()
464 QByteArray viewState
;
465 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
466 saveState(saveStream
);
468 const KFileItemList itemList
= selectedItems();
469 m_selectedUrls
.clear();
470 m_selectedUrls
= itemList
.urlList();
473 loadDirectory(url(), true);
475 QDataStream
restoreStream(viewState
);
476 restoreState(restoreStream
);
479 void DolphinView::stopLoading()
481 m_model
->cancelDirectoryLoading();
484 void DolphinView::readSettings()
486 const int oldZoomLevel
= m_view
->zoomLevel();
488 GeneralSettings::self()->readConfig();
489 m_view
->readSettings();
490 applyViewProperties();
492 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
493 m_container
->controller()->setAutoActivationDelay(delay
);
495 const int newZoomLevel
= m_view
->zoomLevel();
496 if (newZoomLevel
!= oldZoomLevel
) {
497 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
501 void DolphinView::writeSettings()
503 GeneralSettings::self()->writeConfig();
504 m_view
->writeSettings();
507 void DolphinView::setNameFilter(const QString
& nameFilter
)
509 m_model
->setNameFilter(nameFilter
);
512 QString
DolphinView::nameFilter() const
514 return m_model
->nameFilter();
517 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
519 return m_model
->setMimeTypeFilters(filters
);
522 QStringList
DolphinView::mimeTypeFilters() const
524 return m_model
->mimeTypeFilters();
527 QString
DolphinView::statusBarText() const
535 KIO::filesize_t totalFileSize
= 0;
537 if (m_container
->controller()->selectionManager()->hasSelection()) {
538 // Give a summary of the status of the selected files
539 const KFileItemList list
= selectedItems();
540 foreach (const KFileItem
& item
, list
) {
545 totalFileSize
+= item
.size();
549 if (folderCount
+ fileCount
== 1) {
550 // If only one item is selected, show the filename
551 filesText
= i18nc("@info:status", "<filename>%1</filename> selected", list
.first().text());
553 // At least 2 items are selected
554 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
555 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
558 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
559 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
560 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
563 if (fileCount
> 0 && folderCount
> 0) {
564 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
565 foldersText
, filesText
,
566 KGlobal::locale()->formatByteSize(totalFileSize
));
567 } else if (fileCount
> 0) {
568 summary
= i18nc("@info:status files (size)", "%1 (%2)",
570 KGlobal::locale()->formatByteSize(totalFileSize
));
571 } else if (folderCount
> 0) {
572 summary
= foldersText
;
574 summary
= i18nc("@info:status", "0 Folders, 0 Files");
580 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
582 QList
<QAction
*> actions
;
584 if (items
.isEmpty()) {
585 const KFileItem item
= m_model
->rootItem();
586 if (!item
.isNull()) {
587 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
590 actions
= m_versionControlObserver
->actions(items
);
596 void DolphinView::setUrl(const KUrl
& url
)
604 emit
urlAboutToBeChanged(url
);
609 // It is important to clear the items from the model before
610 // applying the view properties, otherwise expensive operations
611 // might be done on the existing items although they get cleared
612 // anyhow afterwards by loadDirectory().
614 applyViewProperties();
617 emit
urlChanged(url
);
620 void DolphinView::selectAll()
622 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
623 selectionManager
->setSelected(0, m_model
->count());
626 void DolphinView::invertSelection()
628 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
629 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
632 void DolphinView::clearSelection()
634 m_selectedUrls
.clear();
635 m_container
->controller()->selectionManager()->clearSelection();
638 void DolphinView::renameSelectedItems()
640 const KFileItemList items
= selectedItems();
641 if (items
.isEmpty()) {
645 if (items
.count() == 1 && GeneralSettings::renameInline()) {
646 const int index
= m_model
->index(items
.first());
647 m_view
->editRole(index
, "text");
649 RenameDialog
* dialog
= new RenameDialog(this, items
);
650 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
653 dialog
->activateWindow();
656 // Assure that the current index remains visible when KFileItemModel
657 // will notify the view about changed items (which might result in
658 // a changed sorting).
659 m_assureVisibleCurrentIndex
= true;
662 void DolphinView::trashSelectedItems()
664 const KUrl::List list
= simplifiedSelectedUrls();
665 KonqOperations::del(this, KonqOperations::TRASH
, list
);
668 void DolphinView::deleteSelectedItems()
670 const KUrl::List list
= simplifiedSelectedUrls();
671 const bool del
= KonqOperations::askDeleteConfirmation(list
,
673 KonqOperations::DEFAULT_CONFIRMATION
,
677 KIO::Job
* job
= KIO::del(list
);
679 job
->ui()->setWindow(this);
681 connect(job
, SIGNAL(result(KJob
*)),
682 this, SLOT(slotDeleteFileFinished(KJob
*)));
686 void DolphinView::cutSelectedItems()
688 QMimeData
* mimeData
= selectionMimeData();
689 KonqMimeData::addIsCutSelection(mimeData
, true);
690 QApplication::clipboard()->setMimeData(mimeData
);
693 void DolphinView::copySelectedItems()
695 QMimeData
* mimeData
= selectionMimeData();
696 QApplication::clipboard()->setMimeData(mimeData
);
699 void DolphinView::paste()
704 void DolphinView::pasteIntoFolder()
706 const KFileItemList items
= selectedItems();
707 if ((items
.count() == 1) && items
.first().isDir()) {
708 pasteToUrl(items
.first().url());
712 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
714 switch (event
->type()) {
715 case QEvent::FocusIn
:
716 if (watched
== m_container
) {
721 case QEvent::GraphicsSceneDragEnter
:
722 if (watched
== m_view
) {
727 case QEvent::GraphicsSceneDragLeave
:
728 if (watched
== m_view
) {
733 case QEvent::GraphicsSceneDrop
:
734 if (watched
== m_view
) {
741 return QWidget::eventFilter(watched
, event
);
744 void DolphinView::wheelEvent(QWheelEvent
* event
)
746 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
747 const int numDegrees
= event
->delta() / 8;
748 const int numSteps
= numDegrees
/ 15;
750 setZoomLevel(zoomLevel() + numSteps
);
757 void DolphinView::hideEvent(QHideEvent
* event
)
760 QWidget::hideEvent(event
);
763 bool DolphinView::event(QEvent
* event
)
766 * Dolphin leaves file preview tooltips open even when is not visible.
768 * Hide tool-tip when Dolphin loses focus.
770 if (event
->type() == QEvent::WindowDeactivate
) {
774 return QWidget::event(event
);
777 void DolphinView::activate()
782 void DolphinView::slotItemActivated(int index
)
784 const KFileItem item
= m_model
->fileItem(index
);
785 if (!item
.isNull()) {
786 emit
itemActivated(item
);
790 void DolphinView::slotItemsActivated(const QSet
<int>& indexes
)
792 Q_ASSERT(indexes
.count() >= 2);
796 QSetIterator
<int> it(indexes
);
797 while (it
.hasNext()) {
798 const int index
= it
.next();
799 items
.append(m_model
->fileItem(index
));
802 foreach (const KFileItem
& item
, items
) {
804 emit
tabRequested(item
.url());
806 emit
itemActivated(item
);
811 void DolphinView::slotItemMiddleClicked(int index
)
813 const KFileItem item
= m_model
->fileItem(index
);
814 if (item
.isDir() || isTabsForFilesEnabled()) {
815 emit
tabRequested(item
.url());
819 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
821 const KFileItem item
= m_model
->fileItem(index
);
822 emit
requestContextMenu(pos
.toPoint(), item
, url(), QList
<QAction
*>());
825 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
827 emit
requestContextMenu(pos
.toPoint(), KFileItem(), url(), QList
<QAction
*>());
830 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
832 ViewProperties
props(viewPropertiesUrl());
834 QPointer
<KMenu
> menu
= new KMenu(QApplication::activeWindow());
836 KItemListView
* view
= m_container
->controller()->view();
837 const QSet
<QByteArray
> visibleRolesSet
= view
->visibleRoles().toSet();
839 bool nepomukRunning
= false;
840 bool indexingEnabled
= false;
842 nepomukRunning
= (Nepomuk::ResourceManager::instance()->initialized());
843 if (nepomukRunning
) {
844 KConfig
config("nepomukserverrc");
845 indexingEnabled
= config
.group("Service-nepomukfileindexer").readEntry("autostart", false);
850 QMenu
* groupMenu
= 0;
852 // Add all roles to the menu that can be shown or hidden by the user
853 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
854 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
855 if (info
.role
== "text") {
856 // It should not be possible to hide the "text" role
860 const QString text
= m_model
->roleDescription(info
.role
);
862 if (info
.group
.isEmpty()) {
863 action
= menu
->addAction(text
);
865 if (!groupMenu
|| info
.group
!= groupName
) {
866 groupName
= info
.group
;
867 groupMenu
= menu
->addMenu(groupName
);
870 action
= groupMenu
->addAction(text
);
873 action
->setCheckable(true);
874 action
->setChecked(visibleRolesSet
.contains(info
.role
));
875 action
->setData(info
.role
);
877 const bool enable
= (!info
.requiresNepomuk
&& !info
.requiresIndexer
) ||
878 (info
.requiresNepomuk
&& nepomukRunning
) ||
879 (info
.requiresIndexer
&& indexingEnabled
);
880 action
->setEnabled(enable
);
883 menu
->addSeparator();
885 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
886 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
888 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
889 autoAdjustWidthsAction
->setCheckable(true);
890 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
891 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
893 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
894 customWidthsAction
->setCheckable(true);
895 customWidthsAction
->setChecked(!autoColumnWidths
);
896 customWidthsAction
->setActionGroup(widthsGroup
);
898 QAction
* action
= menu
->exec(pos
.toPoint());
899 if (menu
&& action
) {
900 KItemListHeader
* header
= view
->header();
902 if (action
== autoAdjustWidthsAction
) {
903 // Clear the column-widths from the viewproperties and turn on
904 // the automatic resizing of the columns
905 props
.setHeaderColumnWidths(QList
<int>());
906 header
->setAutomaticColumnResizing(true);
907 } else if (action
== customWidthsAction
) {
908 // Apply the current column-widths as custom column-widths and turn
909 // off the automatic resizing of the columns
910 QList
<int> columnWidths
;
911 foreach (const QByteArray
& role
, view
->visibleRoles()) {
912 columnWidths
.append(header
->columnWidth(role
));
914 props
.setHeaderColumnWidths(columnWidths
);
915 header
->setAutomaticColumnResizing(false);
917 // Show or hide the selected role
918 const QByteArray selectedRole
= action
->data().toByteArray();
920 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
921 if (action
->isChecked()) {
922 visibleRoles
.append(selectedRole
);
924 visibleRoles
.removeOne(selectedRole
);
927 view
->setVisibleRoles(visibleRoles
);
928 props
.setVisibleRoles(visibleRoles
);
930 QList
<int> columnWidths
;
931 if (!header
->automaticColumnResizing()) {
932 foreach (const QByteArray
& role
, view
->visibleRoles()) {
933 columnWidths
.append(header
->columnWidth(role
));
936 props
.setHeaderColumnWidths(columnWidths
);
943 void DolphinView::slotHeaderColumnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
)
947 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
949 ViewProperties
props(viewPropertiesUrl());
950 QList
<int> columnWidths
= props
.headerColumnWidths();
951 if (columnWidths
.count() != visibleRoles
.count()) {
952 columnWidths
.clear();
953 columnWidths
.reserve(visibleRoles
.count());
954 const KItemListHeader
* header
= m_view
->header();
955 foreach (const QByteArray
& role
, visibleRoles
) {
956 const int width
= header
->columnWidth(role
);
957 columnWidths
.append(width
);
961 const int roleIndex
= visibleRoles
.indexOf(role
);
962 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
963 columnWidths
[roleIndex
] = current
;
965 props
.setHeaderColumnWidths(columnWidths
);
968 void DolphinView::slotItemHovered(int index
)
970 const KFileItem item
= m_model
->fileItem(index
);
972 if (GeneralSettings::showToolTips() && !m_dragging
) {
973 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
974 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
975 itemRect
.moveTo(pos
);
977 m_toolTipManager
->showToolTip(item
, itemRect
);
980 emit
requestItemInfo(item
);
983 void DolphinView::slotItemUnhovered(int index
)
987 emit
requestItemInfo(KFileItem());
990 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
993 KFileItem destItem
= m_model
->fileItem(index
);
994 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
995 // Use the URL of the view as drop target if the item is no directory
997 destItem
= m_model
->rootItem();
1000 // The item represents a directory or desktop-file
1001 destUrl
= destItem
.url();
1004 QDropEvent
dropEvent(event
->pos().toPoint(),
1005 event
->possibleActions(),
1008 event
->modifiers());
1010 const QString error
= DragAndDropHelper::dropUrls(destItem
, destUrl
, &dropEvent
);
1011 if (!error
.isEmpty()) {
1012 emit
errorMessage(error
);
1015 if (destUrl
== url()) {
1016 // Mark the dropped urls as selected.
1017 markPastedUrlsAsSelected(event
->mimeData());
1021 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1023 if (previous
!= 0) {
1024 disconnect(previous
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1025 m_versionControlObserver
->setModel(0);
1029 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1030 connect(current
, SIGNAL(loadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1032 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1033 m_versionControlObserver
->setModel(fileItemModel
);
1037 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1041 if (itemIndex
< 0) {
1042 // Trigger the history navigation only when clicking on the viewport:
1043 // Above an item the XButtons provide a simple way to select items in
1044 // the singleClick mode.
1045 if (buttons
& Qt::XButton1
) {
1046 emit
goBackRequested();
1047 } else if (buttons
& Qt::XButton2
) {
1048 emit
goForwardRequested();
1053 void DolphinView::slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
)
1055 const int currentCount
= current
.count();
1056 const int previousCount
= previous
.count();
1057 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1058 (currentCount
> 0 && previousCount
== 0);
1060 // If nothing has been selected before and something got selected (or if something
1061 // was selected before and now nothing is selected) the selectionChangedSignal must
1062 // be emitted asynchronously as fast as possible to update the edit-actions.
1063 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1064 m_selectionChangedTimer
->start();
1067 void DolphinView::emitSelectionChangedSignal()
1069 m_selectionChangedTimer
->stop();
1070 emit
selectionChanged(selectedItems());
1073 void DolphinView::updateSortRole(const QByteArray
& role
)
1075 ViewProperties
props(viewPropertiesUrl());
1076 props
.setSortRole(role
);
1078 KItemModelBase
* model
= m_container
->controller()->model();
1079 model
->setSortRole(role
);
1081 emit
sortRoleChanged(role
);
1084 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1086 ViewProperties
props(viewPropertiesUrl());
1087 props
.setSortOrder(order
);
1089 m_model
->setSortOrder(order
);
1091 emit
sortOrderChanged(order
);
1094 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1096 ViewProperties
props(viewPropertiesUrl());
1097 props
.setSortFoldersFirst(foldersFirst
);
1099 m_model
->setSortDirectoriesFirst(foldersFirst
);
1101 emit
sortFoldersFirstChanged(foldersFirst
);
1104 QPair
<bool, QString
> DolphinView::pasteInfo() const
1106 return KonqOperations::pasteInfo(url());
1109 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1111 m_tabsForFiles
= tabsForFiles
;
1114 bool DolphinView::isTabsForFilesEnabled() const
1116 return m_tabsForFiles
;
1119 bool DolphinView::itemsExpandable() const
1121 return m_mode
== DetailsView
;
1124 void DolphinView::restoreState(QDataStream
& stream
)
1126 // Restore the current item that had the keyboard focus
1127 stream
>> m_currentItemUrl
;
1129 // Restore the view position
1130 stream
>> m_restoredContentsPosition
;
1132 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1135 m_model
->restoreExpandedDirectories(urls
);
1138 void DolphinView::saveState(QDataStream
& stream
)
1140 // Save the current item that has the keyboard focus
1141 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1142 if (currentIndex
!= -1) {
1143 KFileItem item
= m_model
->fileItem(currentIndex
);
1144 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1145 KUrl currentItemUrl
= item
.url();
1146 stream
<< currentItemUrl
;
1151 // Save view position
1152 const qreal x
= m_container
->horizontalScrollBar()->value();
1153 const qreal y
= m_container
->verticalScrollBar()->value();
1154 stream
<< QPoint(x
, y
);
1156 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1157 stream
<< m_model
->expandedDirectories();
1160 KFileItem
DolphinView::rootItem() const
1162 return m_model
->rootItem();
1165 void DolphinView::setViewPropertiesContext(const QString
& context
)
1167 m_viewPropertiesContext
= context
;
1170 QString
DolphinView::viewPropertiesContext() const
1172 return m_viewPropertiesContext
;
1175 void DolphinView::observeCreatedItem(const KUrl
& url
)
1179 markUrlAsCurrent(url
);
1180 markUrlsAsSelected(QList
<KUrl
>() << url
);
1184 void DolphinView::slotDirectoryRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1186 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
1187 emit
redirection(oldUrl
, newUrl
);
1188 m_url
= newUrl
; // #186947
1192 void DolphinView::updateViewState()
1194 if (m_currentItemUrl
!= KUrl()) {
1195 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1196 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1197 if (currentIndex
!= -1) {
1198 selectionManager
->setCurrentItem(currentIndex
);
1200 // scroll to current item and reset the state
1201 if (m_scrollToCurrentItem
) {
1202 m_view
->scrollToItem(currentIndex
);
1203 m_scrollToCurrentItem
= false;
1206 selectionManager
->setCurrentItem(0);
1208 m_currentItemUrl
= KUrl();
1211 if (!m_restoredContentsPosition
.isNull()) {
1212 const int x
= m_restoredContentsPosition
.x();
1213 const int y
= m_restoredContentsPosition
.y();
1214 m_restoredContentsPosition
= QPoint();
1216 m_container
->horizontalScrollBar()->setValue(x
);
1217 m_container
->verticalScrollBar()->setValue(y
);
1220 if (!m_selectedUrls
.isEmpty()) {
1221 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1223 if (m_clearSelectionBeforeSelectingNewItems
) {
1224 selectionManager
->clearSelection();
1225 m_clearSelectionBeforeSelectingNewItems
= false;
1228 QSet
<int> selectedItems
= selectionManager
->selectedItems();
1230 for (QList
<KUrl
>::iterator it
= m_selectedUrls
.begin(); it
!= m_selectedUrls
.end(); ++it
) {
1231 const int index
= m_model
->index(*it
);
1233 selectedItems
.insert(index
);
1234 m_selectedUrls
.erase(it
);
1238 selectionManager
->setSelectedItems(selectedItems
);
1242 void DolphinView::hideToolTip()
1244 if (GeneralSettings::showToolTips()) {
1245 m_toolTipManager
->hideToolTip();
1249 void DolphinView::calculateItemCount(int& fileCount
,
1251 KIO::filesize_t
& totalFileSize
) const
1253 const int itemCount
= m_model
->count();
1254 for (int i
= 0; i
< itemCount
; ++i
) {
1255 const KFileItem item
= m_model
->fileItem(i
);
1260 totalFileSize
+= item
.size();
1265 void DolphinView::showHoverInformation(const KFileItem
& item
)
1267 emit
requestItemInfo(item
);
1270 void DolphinView::clearHoverInformation()
1272 emit
requestItemInfo(KFileItem());
1275 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1277 if (job
->error() == 0) {
1278 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1279 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1280 emit
errorMessage(job
->errorString());
1284 void DolphinView::slotDirectoryLoadingStarted()
1286 // Disable the writestate temporary until it can be determined in a fast way
1287 // in DolphinView::slotLoadingCompleted()
1288 if (m_isFolderWritable
) {
1289 m_isFolderWritable
= false;
1290 emit
writeStateChanged(m_isFolderWritable
);
1293 emit
directoryLoadingStarted();
1296 void DolphinView::slotDirectoryLoadingCompleted()
1298 // Update the view-state. This has to be done asynchronously
1299 // because the view might not be in its final state yet.
1300 QTimer::singleShot(0, this, SLOT(updateViewState()));
1302 emit
directoryLoadingCompleted();
1304 updateWritableState();
1307 void DolphinView::slotItemsChanged()
1309 m_assureVisibleCurrentIndex
= false;
1312 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1315 Q_ASSERT(m_model
->sortOrder() == current
);
1317 ViewProperties
props(viewPropertiesUrl());
1318 props
.setSortOrder(current
);
1320 emit
sortOrderChanged(current
);
1323 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1326 Q_ASSERT(m_model
->sortRole() == current
);
1328 ViewProperties
props(viewPropertiesUrl());
1329 props
.setSortRole(current
);
1331 emit
sortRoleChanged(current
);
1334 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1335 const QList
<QByteArray
>& previous
)
1338 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1340 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1342 m_visibleRoles
= current
;
1344 ViewProperties
props(viewPropertiesUrl());
1345 props
.setVisibleRoles(m_visibleRoles
);
1347 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1350 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1352 if (index
< 0 || index
>= m_model
->count()) {
1356 if (role
== "text") {
1357 const KFileItem oldItem
= m_model
->fileItem(index
);
1358 const QString newName
= value
.toString();
1359 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1String(".") && newName
!= QLatin1String("..")) {
1360 const KUrl oldUrl
= oldItem
.url();
1362 const KUrl
newUrl(url().path(KUrl::AddTrailingSlash
) + newName
);
1363 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1364 if (!newNameExistsAlready
) {
1365 // Only change the data in the model if no item with the new name
1366 // is in the model yet. If there is an item with the new name
1367 // already, calling KonqOperations::rename() will open a dialog
1368 // asking for a new name, and KFileItemModel will update the
1369 // data when the dir lister signals that the file name has changed.
1370 QHash
<QByteArray
, QVariant
> data
;
1371 data
.insert(role
, value
);
1372 m_model
->setData(index
, data
);
1375 KonqOperations::rename(this, oldUrl
, newName
);
1380 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1382 if (!url
.isValid()) {
1383 const QString
location(url
.pathOrUrl());
1384 if (location
.isEmpty()) {
1385 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1387 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1393 m_model
->refreshDirectory(url
);
1395 m_model
->loadDirectory(url
);
1399 void DolphinView::applyViewProperties()
1401 m_view
->beginTransaction();
1403 const ViewProperties
props(viewPropertiesUrl());
1405 const Mode mode
= props
.viewMode();
1406 if (m_mode
!= mode
) {
1407 const Mode previousMode
= m_mode
;
1410 // Changing the mode might result in changing
1411 // the zoom level. Remember the old zoom level so
1412 // that zoomLevelChanged() can get emitted.
1413 const int oldZoomLevel
= m_view
->zoomLevel();
1416 emit
modeChanged(m_mode
, previousMode
);
1418 if (m_view
->zoomLevel() != oldZoomLevel
) {
1419 emit
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1423 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1424 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1425 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1426 emit
hiddenFilesShownChanged(hiddenFilesShown
);
1429 const bool groupedSorting
= props
.groupedSorting();
1430 if (groupedSorting
!= m_model
->groupedSorting()) {
1431 m_model
->setGroupedSorting(groupedSorting
);
1432 emit
groupedSortingChanged(groupedSorting
);
1435 const QByteArray sortRole
= props
.sortRole();
1436 if (sortRole
!= m_model
->sortRole()) {
1437 m_model
->setSortRole(sortRole
);
1438 emit
sortRoleChanged(sortRole
);
1441 const Qt::SortOrder sortOrder
= props
.sortOrder();
1442 if (sortOrder
!= m_model
->sortOrder()) {
1443 m_model
->setSortOrder(sortOrder
);
1444 emit
sortOrderChanged(sortOrder
);
1447 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1448 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1449 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1450 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1453 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1454 if (visibleRoles
!= m_visibleRoles
) {
1455 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1456 m_visibleRoles
= visibleRoles
;
1457 m_view
->setVisibleRoles(visibleRoles
);
1458 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1461 const bool previewsShown
= props
.previewsShown();
1462 if (previewsShown
!= m_view
->previewsShown()) {
1463 const int oldZoomLevel
= zoomLevel();
1465 m_view
->setPreviewsShown(previewsShown
);
1466 emit
previewsShownChanged(previewsShown
);
1468 // Changing the preview-state might result in a changed zoom-level
1469 if (oldZoomLevel
!= zoomLevel()) {
1470 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1474 KItemListView
* itemListView
= m_container
->controller()->view();
1475 if (itemListView
->isHeaderVisible()) {
1476 KItemListHeader
* header
= itemListView
->header();
1477 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
1478 const int rolesCount
= m_visibleRoles
.count();
1479 if (headerColumnWidths
.count() == rolesCount
) {
1480 header
->setAutomaticColumnResizing(false);
1482 QHash
<QByteArray
, qreal
> columnWidths
;
1483 for (int i
= 0; i
< rolesCount
; ++i
) {
1484 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
1486 header
->setColumnWidths(columnWidths
);
1488 header
->setAutomaticColumnResizing(true);
1492 m_view
->endTransaction();
1495 void DolphinView::applyModeToView()
1498 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
1499 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
1500 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1501 default: Q_ASSERT(false); break;
1505 void DolphinView::pasteToUrl(const KUrl
& url
)
1507 markPastedUrlsAsSelected(QApplication::clipboard()->mimeData());
1508 KonqOperations::doPaste(this, url
);
1511 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1515 const KFileItemList items
= selectedItems();
1516 foreach (const KFileItem
& item
, items
) {
1517 urls
.append(item
.url());
1520 if (itemsExpandable()) {
1521 // TODO: Check if we still need KDirModel for this in KDE 5.0
1522 urls
= KDirModel::simplifiedUrlList(urls
);
1528 QMimeData
* DolphinView::selectionMimeData() const
1530 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1531 const QSet
<int> selectedIndexes
= selectionManager
->selectedItems();
1533 return m_model
->createMimeData(selectedIndexes
);
1536 void DolphinView::markPastedUrlsAsSelected(const QMimeData
* mimeData
)
1538 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1539 KUrl::List destUrls
;
1540 foreach (const KUrl
& source
, sourceUrls
) {
1541 KUrl
destination(url().url() + '/' + source
.fileName());
1542 destUrls
<< destination
;
1544 markUrlsAsSelected(destUrls
);
1545 m_clearSelectionBeforeSelectingNewItems
= true;
1548 void DolphinView::updateWritableState()
1550 const bool wasFolderWritable
= m_isFolderWritable
;
1551 m_isFolderWritable
= true;
1553 const KFileItem item
= m_model
->rootItem();
1554 if (!item
.isNull()) {
1555 KFileItemListProperties
capabilities(KFileItemList() << item
);
1556 m_isFolderWritable
= capabilities
.supportsWriting();
1558 if (m_isFolderWritable
!= wasFolderWritable
) {
1559 emit
writeStateChanged(m_isFolderWritable
);
1563 KUrl
DolphinView::viewPropertiesUrl() const
1565 if (m_viewPropertiesContext
.isEmpty()) {
1570 url
.setProtocol(m_url
.protocol());
1571 url
.setPath(m_viewPropertiesContext
);
1575 #include "dolphinview.moc"