void DolphinColumnView::setModel(QAbstractItemModel* model)
{
+ if (m_dolphinModel != 0) {
+ m_dolphinModel->disconnect(this);
+ }
+
m_proxyModel = static_cast<const QAbstractProxyModel*>(model);
m_dolphinModel = static_cast<const DolphinModel*>(m_proxyModel->sourceModel());
+ connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)),
+ this, SLOT(triggerReloadColumns(const QModelIndex&)));
activeColumn()->setModel(model);
QAbstractItemView::setModel(model);
}
+void DolphinColumnView::reload()
+{
+ deleteInactiveChildColumns();
+
+ // Due to the reloading of the model all columns will be reset to show
+ // the same content as the first column. As this is not wanted, all columns
+ // except of the first column are temporary hidden until the root index can
+ // be updated again.
+ QList<ColumnWidget*>::iterator start = m_columns.begin() + 1;
+ QList<ColumnWidget*>::iterator end = m_columns.end();
+ for (QList<ColumnWidget*>::iterator it = start; it != end; ++it) {
+ (*it)->hide();
+ (*it)->setRootIndex(QModelIndex());
+ }
+
+ // all columns are hidden, now reload the directory lister
+ KDirLister* dirLister = m_dolphinModel->dirLister();
+ connect(dirLister, SIGNAL(completed()),
+ this, SLOT(expandToActiveUrl()));
+ const KUrl baseUrl = m_columns[0]->url();
+ dirLister->openUrl(baseUrl, false, true);
+}
+
bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const
{
Q_UNUSED(index);
QRegion DolphinColumnView::visualRegionForSelection(const QItemSelection& selection) const
{
+ Q_UNUSED(selection);
return QRegion(); //activeColumn()->visualRegionForSelection(selection);
}
doItemsLayout();
}
+void DolphinColumnView::expandToActiveUrl()
+{
+ const KUrl& activeUrl = m_controller->url();
+ const KUrl baseUrl = m_dolphinModel->dirLister()->url();
+ if (baseUrl.isParentOf(activeUrl) && (baseUrl != activeUrl)) {
+ m_dolphinModel->expandToUrl(activeUrl);
+ reloadColumns();
+ }
+}
+
+void DolphinColumnView::triggerReloadColumns(const QModelIndex& index)
+{
+ Q_UNUSED(index);
+ disconnect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)),
+ this, SLOT(triggerReloadColumns(const QModelIndex&)));
+ // the reloading of the columns may not be done in the context of this slot
+ QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection);
+}
+
+void DolphinColumnView::reloadColumns()
+{
+ const int count = m_columns.count() - 1; // ignore the last column
+ for (int i = 0; i < count; ++i) {
+ ColumnWidget* nextColumn = m_columns[i + 1];
+ const QModelIndex rootIndex = nextColumn->rootIndex();
+ if (!rootIndex.isValid()) {
+ const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_columns[i]->childUrl());
+ const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+ if (proxyIndex.isValid()) {
+ nextColumn->setRootIndex(proxyIndex);
+ nextColumn->show();
+ }
+ }
+ }
+}
+
bool DolphinColumnView::isZoomInPossible() const
{
ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
virtual QRect visualRect(const QModelIndex& index) const;
virtual void setModel(QAbstractItemModel* model);
+ /**
+ * Reloads the content of all columns. In opposite to non-hierarchical views
+ * it is not enough to reload the KDirLister, instead this method must be explicitly
+ * invoked.
+ */
+ void reload();
+
protected:
virtual bool isIndexHidden(const QModelIndex& index) const;
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
*/
void updateDecorationSize();
+ /**
+ * Expands the directory model the the currently active URL.
+ * Used by DolphinColumnView::reload() after the directory
+ * lister has been loaded.
+ */
+ void expandToActiveUrl();
+
+ /**
+ * Triggers the reloading of columns after the model index
+ * \a index has been expanded. Used by DolphinModel::expandToActiveUrl().
+ */
+ void triggerReloadColumns(const QModelIndex& index);
+
+ /**
+ * Adjusts the root index of all columns to represent the reloaded
+ * model. Used by DolphinModel::triggerReloadColumns().
+ */
+ void reloadColumns();
+
private:
bool isZoomInPossible() const;
bool isZoomOutPossible() const;
m_dirLister->stop();
- bool openDir = true;
bool keepOldDirs = isColumnViewActive() && !m_initializeColumnView;
m_initializeColumnView = false;
if (keepOldDirs) {
+ // keeping old directories is only necessary for hierarchical views
+ // like the column view
if (reload) {
- keepOldDirs = false;
-
- const KUrl& dirListerUrl = m_dirLister->url();
- if (dirListerUrl.isValid()) {
- const KUrl::List dirs = m_dirLister->directories();
- KUrl url;
- foreach(url, dirs) {
- m_dirLister->updateDirectory(url);
- }
- openDir = false;
- }
+ // for the column view it is not enough to reload the directory lister,
+ // so this task is delegated to the column view directly
+ m_columnView->reload();
} else if (m_dirLister->directories().contains(url)) {
// The dir lister contains the directory already, so
- // KDirLister::openUrl() may not been invoked twice.
+ // KDirLister::openUrl() may not get invoked twice.
m_dirLister->updateDirectory(url);
- openDir = false;
} else {
const KUrl& dirListerUrl = m_dirLister->url();
if ((dirListerUrl == url) || !m_dirLister->url().isParentOf(url)) {
// and hence the view must be reset.
keepOldDirs = false;
}
+ m_dirLister->openUrl(url, keepOldDirs, false);
}
- }
-
- if (openDir) {
- m_dirLister->openUrl(url, keepOldDirs, reload);
+ } else {
+ m_dirLister->openUrl(url, false, reload);
}
}