]> cloud.milkyroute.net Git - dolphin.git/commitdiff
implemented reloading of all columns of the column view (just updating the directory...
authorPeter Penz <peter.penz19@gmail.com>
Fri, 21 Sep 2007 18:52:46 +0000 (18:52 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 21 Sep 2007 18:52:46 +0000 (18:52 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=715294

src/dolphincolumnview.cpp
src/dolphincolumnview.h
src/dolphinview.cpp

index 49434d64aac5f7a6a5f4755569a894489f95760d..6d4f584259ec03c746ae9f68684dd249460a6b60 100644 (file)
@@ -452,13 +452,42 @@ QRect DolphinColumnView::visualRect(const QModelIndex& index) const
 
 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);
@@ -513,6 +542,7 @@ void DolphinColumnView::setSelection(const QRect& rect, QItemSelectionModel::Sel
 
 QRegion DolphinColumnView::visualRegionForSelection(const QItemSelection& selection) const
 {
+    Q_UNUSED(selection);
     return QRegion(); //activeColumn()->visualRegionForSelection(selection);
 }
 
@@ -663,6 +693,42 @@ void DolphinColumnView::updateDecorationSize()
     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();
index ba5ed81011f2b146c25219db7bea61da44a8fba9..37deffd2cc44cd4bc20513ae4738447bf88a768b 100644 (file)
@@ -50,6 +50,13 @@ public:
     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);
@@ -86,6 +93,25 @@ private slots:
      */
     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;
index 2dd8e289bb95ee49192a1f41333520697ce0b3c2..d7e79f3302f32ea833fd33cf5a5a43daacb0f3e3 100644 (file)
@@ -505,28 +505,20 @@ void DolphinView::startDirLister(const KUrl& url, bool reload)
 
     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)) {
@@ -535,11 +527,10 @@ void DolphinView::startDirLister(const KUrl& url, bool reload)
                 // 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);
     }
 }