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 <QAbstractItemView>
24 #include <QApplication>
27 #include <QItemSelection>
32 #include <KActionCollection>
33 #include <KColorScheme>
35 #include <KIconEffect>
37 #include <KFileItemListProperties>
39 #include <kitemviews/kfileitemmodel.h>
40 #include <kitemviews/kfileitemlistview.h>
41 #include <kitemviews/kitemlistselectionmanager.h>
42 #include <kitemviews/kitemlistview.h>
43 #include <kitemviews/kitemlistcontroller.h>
44 #include <KIO/DeleteJob>
45 #include <KIO/NetAccess>
46 #include <KIO/PreviewJob>
49 #include <KMessageBox>
50 #include <konq_fileitemcapabilities.h>
51 #include <konq_operations.h>
52 #include <konqmimedata.h>
53 #include <KToggleAction>
56 #include "additionalinfoaccessor.h"
57 #include "dolphindirlister.h"
58 #include "dolphinnewfilemenuobserver.h"
59 #include "dolphin_detailsmodesettings.h"
60 #include "dolphin_generalsettings.h"
61 #include "dolphinitemlistcontainer.h"
62 #include "renamedialog.h"
63 #include "settings/dolphinsettings.h"
64 #include "viewmodecontroller.h"
65 #include "viewproperties.h"
66 #include "views/tooltips/tooltipmanager.h"
67 #include "zoomlevelinfo.h"
70 const int MaxModeEnum
= DolphinView::CompactView
;
71 const int MaxSortingEnum
= DolphinView::SortByPath
;
74 DolphinView::DolphinView(const KUrl
& url
, QWidget
* parent
) :
77 m_tabsForFiles(false),
78 m_assureVisibleCurrentIndex(false),
79 m_isFolderWritable(true),
81 m_mode(DolphinView::IconsView
),
82 m_additionalInfoList(),
87 m_selectionChangedTimer(0),
88 m_currentItemIndex(-1),
89 m_restoredContentsPosition(),
93 m_topLayout
= new QVBoxLayout(this);
94 m_topLayout
->setSpacing(0);
95 m_topLayout
->setMargin(0);
97 //m_dolphinViewController = new DolphinViewController(this);
99 //m_viewModeController = new ViewModeController(this);
100 //m_viewModeController->setUrl(url);
102 /*connect(m_viewModeController, SIGNAL(urlChanged(KUrl)),
103 this, SIGNAL(urlChanged(KUrl)));
105 connect(m_dolphinViewController, SIGNAL(requestContextMenu(QPoint,QList<QAction*>)),
106 this, SLOT(openContextMenu(QPoint,QList<QAction*>)));
107 connect(m_dolphinViewController, SIGNAL(urlsDropped(KFileItem,KUrl,QDropEvent*)),
108 this, SLOT(dropUrls(KFileItem,KUrl,QDropEvent*)));
109 connect(m_dolphinViewController, SIGNAL(sortingChanged(DolphinView::Sorting)),
110 this, SLOT(updateSorting(DolphinView::Sorting)));
111 connect(m_dolphinViewController, SIGNAL(sortOrderChanged(Qt::SortOrder)),
112 this, SLOT(updateSortOrder(Qt::SortOrder)));
113 connect(m_dolphinViewController, SIGNAL(sortFoldersFirstChanged(bool)),
114 this, SLOT(updateSortFoldersFirst(bool)));
115 connect(m_dolphinViewController, SIGNAL(additionalInfoChanged(QList<DolphinView::AdditionalInfo>)),
116 this, SLOT(updateAdditionalInfo(QList<DolphinView::AdditionalInfo>)));*/
117 //connect(m_dolphinViewController, SIGNAL(itemTriggered(KFileItem)),
118 // this, SLOT(triggerItem(KFileItem)));
119 //connect(m_dolphinViewController, SIGNAL(tabRequested(KUrl)),
120 // this, SIGNAL(tabRequested(KUrl)));
121 /*connect(m_dolphinViewController, SIGNAL(activated()),
122 this, SLOT(activate()));
123 connect(m_dolphinViewController, SIGNAL(itemEntered(KFileItem)),
124 this, SLOT(showHoverInformation(KFileItem)));
125 connect(m_dolphinViewController, SIGNAL(viewportEntered()),
126 this, SLOT(clearHoverInformation()));
127 connect(m_dolphinViewController, SIGNAL(urlChangeRequested(KUrl)),
128 this, SLOT(slotUrlChangeRequested(KUrl)));*/
130 // When a new item has been created by the "Create New..." menu, the item should
131 // get selected and it must be assured that the item will get visible. As the
132 // creation is done asynchronously, several signals must be checked:
133 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(KUrl
)),
134 this, SLOT(observeCreatedItem(KUrl
)));
136 m_selectionChangedTimer
= new QTimer(this);
137 m_selectionChangedTimer
->setSingleShot(true);
138 m_selectionChangedTimer
->setInterval(300);
139 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
140 this, SLOT(emitSelectionChangedSignal()));
142 m_dirLister
= new DolphinDirLister(this);
143 m_dirLister
->setAutoUpdate(true);
144 m_dirLister
->setDelayedMimeTypes(true);
146 connect(m_dirLister
, SIGNAL(redirection(KUrl
,KUrl
)), this, SLOT(slotRedirection(KUrl
,KUrl
)));
147 connect(m_dirLister
, SIGNAL(started(KUrl
)), this, SLOT(slotDirListerStarted(KUrl
)));
148 connect(m_dirLister
, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
149 connect(m_dirLister
, SIGNAL(refreshItems(QList
<QPair
<KFileItem
,KFileItem
> >)),
150 this, SLOT(slotRefreshItems()));
152 connect(m_dirLister
, SIGNAL(clear()), this, SIGNAL(itemCountChanged()));
153 connect(m_dirLister
, SIGNAL(newItems(KFileItemList
)), this, SIGNAL(itemCountChanged()));
154 connect(m_dirLister
, SIGNAL(infoMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
155 connect(m_dirLister
, SIGNAL(errorMessage(QString
)), this, SIGNAL(infoMessage(QString
)));
156 connect(m_dirLister
, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int)));
157 connect(m_dirLister
, SIGNAL(urlIsFileError(KUrl
)), this, SIGNAL(urlIsFileError(KUrl
)));
158 connect(m_dirLister
, SIGNAL(itemsDeleted(KFileItemList
)), this, SIGNAL(itemCountChanged()));
160 m_container
= new DolphinItemListContainer(m_dirLister
, this);
161 QHash
<QByteArray
, int> visibleRoles
;
162 visibleRoles
.insert("name", 0);
163 m_container
->setVisibleRoles(visibleRoles
);
165 KItemListController
* controller
= m_container
->controller();
166 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
167 connect(controller
, SIGNAL(itemClicked(int,Qt::MouseButton
)),
168 this, SLOT(slotItemClicked(int,Qt::MouseButton
)));
169 connect(controller
, SIGNAL(itemExpansionToggleClicked(int)), this, SLOT(slotItemExpansionToggleClicked(int)));
170 connect(controller
, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int)));
171 connect(controller
, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int)));
173 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
174 connect(selectionManager
, SIGNAL(selectionChanged(QSet
<int>,QSet
<int>)),
175 this, SLOT(slotSelectionChanged(QSet
<int>,QSet
<int>)));
177 m_toolTipManager
= new ToolTipManager(this);
179 applyViewProperties();
180 m_topLayout
->addWidget(m_container
);
185 DolphinView::~DolphinView()
189 KUrl
DolphinView::url() const
194 void DolphinView::setActive(bool active
)
196 if (active
== m_active
) {
202 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
207 /*QAbstractItemView* view = m_viewAccessor.itemView();
208 QWidget* viewport = view ? view->viewport() : 0;
211 palette.setColor(viewport->backgroundRole(), color);
212 viewport->setPalette(palette);
222 emit
writeStateChanged(m_isFolderWritable
);
225 //m_viewModeController->indicateActivationChange(active);
228 bool DolphinView::isActive() const
233 void DolphinView::setMode(Mode mode
)
235 if (mode
!= m_mode
) {
236 ViewProperties
props(url());
237 props
.setViewMode(mode
);
240 applyViewProperties();
244 DolphinView::Mode
DolphinView::mode() const
249 bool DolphinView::previewsShown() const
251 return m_container
->previewsShown();
254 bool DolphinView::hiddenFilesShown() const
256 return m_dirLister
->showingDotFiles();
259 bool DolphinView::categorizedSorting() const
261 return false; //m_storedCategorizedSorting;
264 KFileItemList
DolphinView::items() const
266 return m_dirLister
->items();
269 KFileItemList
DolphinView::selectedItems() const
271 const KFileItemModel
* model
= fileItemModel();
272 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
273 const QSet
<int> selectedIndexes
= selectionManager
->selectedItems();
275 KFileItemList selectedItems
;
276 QSetIterator
<int> it(selectedIndexes
);
277 while (it
.hasNext()) {
278 const int index
= it
.next();
279 selectedItems
.append(model
->fileItem(index
));
281 return selectedItems
;
284 int DolphinView::selectedItemsCount() const
286 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
287 return selectionManager
->selectedItems().count();
290 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
292 foreach (const KUrl
& url
, urls
) {
293 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
294 m_selectedItems
.append(item
);
298 void DolphinView::setItemSelectionEnabled(const QRegExp
& pattern
, bool enabled
)
302 /*const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern);
303 const QItemSelectionModel::SelectionFlags command = enabled
304 ? QItemSelectionModel::Select
305 : QItemSelectionModel::Deselect;
306 m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command);*/
309 void DolphinView::setZoomLevel(int level
)
311 const int oldZoomLevel
= zoomLevel();
312 m_container
->setZoomLevel(level
);
313 if (zoomLevel() != oldZoomLevel
) {
314 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
318 int DolphinView::zoomLevel() const
320 return m_container
->zoomLevel();
323 void DolphinView::setSorting(Sorting sorting
)
325 if (sorting
!= this->sorting()) {
326 updateSorting(sorting
);
330 DolphinView::Sorting
DolphinView::sorting() const
332 return DolphinView::SortByName
;
333 //return m_viewAccessor.proxyModel()->sorting();
336 void DolphinView::setSortOrder(Qt::SortOrder order
)
338 if (sortOrder() != order
) {
339 updateSortOrder(order
);
343 Qt::SortOrder
DolphinView::sortOrder() const
345 return Qt::AscendingOrder
; // m_viewAccessor.proxyModel()->sortOrder();
348 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
350 if (sortFoldersFirst() != foldersFirst
) {
351 updateSortFoldersFirst(foldersFirst
);
355 bool DolphinView::sortFoldersFirst() const
357 return true; // m_viewAccessor.proxyModel()->sortFoldersFirst();
360 void DolphinView::setAdditionalInfoList(const QList
<AdditionalInfo
>& info
)
362 const QList
<AdditionalInfo
> previousList
= info
;
364 ViewProperties
props(url());
365 props
.setAdditionalInfoList(info
);
367 m_additionalInfoList
= info
;
368 applyAdditionalInfoListToView();
370 emit
additionalInfoListChanged(m_additionalInfoList
, previousList
);
373 QList
<DolphinView::AdditionalInfo
> DolphinView::additionalInfoList() const
375 return m_additionalInfoList
;
378 void DolphinView::reload()
380 QByteArray viewState
;
381 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
382 saveState(saveStream
);
383 m_selectedItems
= selectedItems();
386 loadDirectory(url(), true);
388 QDataStream
restoreStream(viewState
);
389 restoreState(restoreStream
);
392 void DolphinView::stopLoading()
397 void DolphinView::refresh()
399 const bool oldActivationState
= m_active
;
400 const int oldZoomLevel
= zoomLevel();
403 applyViewProperties();
406 setActive(oldActivationState
);
407 updateZoomLevel(oldZoomLevel
);
410 void DolphinView::setNameFilter(const QString
& nameFilter
)
412 Q_UNUSED(nameFilter
);
413 //m_viewModeController->setNameFilter(nameFilter);
416 QString
DolphinView::nameFilter() const
418 return QString(); //m_viewModeController->nameFilter();
421 void DolphinView::calculateItemCount(int& fileCount
,
423 KIO::filesize_t
& totalFileSize
) const
425 foreach (const KFileItem
& item
, m_dirLister
->items()) {
430 totalFileSize
+= item
.size();
435 QString
DolphinView::statusBarText() const
440 KIO::filesize_t totalFileSize
= 0;
442 if (hasSelection()) {
443 // give a summary of the status of the selected files
444 const KFileItemList list
= selectedItems();
445 if (list
.isEmpty()) {
446 // when an item is triggered, it is temporary selected but selectedItems()
447 // will return an empty list
451 KFileItemList::const_iterator it
= list
.begin();
452 const KFileItemList::const_iterator end
= list
.end();
454 const KFileItem
& item
= *it
;
459 totalFileSize
+= item
.size();
464 if (folderCount
+ fileCount
== 1) {
465 // if only one item is selected, show the filename
466 const QString name
= list
.first().text();
467 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
468 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
469 name
, KIO::convertSize(totalFileSize
));
471 // at least 2 items are selected
472 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
473 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
474 if ((folderCount
> 0) && (fileCount
> 0)) {
475 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
476 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
477 } else if (fileCount
> 0) {
478 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
480 Q_ASSERT(folderCount
> 0);
485 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
486 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
487 fileCount
, folderCount
,
488 totalFileSize
, true);
494 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
497 return QList
<QAction
*>(); //m_dolphinViewController->versionControlActions(items);
500 void DolphinView::setUrl(const KUrl
& url
)
506 emit
urlAboutToBeChanged(url
);
509 if (GeneralSettings::showToolTips()) {
510 m_toolTipManager
->hideToolTip();
513 // It is important to clear the items from the model before
514 // applying the view properties, otherwise expensive operations
515 // might be done on the existing items although they get cleared
516 // anyhow afterwards by loadDirectory().
517 fileItemModel()->clear();
518 applyViewProperties();
521 emit
urlChanged(url
);
524 void DolphinView::selectAll()
526 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
527 selectionManager
->setSelected(0, fileItemModel()->count());
530 void DolphinView::invertSelection()
532 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
533 selectionManager
->setSelected(0, fileItemModel()->count(), KItemListSelectionManager::Toggle
);
536 void DolphinView::clearSelection()
538 m_container
->controller()->selectionManager()->clearSelection();
541 void DolphinView::renameSelectedItems()
543 KFileItemList items
= selectedItems();
544 const int itemCount
= items
.count();
549 /*if ((itemCount == 1) && DolphinSettings::instance().generalSettings()->renameInline()) {
550 const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForItem(items.first());
551 const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
552 m_viewAccessor.itemView()->edit(proxyIndex);
554 RenameDialog
* dialog
= new RenameDialog(this, items
);
555 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
558 dialog
->activateWindow();
561 // assure that the current index remains visible when KDirLister
562 // will notify the view about changed items
563 m_assureVisibleCurrentIndex
= true;
566 void DolphinView::trashSelectedItems()
568 const KUrl::List list
= simplifiedSelectedUrls();
569 KonqOperations::del(this, KonqOperations::TRASH
, list
);
572 void DolphinView::deleteSelectedItems()
574 const KUrl::List list
= simplifiedSelectedUrls();
575 const bool del
= KonqOperations::askDeleteConfirmation(list
,
577 KonqOperations::DEFAULT_CONFIRMATION
,
581 KIO::Job
* job
= KIO::del(list
);
582 connect(job
, SIGNAL(result(KJob
*)),
583 this, SLOT(slotDeleteFileFinished(KJob
*)));
587 void DolphinView::cutSelectedItems()
589 QMimeData
* mimeData
= selectionMimeData();
590 KonqMimeData::addIsCutSelection(mimeData
, true);
591 QApplication::clipboard()->setMimeData(mimeData
);
594 void DolphinView::copySelectedItems()
596 QMimeData
* mimeData
= selectionMimeData();
597 QApplication::clipboard()->setMimeData(mimeData
);
600 void DolphinView::paste()
605 void DolphinView::pasteIntoFolder()
607 const KFileItemList items
= selectedItems();
608 if ((items
.count() == 1) && items
.first().isDir()) {
609 pasteToUrl(items
.first().url());
613 void DolphinView::setPreviewsShown(bool show
)
615 if (previewsShown() == show
) {
619 ViewProperties
props(url());
620 props
.setPreviewsShown(show
);
622 m_container
->setPreviewsShown(show
);
623 emit
previewsShownChanged(show
);
626 void DolphinView::setHiddenFilesShown(bool show
)
628 if (m_dirLister
->showingDotFiles() == show
) {
632 m_selectedItems
= selectedItems();
634 ViewProperties
props(url());
635 props
.setHiddenFilesShown(show
);
637 m_dirLister
->setShowingDotFiles(show
);
638 m_dirLister
->emitChanges();
639 emit
hiddenFilesShownChanged(show
);
642 void DolphinView::setCategorizedSorting(bool categorized
)
644 if (categorized
== categorizedSorting()) {
648 ViewProperties
props(url());
649 props
.setCategorizedSorting(categorized
);
652 //m_viewAccessor.proxyModel()->setCategorizedModel(categorized);
654 emit
categorizedSortingChanged(categorized
);
657 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
659 QWidget::mouseReleaseEvent(event
);
663 void DolphinView::contextMenuEvent(QContextMenuEvent
* event
)
667 const QPoint pos
= m_container
->mapFromGlobal(QCursor::pos());
668 const KItemListView
* view
= m_container
->controller()->view();
669 if (view
->itemAt(pos
) < 0) {
670 // Only open the context-menu if the cursor is above the viewport
671 // (the context-menu for items is handled in slotItemClicked())
672 requestContextMenu(KFileItem(), url(), QList
<QAction
*>());
676 void DolphinView::activate()
681 void DolphinView::slotItemClicked(int index
, Qt::MouseButton button
)
683 const KFileItem item
= fileItemModel()->fileItem(index
);
685 if (button
& Qt::LeftButton
) {
686 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
687 } else if (button
& Qt::MidButton
) {
688 if (item
.isDir() || isTabsForFilesEnabled()) {
689 emit
tabRequested(item
.url());
691 } else if (button
& Qt::RightButton
) {
692 if (GeneralSettings::showToolTips()) {
693 m_toolTipManager
->hideToolTip();
695 emit
requestContextMenu(item
, url(), QList
<QAction
*>());
699 void DolphinView::slotItemExpansionToggleClicked(int index
)
701 // TODO: When doing a model->setExpanded(false) it should
702 // be checked here whether the current index is part of the
703 // closed sub-tree. If this is the case, the current index
704 // should be adjusted to the parent index.
705 KFileItemModel
* model
= fileItemModel();
706 const bool expanded
= model
->isExpanded(index
);
707 model
->setExpanded(index
, !expanded
);
710 void DolphinView::slotItemHovered(int index
)
712 const KFileItem item
= fileItemModel()->fileItem(index
);
714 if (GeneralSettings::showToolTips()) {
715 QRectF itemRect
= m_container
->controller()->view()->itemBoundingRect(index
);
716 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
717 itemRect
.moveTo(pos
);
719 m_toolTipManager
->showToolTip(item
, itemRect
);
722 emit
requestItemInfo(item
);
725 void DolphinView::slotItemUnhovered(int index
)
728 if (GeneralSettings::showToolTips()) {
729 m_toolTipManager
->hideToolTip();
731 emit
requestItemInfo(KFileItem());
734 void DolphinView::slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
)
736 const int currentCount
= current
.count();
737 const int previousCount
= previous
.count();
738 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
739 (currentCount
> 0 && previousCount
== 0);
741 // If nothing has been selected before and something got selected (or if something
742 // was selected before and now nothing is selected) the selectionChangedSignal must
743 // be emitted asynchronously as fast as possible to update the edit-actions.
744 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
745 m_selectionChangedTimer
->start();
748 void DolphinView::emitSelectionChangedSignal()
750 m_selectionChangedTimer
->stop();
751 emit
selectionChanged(selectedItems());
754 void DolphinView::openContextMenu(const QPoint
& pos
,
755 const QList
<QAction
*>& customActions
)
758 const int index
= m_container
->controller()->view()->itemAt(pos
);
760 item
= fileItemModel()->fileItem(index
);
763 emit
requestContextMenu(item
, url(), customActions
);
766 void DolphinView::dropUrls(const KFileItem
& destItem
,
767 const KUrl
& destPath
,
772 markPastedUrlsAsSelected(event
->mimeData());
773 //DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
776 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
778 ViewProperties
props(url());
779 props
.setSorting(sorting
);
781 KItemModelBase
* model
= m_container
->controller()->model();
782 model
->setSortRole(sortRoleForSorting(sorting
));
784 emit
sortingChanged(sorting
);
787 void DolphinView::updateSortOrder(Qt::SortOrder order
)
789 ViewProperties
props(url());
790 props
.setSortOrder(order
);
792 //m_viewAccessor.proxyModel()->setSortOrder(order);
794 emit
sortOrderChanged(order
);
797 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
799 ViewProperties
props(url());
800 props
.setSortFoldersFirst(foldersFirst
);
802 //m_viewAccessor.proxyModel()->setSortFoldersFirst(foldersFirst);
804 emit
sortFoldersFirstChanged(foldersFirst
);
807 QPair
<bool, QString
> DolphinView::pasteInfo() const
809 return KonqOperations::pasteInfo(url());
812 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
814 m_tabsForFiles
= tabsForFiles
;
817 bool DolphinView::isTabsForFilesEnabled() const
819 return m_tabsForFiles
;
822 bool DolphinView::itemsExpandable() const
824 return false; //m_viewAccessor.itemsExpandable();
827 void DolphinView::restoreState(QDataStream
& stream
)
829 // Restore the current item that had the keyboard focus
830 stream
>> m_currentItemIndex
;
832 // Restore the view position
833 stream
>> m_restoredContentsPosition
;
835 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
836 QSet
<KUrl
> urlsToExpand
;
837 stream
>> urlsToExpand
;
838 /*const DolphinDetailsViewExpander* expander = m_viewAccessor.setExpandedUrls(urlsToExpand);
840 m_expanderActive = true;
841 connect (expander, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
844 m_expanderActive = false;
848 void DolphinView::saveState(QDataStream
& stream
)
850 // Save the current item that has the keyboard focus
851 stream
<< m_container
->controller()->selectionManager()->currentItem();
853 // Save view position
854 const qreal x
= m_container
->horizontalScrollBar()->value();
855 const qreal y
= m_container
->verticalScrollBar()->value();
856 stream
<< QPoint(x
, y
);
858 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
859 //stream << m_viewAccessor.expandedUrls();
862 bool DolphinView::hasSelection() const
864 return m_container
->controller()->selectionManager()->hasSelection();
867 KFileItem
DolphinView::rootItem() const
869 return m_dirLister
->rootItem();
872 void DolphinView::observeCreatedItem(const KUrl
& url
)
874 m_createdItemUrl
= url
;
875 //connect(m_dirModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
876 // this, SLOT(selectAndScrollToCreatedItem()));
879 void DolphinView::selectAndScrollToCreatedItem()
881 /*const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForUrl(m_createdItemUrl);
882 if (dirIndex.isValid()) {
883 const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
884 QAbstractItemView* view = m_viewAccessor.itemView();
886 view->setCurrentIndex(proxyIndex);
890 disconnect(m_viewAccessor.dirModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
891 this, SLOT(selectAndScrollToCreatedItem()));*/
892 m_createdItemUrl
= KUrl();
895 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
897 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
898 emit
redirection(oldUrl
, newUrl
);
899 m_url
= newUrl
; // #186947
903 void DolphinView::updateViewState()
905 if (m_currentItemIndex
>= 0) {
906 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
907 selectionManager
->setCurrentItem(m_currentItemIndex
);
908 m_currentItemIndex
=-1;
911 if (!m_restoredContentsPosition
.isNull()) {
912 const int x
= m_restoredContentsPosition
.x();
913 const int y
= m_restoredContentsPosition
.y();
914 m_restoredContentsPosition
= QPoint();
916 m_container
->horizontalScrollBar()->setValue(x
);
917 m_container
->verticalScrollBar()->setValue(y
);
920 if (!m_selectedItems
.isEmpty()) {
921 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
922 QSet
<int> selectedItems
= selectionManager
->selectedItems();
923 const KFileItemModel
* model
= fileItemModel();
925 foreach (const KFileItem
& selectedItem
, m_selectedItems
) {
926 const int index
= model
->index(selectedItem
);
928 selectedItems
.insert(index
);
932 selectionManager
->setSelectedItems(selectedItems
);
933 m_selectedItems
.clear();
937 void DolphinView::showHoverInformation(const KFileItem
& item
)
939 emit
requestItemInfo(item
);
942 void DolphinView::clearHoverInformation()
944 emit
requestItemInfo(KFileItem());
947 void DolphinView::slotDeleteFileFinished(KJob
* job
)
949 if (job
->error() == 0) {
950 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
951 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
952 emit
errorMessage(job
->errorString());
956 void DolphinView::slotDirListerStarted(const KUrl
& url
)
958 // Disable the writestate temporary until it can be determined in a fast way
959 // in DolphinView::slotDirListerCompleted()
960 if (m_isFolderWritable
) {
961 m_isFolderWritable
= false;
962 emit
writeStateChanged(m_isFolderWritable
);
965 emit
startedPathLoading(url
);
968 void DolphinView::slotDirListerCompleted()
970 // Update the view-state. This has to be done using a Qt::QueuedConnection
971 // because the view might not be in its final state yet (the view also
972 // listens to the completed()-signal from KDirLister and the order of
973 // of slots is undefined).
974 QTimer::singleShot(0, this, SLOT(updateViewState()));
976 emit
finishedPathLoading(url());
978 updateWritableState();
981 void DolphinView::slotRefreshItems()
983 if (m_assureVisibleCurrentIndex
) {
984 m_assureVisibleCurrentIndex
= false;
985 //QAbstractItemView* view = m_viewAccessor.itemView();
987 // m_viewAccessor.itemView()->scrollTo(m_viewAccessor.itemView()->currentIndex());
992 KFileItemModel
* DolphinView::fileItemModel() const
994 return static_cast<KFileItemModel
*>(m_container
->controller()->model());
997 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
999 if (!url
.isValid()) {
1000 const QString
location(url
.pathOrUrl());
1001 if (location
.isEmpty()) {
1002 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1004 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1009 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1012 void DolphinView::applyViewProperties()
1014 m_container
->beginTransaction();
1016 const ViewProperties
props(url());
1018 const Mode mode
= props
.viewMode();
1019 if (m_mode
!= mode
) {
1020 const Mode previousMode
= m_mode
;
1023 // Changing the mode might result in changing
1024 // the zoom level. Remember the old zoom level so
1025 // that zoomLevelChanged() can get emitted.
1026 const int oldZoomLevel
= m_container
->zoomLevel();
1029 case IconsView
: m_container
->setItemLayout(KFileItemListView::IconsLayout
); break;
1030 case CompactView
: m_container
->setItemLayout(KFileItemListView::CompactLayout
); break;
1031 case DetailsView
: m_container
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1032 default: Q_ASSERT(false); break;
1035 emit
modeChanged(m_mode
, previousMode
);
1037 if (m_container
->zoomLevel() != oldZoomLevel
) {
1038 emit
zoomLevelChanged(m_container
->zoomLevel(), oldZoomLevel
);
1042 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1043 if (hiddenFilesShown
!= m_dirLister
->showingDotFiles()) {
1044 m_dirLister
->setShowingDotFiles(hiddenFilesShown
);
1045 m_dirLister
->emitChanges();
1046 emit
hiddenFilesShownChanged(hiddenFilesShown
);
1049 /* m_storedCategorizedSorting = props.categorizedSorting();
1050 const bool categorized = m_storedCategorizedSorting && supportsCategorizedSorting();
1051 if (categorized != m_viewAccessor.proxyModel()->isCategorizedModel()) {
1052 m_viewAccessor.proxyModel()->setCategorizedModel(categorized);
1053 emit categorizedSortingChanged();
1056 const DolphinView::Sorting sorting
= props
.sorting();
1057 KItemModelBase
* model
= m_container
->controller()->model();
1058 const QByteArray newSortRole
= sortRoleForSorting(sorting
);
1059 if (newSortRole
!= model
->sortRole()) {
1060 model
->setSortRole(newSortRole
);
1061 emit
sortingChanged(sorting
);
1064 const Qt::SortOrder sortOrder = props.sortOrder();
1065 if (sortOrder != m_viewAccessor.proxyModel()->sortOrder()) {
1066 m_viewAccessor.proxyModel()->setSortOrder(sortOrder);
1067 emit sortOrderChanged(sortOrder);
1070 const bool sortFoldersFirst = props.sortFoldersFirst();
1071 if (sortFoldersFirst != m_viewAccessor.proxyModel()->sortFoldersFirst()) {
1072 m_viewAccessor.proxyModel()->setSortFoldersFirst(sortFoldersFirst);
1073 emit sortFoldersFirstChanged(sortFoldersFirst);
1076 const QList
<DolphinView::AdditionalInfo
> infoList
= props
.additionalInfoList();
1077 if (infoList
!= m_additionalInfoList
) {
1078 const QList
<DolphinView::AdditionalInfo
> previousList
= m_additionalInfoList
;
1079 m_additionalInfoList
= infoList
;
1080 applyAdditionalInfoListToView();
1081 emit
additionalInfoListChanged(m_additionalInfoList
, previousList
);
1084 const bool previewsShown
= props
.previewsShown();
1085 if (previewsShown
!= m_container
->previewsShown()) {
1086 const int oldZoomLevel
= zoomLevel();
1088 m_container
->setPreviewsShown(previewsShown
);
1089 emit
previewsShownChanged(previewsShown
);
1091 // Changing the preview-state might result in a changed zoom-level
1092 if (oldZoomLevel
!= zoomLevel()) {
1093 emit
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1097 m_container
->endTransaction();
1100 void DolphinView::applyAdditionalInfoListToView()
1102 const AdditionalInfoAccessor
& infoAccessor
= AdditionalInfoAccessor::instance();
1104 QHash
<QByteArray
, int> visibleRoles
;
1105 visibleRoles
.insert("name", 0);
1108 foreach (AdditionalInfo info
, m_additionalInfoList
) {
1109 visibleRoles
.insert(infoAccessor
.role(info
), index
);
1113 m_container
->setVisibleRoles(visibleRoles
);
1116 void DolphinView::pasteToUrl(const KUrl
& url
)
1118 markPastedUrlsAsSelected(QApplication::clipboard()->mimeData());
1119 KonqOperations::doPaste(this, url
);
1122 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1124 Q_UNUSED(oldZoomLevel
);
1125 /* const int newZoomLevel = ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor.itemView()->iconSize());
1126 if (oldZoomLevel != newZoomLevel) {
1127 m_viewModeController->setZoomLevel(newZoomLevel);
1128 emit zoomLevelChanged(newZoomLevel);
1132 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1134 Q_ASSERT(false); // TODO
1137 const KFileItemList items = selectedItems();
1138 foreach (const KFileItem &item, items) {
1139 urls.append(item.url());
1143 if (itemsExpandable()) {
1144 urls = KDirModel::simplifiedUrlList(urls);
1150 QMimeData
* DolphinView::selectionMimeData() const
1152 /*const QAbstractItemView* view = m_viewAccessor.itemView();
1153 Q_ASSERT((view) && (view->selectionModel()));
1154 const QItemSelection selection = m_viewAccessor.proxyModel()->mapSelectionToSource(view->selectionModel()->selection());
1155 return m_viewAccessor.dirModel()->mimeData(selection.indexes());*/
1159 void DolphinView::markPastedUrlsAsSelected(const QMimeData
* mimeData
)
1161 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1162 markUrlsAsSelected(urls
);
1165 QItemSelection
DolphinView::childrenMatchingPattern(const QModelIndex
& parent
, const QRegExp
& pattern
) const
1169 QItemSelection matchingIndexes
;
1170 /*const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel();
1171 const DolphinModel* dolphinModel = m_viewAccessor.dirModel();
1173 const int rowCount = proxyModel->rowCount(parent);
1175 for (int row = 0; row < rowCount; ++row) {
1176 QModelIndex index = proxyModel->index(row, 0, parent);
1177 QModelIndex sourceIndex = proxyModel->mapToSource(index);
1179 if (sourceIndex.isValid() && pattern.exactMatch(dolphinModel->data(sourceIndex).toString())) {
1180 matchingIndexes += QItemSelectionRange(index);
1183 if (proxyModel->hasChildren(index)) {
1184 matchingIndexes += childrenMatchingPattern(index, pattern);
1188 return matchingIndexes
;
1191 void DolphinView::updateWritableState()
1193 const bool wasFolderWritable
= m_isFolderWritable
;
1194 m_isFolderWritable
= true;
1196 const KFileItem item
= m_dirLister
->rootItem();
1197 if (!item
.isNull()) {
1198 KFileItemListProperties
capabilities(KFileItemList() << item
);
1199 m_isFolderWritable
= capabilities
.supportsWriting();
1201 if (m_isFolderWritable
!= wasFolderWritable
) {
1202 emit
writeStateChanged(m_isFolderWritable
);
1206 QByteArray
DolphinView::sortRoleForSorting(Sorting sorting
) const
1209 case SortByName
: return "name";
1210 case SortBySize
: return "size";
1211 case SortByDate
: return "date";
1212 case SortByPermissions
: return "permissions";
1213 case SortByOwner
: return "owner";
1214 case SortByGroup
: return "group";
1215 case SortByType
: return "type";
1216 case SortByDestination
: return "destination";
1217 case SortByPath
: return "path";
1221 return QByteArray();
1224 #include "dolphinview.moc"