+QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const
+{
+ QItemSelection matchingIndexes;
+ const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel();
+ const DolphinModel* dolphinModel = m_viewAccessor.dirModel();
+
+ const int rowCount = proxyModel->rowCount(parent);
+
+ for (int row = 0; row < rowCount; ++row) {
+ QModelIndex index = proxyModel->index(row, 0, parent);
+ QModelIndex sourceIndex = proxyModel->mapToSource(index);
+
+ if (sourceIndex.isValid() && pattern.exactMatch(dolphinModel->data(sourceIndex).toString())) {
+ matchingIndexes += QItemSelectionRange(index);
+ }
+
+ if (proxyModel->hasChildren(index)) {
+ matchingIndexes += childrenMatchingPattern(index, pattern);
+ }
+ }
+
+ return matchingIndexes;
+}
+
+void DolphinView::connectViewAccessor()
+{
+ KDirLister* dirLister = m_viewAccessor.dirLister();
+ connect(dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl)));
+ connect(dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl)));
+ connect(dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
+ connect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
+ this, SLOT(slotRefreshItems()));
+
+ connect(dirLister, SIGNAL(clear()), this, SIGNAL(itemCountChanged()));
+ connect(dirLister, SIGNAL(newItems(KFileItemList)), this, SIGNAL(itemCountChanged()));
+ connect(dirLister, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&)));
+ connect(dirLister, SIGNAL(errorMessage(const QString&)), this, SIGNAL(infoMessage(const QString&)));
+ connect(dirLister, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int)));
+ connect(dirLister, SIGNAL(urlIsFileError(const KUrl&)), this, SIGNAL(urlIsFileError(const KUrl&)));
+ connect(dirLister, SIGNAL(itemsDeleted(const KFileItemList&)), this, SIGNAL(itemCountChanged()));
+
+ QAbstractItemView* view = m_viewAccessor.itemView();
+ connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+ this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
+}
+
+void DolphinView::disconnectViewAccessor()
+{
+ KDirLister* dirLister = m_viewAccessor.dirLister();
+ disconnect(dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl)));
+ disconnect(dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl)));
+ disconnect(dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
+ disconnect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
+ this, SLOT(slotRefreshItems()));
+
+ disconnect(dirLister, SIGNAL(clear()), this, SIGNAL(itemCountChanged()));
+ disconnect(dirLister, SIGNAL(newItems(KFileItemList)), this, SIGNAL(itemCountChanged()));
+ disconnect(dirLister, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&)));
+ disconnect(dirLister, SIGNAL(errorMessage(const QString&)), this, SIGNAL(errorMessage(const QString&)));
+ disconnect(dirLister, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int)));
+ disconnect(dirLister, SIGNAL(urlIsFileError(const KUrl&)), this, SIGNAL(urlIsFileError(const KUrl&)));
+ disconnect(dirLister, SIGNAL(itemsDeleted(const KFileItemList&)), this, SIGNAL(itemCountChanged()));
+
+ QAbstractItemView* view = m_viewAccessor.itemView();
+ disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+ this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
+}
+
+void DolphinView::updateWritableState()
+{
+ const bool wasFolderWritable = m_isFolderWritable;
+ m_isFolderWritable = true;
+
+ const KFileItem item = m_viewAccessor.dirLister()->rootItem();
+ if (!item.isNull()) {
+ KFileItemListProperties capabilities(KFileItemList() << item);
+ m_isFolderWritable = capabilities.supportsWriting();
+ }
+ if (m_isFolderWritable != wasFolderWritable) {
+ emit writeStateChanged(m_isFolderWritable);
+ }
+}
+
+DolphinView::ViewAccessor::ViewAccessor() :
+ m_rootUrl(),