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(roleEditingCanceled(int,QByteArray
,QVariant
)),
178 this, SLOT(slotRoleEditingCanceled(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 QList
<int> selectedIndexes
= selectionManager
->selectedItems().toList();
348 qSort(selectedIndexes
);
350 KFileItemList selectedItems
;
351 QListIterator
<int> it(selectedIndexes
);
352 while (it
.hasNext()) {
353 const int index
= it
.next();
354 selectedItems
.append(m_model
->fileItem(index
));
356 return selectedItems
;
359 int DolphinView::selectedItemsCount() const
361 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
362 return selectionManager
->selectedItems().count();
365 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
367 m_selectedUrls
= urls
;
370 void DolphinView::markUrlAsCurrent(const KUrl
& url
)
372 m_currentItemUrl
= url
;
373 m_scrollToCurrentItem
= true;
376 void DolphinView::selectItems(const QRegExp
& pattern
, bool enabled
)
378 const KItemListSelectionManager::SelectionMode mode
= enabled
379 ? KItemListSelectionManager::Select
380 : KItemListSelectionManager::Deselect
;
381 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
383 for (int index
= 0; index
< m_model
->count(); index
++) {
384 const KFileItem item
= m_model
->fileItem(index
);
385 if (pattern
.exactMatch(item
.text())) {
386 // An alternative approach would be to store the matching items in a QSet<int> and
387 // select them in one go after the loop, but we'd need a new function
388 // KItemListSelectionManager::setSelected(QSet<int>, SelectionMode mode)
390 selectionManager
->setSelected(index
, 1, mode
);
395 void DolphinView::setZoomLevel(int level
)
397 const int oldZoomLevel
= zoomLevel();
398 m_view
->setZoomLevel(level
);
399 if (zoomLevel() != oldZoomLevel
) {
401 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
405 int DolphinView::zoomLevel() const
407 return m_view
->zoomLevel();
410 void DolphinView::setSortRole(const QByteArray
& role
)
412 if (role
!= sortRole()) {
413 updateSortRole(role
);
417 QByteArray
DolphinView::sortRole() const
419 const KItemModelBase
* model
= m_container
->controller()->model();
420 return model
->sortRole();
423 void DolphinView::setSortOrder(Qt::SortOrder order
)
425 if (sortOrder() != order
) {
426 updateSortOrder(order
);
430 Qt::SortOrder
DolphinView::sortOrder() const
432 return m_model
->sortOrder();
435 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
437 if (sortFoldersFirst() != foldersFirst
) {
438 updateSortFoldersFirst(foldersFirst
);
442 bool DolphinView::sortFoldersFirst() const
444 return m_model
->sortDirectoriesFirst();
447 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
449 const QList
<QByteArray
> previousRoles
= roles
;
451 ViewProperties
props(viewPropertiesUrl());
452 props
.setVisibleRoles(roles
);
454 m_visibleRoles
= roles
;
455 m_view
->setVisibleRoles(roles
);
457 emit
visibleRolesChanged(m_visibleRoles
, previousRoles
);
460 QList
<QByteArray
> DolphinView::visibleRoles() const
462 return m_visibleRoles
;
465 void DolphinView::reload()
467 QByteArray viewState
;
468 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
469 saveState(saveStream
);
471 const KFileItemList itemList
= selectedItems();
472 m_selectedUrls
.clear();
473 m_selectedUrls
= itemList
.urlList();
476 loadDirectory(url(), true);
478 QDataStream
restoreStream(viewState
);
479 restoreState(restoreStream
);
482 void DolphinView::stopLoading()
484 m_model
->cancelDirectoryLoading();
487 void DolphinView::readSettings()
489 const int oldZoomLevel
= m_view
->zoomLevel();
491 GeneralSettings::self()->readConfig();
492 m_view
->readSettings();
493 applyViewProperties();
495 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
496 m_container
->controller()->setAutoActivationDelay(delay
);
498 const int newZoomLevel
= m_view
->zoomLevel();
499 if (newZoomLevel
!= oldZoomLevel
) {
500 emit
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
504 void DolphinView::writeSettings()
506 GeneralSettings::self()->writeConfig();
507 m_view
->writeSettings();
510 void DolphinView::setNameFilter(const QString
& nameFilter
)
512 m_model
->setNameFilter(nameFilter
);
515 QString
DolphinView::nameFilter() const
517 return m_model
->nameFilter();
520 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
522 return m_model
->setMimeTypeFilters(filters
);
525 QStringList
DolphinView::mimeTypeFilters() const
527 return m_model
->mimeTypeFilters();
530 QString
DolphinView::statusBarText() const
538 KIO::filesize_t totalFileSize
= 0;
540 if (m_container
->controller()->selectionManager()->hasSelection()) {
541 // Give a summary of the status of the selected files
542 const KFileItemList list
= selectedItems();
543 foreach (const KFileItem
& item
, list
) {
548 totalFileSize
+= item
.size();
552 if (folderCount
+ fileCount
== 1) {
553 // If only one item is selected, show the filename
554 filesText
= i18nc("@info:status", "<filename>%1</filename> selected", list
.first().text());
556 // At least 2 items are selected
557 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
558 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
561 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
562 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
563 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
566 if (fileCount
> 0 && folderCount
> 0) {
567 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
568 foldersText
, filesText
,
569 KGlobal::locale()->formatByteSize(totalFileSize
));
570 } else if (fileCount
> 0) {
571 summary
= i18nc("@info:status files (size)", "%1 (%2)",
573 KGlobal::locale()->formatByteSize(totalFileSize
));
574 } else if (folderCount
> 0) {
575 summary
= foldersText
;
577 summary
= i18nc("@info:status", "0 Folders, 0 Files");
583 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
585 QList
<QAction
*> actions
;
587 if (items
.isEmpty()) {
588 const KFileItem item
= m_model
->rootItem();
589 if (!item
.isNull()) {
590 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
593 actions
= m_versionControlObserver
->actions(items
);
599 void DolphinView::setUrl(const KUrl
& url
)
607 emit
urlAboutToBeChanged(url
);
612 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
613 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
615 // It is important to clear the items from the model before
616 // applying the view properties, otherwise expensive operations
617 // might be done on the existing items although they get cleared
618 // anyhow afterwards by loadDirectory().
620 applyViewProperties();
623 emit
urlChanged(url
);
626 void DolphinView::selectAll()
628 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
629 selectionManager
->setSelected(0, m_model
->count());
632 void DolphinView::invertSelection()
634 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
635 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
638 void DolphinView::clearSelection()
640 m_selectedUrls
.clear();
641 m_container
->controller()->selectionManager()->clearSelection();
644 void DolphinView::renameSelectedItems()
646 const KFileItemList items
= selectedItems();
647 if (items
.isEmpty()) {
651 if (items
.count() == 1 && GeneralSettings::renameInline()) {
652 const int index
= m_model
->index(items
.first());
653 m_view
->editRole(index
, "text");
655 connect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
656 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
658 RenameDialog
* dialog
= new RenameDialog(this, items
);
659 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
662 dialog
->activateWindow();
665 // Assure that the current index remains visible when KFileItemModel
666 // will notify the view about changed items (which might result in
667 // a changed sorting).
668 m_assureVisibleCurrentIndex
= true;
671 void DolphinView::trashSelectedItems()
673 const KUrl::List list
= simplifiedSelectedUrls();
674 KonqOperations::del(this, KonqOperations::TRASH
, list
);
677 void DolphinView::deleteSelectedItems()
679 const KUrl::List list
= simplifiedSelectedUrls();
680 const bool del
= KonqOperations::askDeleteConfirmation(list
,
682 KonqOperations::DEFAULT_CONFIRMATION
,
686 KIO::Job
* job
= KIO::del(list
);
688 job
->ui()->setWindow(this);
690 connect(job
, SIGNAL(result(KJob
*)),
691 this, SLOT(slotDeleteFileFinished(KJob
*)));
695 void DolphinView::cutSelectedItems()
697 QMimeData
* mimeData
= selectionMimeData();
698 KonqMimeData::addIsCutSelection(mimeData
, true);
699 QApplication::clipboard()->setMimeData(mimeData
);
702 void DolphinView::copySelectedItems()
704 QMimeData
* mimeData
= selectionMimeData();
705 QApplication::clipboard()->setMimeData(mimeData
);
708 void DolphinView::paste()
713 void DolphinView::pasteIntoFolder()
715 const KFileItemList items
= selectedItems();
716 if ((items
.count() == 1) && items
.first().isDir()) {
717 pasteToUrl(items
.first().url());
721 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
723 switch (event
->type()) {
724 case QEvent::FocusIn
:
725 if (watched
== m_container
) {
730 case QEvent::GraphicsSceneDragEnter
:
731 if (watched
== m_view
) {
736 case QEvent::GraphicsSceneDragLeave
:
737 if (watched
== m_view
) {
742 case QEvent::GraphicsSceneDrop
:
743 if (watched
== m_view
) {
750 return QWidget::eventFilter(watched
, event
);
753 void DolphinView::wheelEvent(QWheelEvent
* event
)
755 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
756 const int numDegrees
= event
->delta() / 8;
757 const int numSteps
= numDegrees
/ 15;
759 setZoomLevel(zoomLevel() + numSteps
);
766 void DolphinView::hideEvent(QHideEvent
* event
)
769 QWidget::hideEvent(event
);
772 bool DolphinView::event(QEvent
* event
)
775 * Dolphin leaves file preview tooltips open even when is not visible.
777 * Hide tool-tip when Dolphin loses focus.
779 if (event
->type() == QEvent::WindowDeactivate
) {
783 return QWidget::event(event
);
786 void DolphinView::activate()
791 void DolphinView::slotItemActivated(int index
)
793 const KFileItem item
= m_model
->fileItem(index
);
794 if (!item
.isNull()) {
795 emit
itemActivated(item
);
799 void DolphinView::slotItemsActivated(const QSet
<int>& indexes
)
801 Q_ASSERT(indexes
.count() >= 2);
803 if (indexes
.count() > 5) {
804 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
805 const int answer
= KMessageBox::warningYesNo(this, question
);
806 if (answer
!= KMessageBox::Yes
) {
812 items
.reserve(indexes
.count());
814 QSetIterator
<int> it(indexes
);
815 while (it
.hasNext()) {
816 const int index
= it
.next();
817 KFileItem item
= m_model
->fileItem(index
);
819 if (item
.isDir()) { // Open folders in new tabs
820 emit
tabRequested(item
.url());
826 if (items
.count() == 1) {
827 emit
itemActivated(items
.first());
828 } else if (items
.count() > 1) {
829 emit
itemsActivated(items
);
833 void DolphinView::slotItemMiddleClicked(int index
)
835 const KFileItem item
= m_model
->fileItem(index
);
836 if (item
.isDir() || isTabsForFilesEnabled()) {
837 emit
tabRequested(item
.url());
841 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
843 const KFileItem item
= m_model
->fileItem(index
);
844 emit
requestContextMenu(pos
.toPoint(), item
, url(), QList
<QAction
*>());
847 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
849 emit
requestContextMenu(pos
.toPoint(), KFileItem(), url(), QList
<QAction
*>());
852 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
854 ViewProperties
props(viewPropertiesUrl());
856 QPointer
<KMenu
> menu
= new KMenu(QApplication::activeWindow());
858 KItemListView
* view
= m_container
->controller()->view();
859 const QSet
<QByteArray
> visibleRolesSet
= view
->visibleRoles().toSet();
861 bool nepomukRunning
= false;
862 bool indexingEnabled
= false;
864 nepomukRunning
= (Nepomuk2::ResourceManager::instance()->initialized());
865 if (nepomukRunning
) {
866 KConfig
config("nepomukserverrc");
867 indexingEnabled
= config
.group("Service-nepomukfileindexer").readEntry("autostart", true);
872 QMenu
* groupMenu
= 0;
874 // Add all roles to the menu that can be shown or hidden by the user
875 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
876 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
877 if (info
.role
== "text") {
878 // It should not be possible to hide the "text" role
882 const QString text
= m_model
->roleDescription(info
.role
);
884 if (info
.group
.isEmpty()) {
885 action
= menu
->addAction(text
);
887 if (!groupMenu
|| info
.group
!= groupName
) {
888 groupName
= info
.group
;
889 groupMenu
= menu
->addMenu(groupName
);
892 action
= groupMenu
->addAction(text
);
895 action
->setCheckable(true);
896 action
->setChecked(visibleRolesSet
.contains(info
.role
));
897 action
->setData(info
.role
);
899 const bool enable
= (!info
.requiresNepomuk
&& !info
.requiresIndexer
) ||
900 (info
.requiresNepomuk
&& nepomukRunning
) ||
901 (info
.requiresIndexer
&& indexingEnabled
);
902 action
->setEnabled(enable
);
905 menu
->addSeparator();
907 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
908 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
910 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
911 autoAdjustWidthsAction
->setCheckable(true);
912 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
913 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
915 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
916 customWidthsAction
->setCheckable(true);
917 customWidthsAction
->setChecked(!autoColumnWidths
);
918 customWidthsAction
->setActionGroup(widthsGroup
);
920 QAction
* action
= menu
->exec(pos
.toPoint());
921 if (menu
&& action
) {
922 KItemListHeader
* header
= view
->header();
924 if (action
== autoAdjustWidthsAction
) {
925 // Clear the column-widths from the viewproperties and turn on
926 // the automatic resizing of the columns
927 props
.setHeaderColumnWidths(QList
<int>());
928 header
->setAutomaticColumnResizing(true);
929 } else if (action
== customWidthsAction
) {
930 // Apply the current column-widths as custom column-widths and turn
931 // off the automatic resizing of the columns
932 QList
<int> columnWidths
;
933 foreach (const QByteArray
& role
, view
->visibleRoles()) {
934 columnWidths
.append(header
->columnWidth(role
));
936 props
.setHeaderColumnWidths(columnWidths
);
937 header
->setAutomaticColumnResizing(false);
939 // Show or hide the selected role
940 const QByteArray selectedRole
= action
->data().toByteArray();
942 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
943 if (action
->isChecked()) {
944 visibleRoles
.append(selectedRole
);
946 visibleRoles
.removeOne(selectedRole
);
949 view
->setVisibleRoles(visibleRoles
);
950 props
.setVisibleRoles(visibleRoles
);
952 QList
<int> columnWidths
;
953 if (!header
->automaticColumnResizing()) {
954 foreach (const QByteArray
& role
, view
->visibleRoles()) {
955 columnWidths
.append(header
->columnWidth(role
));
958 props
.setHeaderColumnWidths(columnWidths
);
965 void DolphinView::slotHeaderColumnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
)
969 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
971 ViewProperties
props(viewPropertiesUrl());
972 QList
<int> columnWidths
= props
.headerColumnWidths();
973 if (columnWidths
.count() != visibleRoles
.count()) {
974 columnWidths
.clear();
975 columnWidths
.reserve(visibleRoles
.count());
976 const KItemListHeader
* header
= m_view
->header();
977 foreach (const QByteArray
& role
, visibleRoles
) {
978 const int width
= header
->columnWidth(role
);
979 columnWidths
.append(width
);
983 const int roleIndex
= visibleRoles
.indexOf(role
);
984 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
985 columnWidths
[roleIndex
] = current
;
987 props
.setHeaderColumnWidths(columnWidths
);
990 void DolphinView::slotItemHovered(int index
)
992 const KFileItem item
= m_model
->fileItem(index
);
994 if (GeneralSettings::showToolTips() && !m_dragging
) {
995 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
996 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
997 itemRect
.moveTo(pos
);
999 m_toolTipManager
->showToolTip(item
, itemRect
);
1002 emit
requestItemInfo(item
);
1005 void DolphinView::slotItemUnhovered(int index
)
1009 emit
requestItemInfo(KFileItem());
1012 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1015 KFileItem destItem
= m_model
->fileItem(index
);
1016 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1017 // Use the URL of the view as drop target if the item is no directory
1019 destItem
= m_model
->rootItem();
1022 // The item represents a directory or desktop-file
1023 destUrl
= destItem
.url();
1026 QDropEvent
dropEvent(event
->pos().toPoint(),
1027 event
->possibleActions(),
1030 event
->modifiers());
1032 const QString error
= DragAndDropHelper::dropUrls(destItem
, destUrl
, &dropEvent
);
1033 if (!error
.isEmpty()) {
1034 emit
infoMessage(error
);
1037 if (destUrl
== url()) {
1038 // Mark the dropped urls as selected.
1039 markPastedUrlsAsSelected(event
->mimeData());
1043 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1045 if (previous
!= 0) {
1046 disconnect(previous
, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1047 m_versionControlObserver
->setModel(0);
1051 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1052 connect(current
, SIGNAL(loadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
1054 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1055 m_versionControlObserver
->setModel(fileItemModel
);
1059 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1063 if (itemIndex
< 0) {
1064 // Trigger the history navigation only when clicking on the viewport:
1065 // Above an item the XButtons provide a simple way to select items in
1066 // the singleClick mode.
1067 if (buttons
& Qt::XButton1
) {
1068 emit
goBackRequested();
1069 } else if (buttons
& Qt::XButton2
) {
1070 emit
goForwardRequested();
1075 void DolphinView::slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
)
1077 const int currentCount
= current
.count();
1078 const int previousCount
= previous
.count();
1079 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1080 (currentCount
> 0 && previousCount
== 0);
1082 // If nothing has been selected before and something got selected (or if something
1083 // was selected before and now nothing is selected) the selectionChangedSignal must
1084 // be emitted asynchronously as fast as possible to update the edit-actions.
1085 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1086 m_selectionChangedTimer
->start();
1089 void DolphinView::emitSelectionChangedSignal()
1091 m_selectionChangedTimer
->stop();
1092 emit
selectionChanged(selectedItems());
1095 void DolphinView::updateSortRole(const QByteArray
& role
)
1097 ViewProperties
props(viewPropertiesUrl());
1098 props
.setSortRole(role
);
1100 KItemModelBase
* model
= m_container
->controller()->model();
1101 model
->setSortRole(role
);
1103 emit
sortRoleChanged(role
);
1106 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1108 ViewProperties
props(viewPropertiesUrl());
1109 props
.setSortOrder(order
);
1111 m_model
->setSortOrder(order
);
1113 emit
sortOrderChanged(order
);
1116 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1118 ViewProperties
props(viewPropertiesUrl());
1119 props
.setSortFoldersFirst(foldersFirst
);
1121 m_model
->setSortDirectoriesFirst(foldersFirst
);
1123 emit
sortFoldersFirstChanged(foldersFirst
);
1126 QPair
<bool, QString
> DolphinView::pasteInfo() const
1128 return KonqOperations::pasteInfo(url());
1131 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1133 m_tabsForFiles
= tabsForFiles
;
1136 bool DolphinView::isTabsForFilesEnabled() const
1138 return m_tabsForFiles
;
1141 bool DolphinView::itemsExpandable() const
1143 return m_mode
== DetailsView
;
1146 void DolphinView::restoreState(QDataStream
& stream
)
1148 // Restore the current item that had the keyboard focus
1149 stream
>> m_currentItemUrl
;
1151 // Restore the view position
1152 stream
>> m_restoredContentsPosition
;
1154 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1157 m_model
->restoreExpandedDirectories(urls
);
1160 void DolphinView::saveState(QDataStream
& stream
)
1162 // Save the current item that has the keyboard focus
1163 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1164 if (currentIndex
!= -1) {
1165 KFileItem item
= m_model
->fileItem(currentIndex
);
1166 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1167 KUrl currentItemUrl
= item
.url();
1168 stream
<< currentItemUrl
;
1173 // Save view position
1174 const qreal x
= m_container
->horizontalScrollBar()->value();
1175 const qreal y
= m_container
->verticalScrollBar()->value();
1176 stream
<< QPoint(x
, y
);
1178 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1179 stream
<< m_model
->expandedDirectories();
1182 KFileItem
DolphinView::rootItem() const
1184 return m_model
->rootItem();
1187 void DolphinView::setViewPropertiesContext(const QString
& context
)
1189 m_viewPropertiesContext
= context
;
1192 QString
DolphinView::viewPropertiesContext() const
1194 return m_viewPropertiesContext
;
1197 void DolphinView::observeCreatedItem(const KUrl
& url
)
1201 markUrlAsCurrent(url
);
1202 markUrlsAsSelected(QList
<KUrl
>() << url
);
1206 void DolphinView::slotDirectoryRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1208 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
1209 emit
redirection(oldUrl
, newUrl
);
1210 m_url
= newUrl
; // #186947
1214 void DolphinView::updateViewState()
1216 if (m_currentItemUrl
!= KUrl()) {
1217 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1218 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1219 if (currentIndex
!= -1) {
1220 selectionManager
->setCurrentItem(currentIndex
);
1222 // scroll to current item and reset the state
1223 if (m_scrollToCurrentItem
) {
1224 m_view
->scrollToItem(currentIndex
);
1225 m_scrollToCurrentItem
= false;
1228 selectionManager
->setCurrentItem(0);
1230 m_currentItemUrl
= KUrl();
1233 if (!m_restoredContentsPosition
.isNull()) {
1234 const int x
= m_restoredContentsPosition
.x();
1235 const int y
= m_restoredContentsPosition
.y();
1236 m_restoredContentsPosition
= QPoint();
1238 m_container
->horizontalScrollBar()->setValue(x
);
1239 m_container
->verticalScrollBar()->setValue(y
);
1242 if (!m_selectedUrls
.isEmpty()) {
1243 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1245 if (m_clearSelectionBeforeSelectingNewItems
) {
1246 selectionManager
->clearSelection();
1247 m_clearSelectionBeforeSelectingNewItems
= false;
1250 QSet
<int> selectedItems
= selectionManager
->selectedItems();
1252 QList
<KUrl
>::iterator it
= m_selectedUrls
.begin();
1253 while (it
!= m_selectedUrls
.end()) {
1254 const int index
= m_model
->index(*it
);
1256 selectedItems
.insert(index
);
1257 it
= m_selectedUrls
.erase(it
);
1263 selectionManager
->setSelectedItems(selectedItems
);
1267 void DolphinView::hideToolTip()
1269 if (GeneralSettings::showToolTips()) {
1270 m_toolTipManager
->hideToolTip();
1274 void DolphinView::calculateItemCount(int& fileCount
,
1276 KIO::filesize_t
& totalFileSize
) const
1278 const int itemCount
= m_model
->count();
1279 for (int i
= 0; i
< itemCount
; ++i
) {
1280 const KFileItem item
= m_model
->fileItem(i
);
1285 totalFileSize
+= item
.size();
1290 void DolphinView::showHoverInformation(const KFileItem
& item
)
1292 emit
requestItemInfo(item
);
1295 void DolphinView::clearHoverInformation()
1297 emit
requestItemInfo(KFileItem());
1300 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1302 if (job
->error() == 0) {
1303 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1304 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1305 emit
errorMessage(job
->errorString());
1309 void DolphinView::slotDirectoryLoadingStarted()
1311 // Disable the writestate temporary until it can be determined in a fast way
1312 // in DolphinView::slotLoadingCompleted()
1313 if (m_isFolderWritable
) {
1314 m_isFolderWritable
= false;
1315 emit
writeStateChanged(m_isFolderWritable
);
1318 emit
directoryLoadingStarted();
1321 void DolphinView::slotDirectoryLoadingCompleted()
1323 // Update the view-state. This has to be done asynchronously
1324 // because the view might not be in its final state yet.
1325 QTimer::singleShot(0, this, SLOT(updateViewState()));
1327 emit
directoryLoadingCompleted();
1329 updateWritableState();
1332 void DolphinView::slotItemsChanged()
1334 m_assureVisibleCurrentIndex
= false;
1337 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1340 Q_ASSERT(m_model
->sortOrder() == current
);
1342 ViewProperties
props(viewPropertiesUrl());
1343 props
.setSortOrder(current
);
1345 emit
sortOrderChanged(current
);
1348 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1351 Q_ASSERT(m_model
->sortRole() == current
);
1353 ViewProperties
props(viewPropertiesUrl());
1354 props
.setSortRole(current
);
1356 emit
sortRoleChanged(current
);
1359 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1360 const QList
<QByteArray
>& previous
)
1363 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1365 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1367 m_visibleRoles
= current
;
1369 ViewProperties
props(viewPropertiesUrl());
1370 props
.setVisibleRoles(m_visibleRoles
);
1372 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1375 void DolphinView::slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
)
1377 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
1378 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
1381 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1383 disconnect(m_view
, SIGNAL(roleEditingFinished(int,QByteArray
,QVariant
)),
1384 this, SLOT(slotRoleEditingFinished(int,QByteArray
,QVariant
)));
1386 if (index
< 0 || index
>= m_model
->count()) {
1390 if (role
== "text") {
1391 const KFileItem oldItem
= m_model
->fileItem(index
);
1392 const QString newName
= value
.toString();
1393 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1String(".") && newName
!= QLatin1String("..")) {
1394 const KUrl oldUrl
= oldItem
.url();
1396 const KUrl
newUrl(url().path(KUrl::AddTrailingSlash
) + newName
);
1397 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1398 if (!newNameExistsAlready
) {
1399 // Only change the data in the model if no item with the new name
1400 // is in the model yet. If there is an item with the new name
1401 // already, calling KonqOperations::rename() will open a dialog
1402 // asking for a new name, and KFileItemModel will update the
1403 // data when the dir lister signals that the file name has changed.
1404 QHash
<QByteArray
, QVariant
> data
;
1405 data
.insert(role
, value
);
1406 m_model
->setData(index
, data
);
1409 KonqOperations::rename(this, oldUrl
, newName
);
1414 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1416 if (!url
.isValid()) {
1417 const QString
location(url
.pathOrUrl());
1418 if (location
.isEmpty()) {
1419 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1421 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1427 m_model
->refreshDirectory(url
);
1429 m_model
->loadDirectory(url
);
1433 void DolphinView::applyViewProperties()
1435 m_view
->beginTransaction();
1437 const ViewProperties
props(viewPropertiesUrl());
1439 const Mode mode
= props
.viewMode();
1440 if (m_mode
!= mode
) {
1441 const Mode previousMode
= m_mode
;
1444 // Changing the mode might result in changing
1445 // the zoom level. Remember the old zoom level so
1446 // that zoomLevelChanged() can get emitted.
1447 const int oldZoomLevel
= m_view
->zoomLevel();
1450 emit
modeChanged(m_mode
, previousMode
);
1452 if (m_view
->zoomLevel() != oldZoomLevel
) {
1453 emit
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1457 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1458 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1459 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1460 emit
hiddenFilesShownChanged(hiddenFilesShown
);
1463 const bool groupedSorting
= props
.groupedSorting();
1464 if (groupedSorting
!= m_model
->groupedSorting()) {
1465 m_model
->setGroupedSorting(groupedSorting
);
1466 emit
groupedSortingChanged(groupedSorting
);
1469 const QByteArray sortRole
= props
.sortRole();
1470 if (sortRole
!= m_model
->sortRole()) {
1471 m_model
->setSortRole(sortRole
);
1472 emit
sortRoleChanged(sortRole
);
1475 const Qt::SortOrder sortOrder
= props
.sortOrder();
1476 if (sortOrder
!= m_model
->sortOrder()) {
1477 m_model
->setSortOrder(sortOrder
);
1478 emit
sortOrderChanged(sortOrder
);
1481 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1482 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1483 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1484 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1487 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1488 if (visibleRoles
!= m_visibleRoles
) {
1489 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1490 m_visibleRoles
= visibleRoles
;
1491 m_view
->setVisibleRoles(visibleRoles
);
1492 emit
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1495 const bool previewsShown
= props
.previewsShown();
1496 if (previewsShown
!= m_view
->previewsShown()) {
1497 const int oldZoomLevel
= zoomLevel();
1499 m_view
->setPreviewsShown(previewsShown
);
1500 emit
previewsShownChanged(previewsShown
);
1502 // Changing the preview-state might result in a changed zoom-level
1503 if (oldZoomLevel
!= zoomLevel()) {
1504 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1508 KItemListView
* itemListView
= m_container
->controller()->view();
1509 if (itemListView
->isHeaderVisible()) {
1510 KItemListHeader
* header
= itemListView
->header();
1511 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
1512 const int rolesCount
= m_visibleRoles
.count();
1513 if (headerColumnWidths
.count() == rolesCount
) {
1514 header
->setAutomaticColumnResizing(false);
1516 QHash
<QByteArray
, qreal
> columnWidths
;
1517 for (int i
= 0; i
< rolesCount
; ++i
) {
1518 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
1520 header
->setColumnWidths(columnWidths
);
1522 header
->setAutomaticColumnResizing(true);
1526 m_view
->endTransaction();
1529 void DolphinView::applyModeToView()
1532 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
1533 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
1534 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1535 default: Q_ASSERT(false); break;
1539 void DolphinView::pasteToUrl(const KUrl
& url
)
1541 markPastedUrlsAsSelected(QApplication::clipboard()->mimeData());
1542 KonqOperations::doPaste(this, url
);
1545 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1549 const KFileItemList items
= selectedItems();
1550 foreach (const KFileItem
& item
, items
) {
1551 urls
.append(item
.url());
1554 if (itemsExpandable()) {
1555 // TODO: Check if we still need KDirModel for this in KDE 5.0
1556 urls
= KDirModel::simplifiedUrlList(urls
);
1562 QMimeData
* DolphinView::selectionMimeData() const
1564 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1565 const QSet
<int> selectedIndexes
= selectionManager
->selectedItems();
1567 return m_model
->createMimeData(selectedIndexes
);
1570 void DolphinView::markPastedUrlsAsSelected(const QMimeData
* mimeData
)
1572 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
1573 KUrl::List destUrls
;
1574 foreach (const KUrl
& source
, sourceUrls
) {
1575 KUrl
destination(url().url() + '/' + source
.fileName());
1576 destUrls
<< destination
;
1578 markUrlsAsSelected(destUrls
);
1579 m_clearSelectionBeforeSelectingNewItems
= true;
1582 void DolphinView::updateWritableState()
1584 const bool wasFolderWritable
= m_isFolderWritable
;
1585 m_isFolderWritable
= true;
1587 const KFileItem item
= m_model
->rootItem();
1588 if (!item
.isNull()) {
1589 KFileItemListProperties
capabilities(KFileItemList() << item
);
1590 m_isFolderWritable
= capabilities
.supportsWriting();
1592 if (m_isFolderWritable
!= wasFolderWritable
) {
1593 emit
writeStateChanged(m_isFolderWritable
);
1597 KUrl
DolphinView::viewPropertiesUrl() const
1599 if (m_viewPropertiesContext
.isEmpty()) {
1604 url
.setProtocol(m_url
.protocol());
1605 url
.setPath(m_viewPropertiesContext
);
1609 #include "dolphinview.moc"