From: Peter Penz Date: Wed, 26 Sep 2007 08:39:58 +0000 (+0000) Subject: Listen to the directory lister signals to know whether the directory lister is still... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/8c9c081ead1b473ee05977708e33a746af7297c2?ds=inline Listen to the directory lister signals to know whether the directory lister is still working. This information is needed as KDirModel::expandToUrl() may never get invoked if the directory lister is still busy... svn path=/trunk/KDE/kdebase/apps/; revision=717188 --- diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index b748dad5e..8fd09074c 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include /** @@ -298,7 +299,7 @@ void ColumnWidget::keyPressEvent(QKeyEvent* event) && (event->key() == Qt::Key_Return) && (selModel->selectedIndexes().count() <= 1); if (triggerItem) { - m_view->triggerItem(currentIndex); + m_view->m_controller->triggerItem(currentIndex); } } @@ -340,10 +341,10 @@ void ColumnWidget::activate() // necessary connecting the signal 'singleClick()' or 'doubleClick'. if (KGlobalSettings::singleClick()) { connect(this, SIGNAL(clicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); } else { connect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); } const QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); @@ -369,10 +370,10 @@ void ColumnWidget::deactivate() // necessary connecting the signal 'singleClick()' or 'doubleClick'. if (KGlobalSettings::singleClick()) { disconnect(this, SIGNAL(clicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); } else { disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); } const QPalette palette = m_view->viewport()->palette(); @@ -388,7 +389,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control QAbstractItemView(parent), m_controller(controller), m_restoreActiveColumnFocus(false), - m_initializedDirLister(false), + m_dirListerCompleted(false), m_index(-1), m_contentX(0), m_columns(), @@ -475,6 +476,12 @@ 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); } @@ -520,7 +527,7 @@ void DolphinColumnView::reload() connect(dirLister, SIGNAL(completed()), this, SLOT(expandToActiveUrl())); const KUrl& rootUrl = m_columns[0]->url(); - m_initializedDirLister = dirLister->openUrl(m_columns[0]->url(), false, true); + dirLister->openUrl(rootUrl, false, true); reloadColumns(); } @@ -639,13 +646,14 @@ void DolphinColumnView::showColumn(const KUrl& url) m_index = columnIndex; activeColumn()->setActive(true); - if (m_initializedDirLister) { - // expanding the active URL may only be done if the directory lister - // has been initialized - QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection); - } else { - QMetaObject::invokeMethod(this, "reload", Qt::QueuedConnection); - } + reloadColumns(); + + // reloadColumns() is enough for simple use cases where only one column is added. + // However when exchanging several columns a more complex synchronization must be + // done by invoking synchronize(). The delay is an optimization for default use + // cases and gives the directory lister the chance to be already finished when + // synchronize() is invoked, which assures zero flickering. + QTimer::singleShot(1000, this, SLOT(synchronize())); } void DolphinColumnView::selectAll() @@ -798,6 +806,7 @@ void DolphinColumnView::expandToActiveUrl() const bool expand = rootUrl.isParentOf(activeUrl) && !rootUrl.equals(activeUrl, KUrl::CompareWithoutTrailingSlash); if (expand) { + Q_ASSERT(m_dirListerCompleted); m_dolphinModel->expandToUrl(activeUrl); } reloadColumns(); @@ -835,10 +844,27 @@ void DolphinColumnView::reloadColumns() assureVisibleActiveColumn(); } -void DolphinColumnView::triggerItem(const QModelIndex& index) +void DolphinColumnView::synchronize() +{ + if (m_dirListerCompleted) { + // expanding the active URL may only be done if the directory lister + // has been completed the loading + expandToActiveUrl(); + } else { + reload(); + } +} + + +void DolphinColumnView::slotDirListerStarted(const KUrl& url) +{ + Q_UNUSED(url); + m_dirListerCompleted = false; +} + +void DolphinColumnView::slotDirListerCompleted() { - m_initializedDirLister = true; - m_controller->triggerItem(index); + m_dirListerCompleted = true; } bool DolphinColumnView::isZoomInPossible() const diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 5a20b1f9f..511d4d7e5 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -53,7 +53,6 @@ public: /** Inverts the selection of the currently active column. */ void invertSelection(); -public slots: /** * 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 @@ -61,6 +60,7 @@ public slots: */ void reload(); +public slots: /** * Shows the column which represents the URL \a url. If the column * is already shown, it gets activated, otherwise it will be created. @@ -118,7 +118,25 @@ private slots: */ void reloadColumns(); - void triggerItem(const QModelIndex& index); + /** + * Synchronizes the current state of the directory lister with + * the currently shown columns. This is required if the directory + * lister has been changed from outside without user interaction. + */ + void synchronize(); + + /** + * Is invoked when the directory lister has started the loading + * of the URL \a url and sets the internal m_dirListerCompleted + * state to false. + */ + void slotDirListerStarted(const KUrl& url); + + /** + * Is invoked when the directory lister has completed the loading + * and sets the internal m_dirListerCompleted state to true. + */ + void slotDirListerCompleted(); private: bool isZoomInPossible() const; @@ -153,7 +171,7 @@ private: private: DolphinController* m_controller; bool m_restoreActiveColumnFocus; - bool m_initializedDirLister; + bool m_dirListerCompleted; int m_index; int m_contentX; QList m_columns;