]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Listen to the directory lister signals to know whether the directory lister is still...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 26 Sep 2007 08:39:58 +0000 (08:39 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 26 Sep 2007 08:39:58 +0000 (08:39 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=717188

src/dolphincolumnview.cpp
src/dolphincolumnview.h

index b748dad5e607aa017c36df4404131daad5ad3422..8fd09074c9cab44bccdf869ab1f4a3ba47310e6b 100644 (file)
@@ -33,6 +33,7 @@
 #include <QApplication>
 #include <QPoint>
 #include <QScrollBar>
+#include <QTimer>
 #include <QTimeLine>
 
 /**
@@ -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
index 5a20b1f9f45999808420f9a8a6f945eb2548b8dd..511d4d7e5a309b6a31d3f46266c1cfcc244f9974 100644 (file)
@@ -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<ColumnWidget*> m_columns;