this, SLOT(emitSelectionChangedSignal()));
applyViewProperties();
- m_topLayout->addWidget(m_viewAccessor.itemView());
+ m_topLayout->addWidget(m_viewAccessor.layoutTarget());
}
DolphinView::~DolphinView()
const int oldZoomLevel = m_controller->zoomLevel();
m_mode = mode;
+ // remember the currently selected items, so that they will
+ // be restored after reloading the directory
+ m_selectedItems = selectedItems();
+
deleteView();
const KUrl viewPropsUrl = rootUrl();
emit modeChanged();
updateZoomLevel(oldZoomLevel);
- if (m_showPreview) {
- loadDirectory(viewPropsUrl);
- }
+ loadDirectory(viewPropsUrl);
}
DolphinView::Mode DolphinView::mode() const
bool DolphinView::hasSelection() const
{
const QAbstractItemView* view = m_viewAccessor.itemView();
- return view && view->selectionModel()->hasSelection();
+ return (view != 0) && view->selectionModel()->hasSelection();
+}
+
+void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
+{
+ foreach (const KUrl& url, urls) {
+ KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+ m_selectedItems.append(item);
+ }
}
KFileItemList DolphinView::selectedItems() const
{
+ KFileItemList itemList;
const QAbstractItemView* view = m_viewAccessor.itemView();
-
- // Our view has a selection, we will map them back to the DolphinModel
- // and then fill the KFileItemList.
- Q_ASSERT((view != 0) && (view->selectionModel() != 0));
+ if (view == 0) {
+ return itemList;
+ }
const QItemSelection selection = m_viewAccessor.proxyModel()->mapSelectionToSource(view->selectionModel()->selection());
- KFileItemList itemList;
const QModelIndexList indexList = selection.indexes();
foreach (const QModelIndex &index, indexList) {
int DolphinView::selectedItemsCount() const
{
- return m_viewAccessor.itemView()->selectionModel()->selectedIndexes().count();
+ const QAbstractItemView* view = m_viewAccessor.itemView();
+ if (view == 0) {
+ return 0;
+ }
+
+ return view->selectionModel()->selectedIndexes().count();
}
QItemSelectionModel* DolphinView::selectionModel() const
void DolphinView::reload()
{
+ QByteArray viewState;
+ QDataStream saveStream(&viewState, QIODevice::WriteOnly);
+ saveState(saveStream);
+ m_selectedItems= selectedItems();
+
setUrl(url());
loadDirectory(url(), true);
+
+ QDataStream restoreStream(viewState);
+ restoreState(restoreStream);
}
void DolphinView::refresh()
if (folderCount + fileCount == 1) {
// if only one item is selected, show the filename
- const QString name = list.first().name();
+ const QString name = list.first().text();
text = (folderCount == 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name) :
i18nc("@info:status", "<filename>%1</filename> selected (%2)",
name, KIO::convertSize(totalFileSize));
void DolphinView::selectAll()
{
- QAbstractItemView* view = m_viewAccessor.itemView();
- // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
- // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
- // selection instead of selecting all items. This is bypassed for KDE 4.0
- // by invoking clearSelection() first.
- view->clearSelection();
- view->selectAll();
+ m_viewAccessor.itemView()->selectAll();
}
void DolphinView::invertSelection()
void DolphinView::clearSelection()
{
- QItemSelectionModel* selModel = m_viewAccessor.itemView()->selectionModel();
- const QModelIndex currentIndex = selModel->currentIndex();
- selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current |
- QItemSelectionModel::Clear);
- m_selectedItems.clear();
-}
-
-void DolphinView::changeSelection(const KFileItemList& selection)
-{
- clearSelection();
- if (selection.isEmpty()) {
- return;
- }
- const KUrl& baseUrl = url();
- KUrl url;
- QItemSelection newSelection;
- foreach(const KFileItem& item, selection) {
- url = item.url().upUrl();
- if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
- QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
- newSelection.select(index, index);
- }
- }
- m_viewAccessor.itemView()->selectionModel()->select(newSelection,
- QItemSelectionModel::ClearAndSelect
- | QItemSelectionModel::Current);
+ m_viewAccessor.itemView()->clearSelection();
}
void DolphinView::renameSelectedItems()
}
}
break;
-
+
default:
break;
}
emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
}
-void DolphinView::emitDelayedSelectionChangedSignal()
+void DolphinView::slotSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
- // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
- // that fast selection changes don't result in expensive operations to
- // collect all file items for the signal (see DolphinView::selectedItems()).
+ const int count = selectedItemsCount();
+ const bool selectionStateChanged = ((count > 0) && (selected.count() == count)) ||
+ ((count == 0) && !deselected.isEmpty());
+
+ // If nothing has been selected before and something got selected (or if something
+ // was selected before and now nothing is selected) the selectionChangedSignal must
+ // be emitted asynchronously as fast as possible to update the edit-actions.
+ m_selectionChangedTimer->setInterval(selectionStateChanged ? 0 : 300);
m_selectionChangedTimer->start();
}
m_createdItemUrl = KUrl();
}
-void DolphinView::restoreSelection()
-{
- disconnect(m_viewAccessor.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
- changeSelection(m_selectedItems);
-}
-
void DolphinView::emitContentsMoved()
{
// TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
void DolphinView::slotLoadingCompleted()
{
m_expanderActive = false;
- m_loadingDirectory = false;
+ m_loadingDirectory = false;
if (!m_activeItemUrl.isEmpty()) {
// assure that the current item remains visible
}
}
+ if (!m_selectedItems.isEmpty()) {
+ const KUrl& baseUrl = url();
+ KUrl url;
+ QItemSelection newSelection;
+ foreach(const KFileItem& item, m_selectedItems) {
+ url = item.url().upUrl();
+ if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+ QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
+ newSelection.select(index, index);
+ }
+ }
+ m_viewAccessor.itemView()->selectionModel()->select(newSelection,
+ QItemSelectionModel::ClearAndSelect
+ | QItemSelectionModel::Current);
+ m_selectedItems.clear();
+ }
+
// Restore the contents position. This has to be done using a Qt::QueuedConnection
// because the view might not be in its final state yet.
QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection);
m_loadingDirectory = true;
m_expanderActive = false;
- if (reload) {
- m_selectedItems = selectedItems();
- connect(m_viewAccessor.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
- }
+ KDirLister* dirLister = m_viewAccessor.dirLister();
+ dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
- m_viewAccessor.dirLister()->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
+ KDirLister* rootDirLister = m_viewAccessor.rootDirLister();
+ if (dirLister != rootDirLister) {
+ // In the case of the column view the root directory lister can be different. Assure
+ // that it gets synchronized (clients from DolphinView are not aware that internally
+ // different directory listers are used).
+ rootDirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
+ }
}
void DolphinView::applyViewProperties()
view->viewport()->installEventFilter(this);
m_controller->setItemView(view);
- connect(m_controller, SIGNAL(selectionChanged()),
- this, SLOT(emitDelayedSelectionChangedSignal()));
// When changing the view mode, the selection is lost due to reinstantiating
// a new item view with a custom selection model. Pass the ownership of the
m_selectionModel = view->selectionModel();
}
m_selectionModel->setParent(this);
+ connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(emitContentsMoved()));
}
if(!m_detailsViewExpander.isNull()) {
- // Stop expanding items in the current folder
+ // stop expanding items in the current folder
m_detailsViewExpander->stop();
}
}
return (m_columnsContainer != 0) ? m_columnsContainer->rootUrl() : KUrl();
}
+KDirLister* DolphinView::ViewAccessor::rootDirLister() const
+{
+ return static_cast<DolphinModel*>(m_proxyModel->sourceModel())->dirLister();
+}
+
bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
{
return m_iconsView != 0;
QSet<KUrl> DolphinView::ViewAccessor::expandedUrls() const
{
- if(m_detailsView != 0) {
+ if (m_detailsView != 0) {
return m_detailsView->expandedUrls();
}
- else {
- return QSet<KUrl>();
- }
+
+ return QSet<KUrl>();
}
const DolphinDetailsViewExpander* DolphinView::ViewAccessor::setExpandedUrls(const QSet<KUrl>& urlsToExpand)
{
- if((m_detailsView != 0) && m_detailsView->itemsExpandable() && !urlsToExpand.isEmpty()) {
+ if ((m_detailsView != 0) && m_detailsView->itemsExpandable() && !urlsToExpand.isEmpty()) {
m_detailsViewExpander = new DolphinDetailsViewExpander(m_detailsView, urlsToExpand);
return m_detailsViewExpander;
}