X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/93f8093b661d6cd8db6dd747fbdfe38ebd38294b..093efca22dfd247f06e2a669ad968300e71ef08d:/src/dolphincolumnview.cpp diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index a85e0198a..3f6523ebe 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include /** @@ -386,6 +387,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control QAbstractItemView(parent), m_controller(controller), m_restoreActiveColumnFocus(false), + m_dirListerCompleted(false), m_index(-1), m_contentX(0), m_columns(), @@ -472,10 +474,33 @@ void DolphinColumnView::setModel(QAbstractItemModel* model) connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), this, SLOT(triggerReloadColumns(const QModelIndex&))); + KDirLister* dirLister = m_dolphinModel->dirLister(); + connect(dirLister, SIGNAL(started(const KUrl&)), + this, SLOT(slotDirListerStarted(const KUrl&))); + connect(dirLister, SIGNAL(completed()), + this, SLOT(slotDirListerCompleted())); + activeColumn()->setModel(model); QAbstractItemView::setModel(model); } +void DolphinColumnView::invertSelection() +{ + // TODO: this approach of inverting the selection is quite slow. It should + // be possible to speedup the implementation by using QItemSelection, but + // all adempts have failed yet... + + ColumnWidget* column = activeColumn(); + QItemSelectionModel* selModel = column->selectionModel(); + + KDirLister* dirLister = m_dolphinModel->dirLister(); + const KFileItemList list = dirLister->itemsForDir(column->url()); + foreach (KFileItem* item, list) { + const QModelIndex index = m_dolphinModel->indexForUrl(item->url()); + selModel->select(m_proxyModel->mapFromSource(index), QItemSelectionModel::Toggle); + } +} + void DolphinColumnView::reload() { // Due to the reloading of the model all columns will be reset to show @@ -493,31 +518,13 @@ void DolphinColumnView::reload() m_restoreActiveColumnFocus = true; } column->hide(); - } + } // all columns are hidden, now reload the directory lister KDirLister* dirLister = m_dolphinModel->dirLister(); - connect(dirLister, SIGNAL(completed()), - this, SLOT(expandToActiveUrl())); - const KUrl rootUrl = m_columns[0]->url(); + const KUrl& rootUrl = m_columns[0]->url(); dirLister->openUrl(rootUrl, false, true); -} - -void DolphinColumnView::invertSelection() -{ - // TODO: this approach of inverting the selection is quite slow. It should - // be possible to speedup the implementation by using QItemSelection, but - // all adempts have failed yet... - - ColumnWidget* column = activeColumn(); - QItemSelectionModel* selModel = column->selectionModel(); - - KDirLister* dirLister = m_dolphinModel->dirLister(); - const KFileItemList list = dirLister->itemsForDir(column->url()); - foreach (KFileItem* item, list) { - const QModelIndex index = m_dolphinModel->indexForUrl(item->url()); - selModel->select(m_proxyModel->mapFromSource(index), QItemSelectionModel::Toggle); - } + updateColumns(); } void DolphinColumnView::showColumn(const KUrl& url) @@ -634,10 +641,6 @@ void DolphinColumnView::showColumn(const KUrl& url) activeColumn()->setActive(false); m_index = columnIndex; activeColumn()->setActive(true); - - connect(dirLister, SIGNAL(completed()), - this, SLOT(expandToActiveUrl())); - dirLister->openUrl(rootUrl, false, true); } void DolphinColumnView::selectAll() @@ -780,34 +783,36 @@ void DolphinColumnView::updateDecorationSize() void DolphinColumnView::expandToActiveUrl() { - disconnect(m_dolphinModel->dirLister(), SIGNAL(completed()), - this, SLOT(expandToActiveUrl())); - const int lastIndex = m_columns.count() - 1; Q_ASSERT(lastIndex >= 0); const KUrl& activeUrl = m_columns[lastIndex]->url(); const KUrl rootUrl = m_dolphinModel->dirLister()->url(); - const bool expand = rootUrl.isParentOf(activeUrl) + const bool expand = m_dirListerCompleted + && rootUrl.isParentOf(activeUrl) && !rootUrl.equals(activeUrl, KUrl::CompareWithoutTrailingSlash); if (expand) { m_dolphinModel->expandToUrl(activeUrl); - reloadColumns(); } + updateColumns(); } -void DolphinColumnView::triggerReloadColumns(const QModelIndex& index) +void DolphinColumnView::triggerUpdateColumns(const QModelIndex& index) { Q_UNUSED(index); - // the reloading of the columns may not be done in the context of this slot - QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection); + // the updating of the columns may not be done in the context of this slot + QMetaObject::invokeMethod(this, "updateColumns", Qt::QueuedConnection); } -void DolphinColumnView::reloadColumns() +void DolphinColumnView::updateColumns() { + KDirLister* dirLister = m_dolphinModel->dirLister(); + foreach (ColumnWidget* column, m_columns) { + dirLister->updateDirectory(column->url()); + } + const int end = m_columns.count() - 2; // next to last column for (int i = 0; i <= end; ++i) { ColumnWidget* nextColumn = m_columns[i + 1]; - const QModelIndex rootIndex = nextColumn->rootIndex(); if (rootIndex.isValid()) { nextColumn->show(); @@ -827,6 +832,18 @@ void DolphinColumnView::reloadColumns() assureVisibleActiveColumn(); } +void DolphinColumnView::slotDirListerStarted(const KUrl& url) +{ + Q_UNUSED(url); + m_dirListerCompleted = false; +} + +void DolphinColumnView::slotDirListerCompleted() +{ + m_dirListerCompleted = true; + QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection); +} + bool DolphinColumnView::isZoomInPossible() const { ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();