]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Allow filtering of items also for the column view. A filtering of directories is...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 9 Oct 2007 22:32:54 +0000 (22:32 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 9 Oct 2007 22:32:54 +0000 (22:32 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=723536

src/dolphincolumnview.cpp
src/dolphincolumnview.h
src/dolphincolumnwidget.cpp
src/dolphincolumnwidget.h
src/dolphinview.cpp
src/dolphinview.h
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h

index e8b75c532f0122b5a7efbfbfc0ab800a5163334b..c0f08eaeb2b0edf3d5ff94aa51403ba4d1b78e84 100644 (file)
@@ -139,6 +139,18 @@ void DolphinColumnView::setRootUrl(const KUrl& url)
     m_columns[0]->setUrl(url);
 }
 
+void DolphinColumnView::setNameFilter(const QString& nameFilter)
+{
+    foreach (DolphinColumnWidget* column, m_columns) {
+        column->setNameFilter(nameFilter);
+    }
+}
+
+QString DolphinColumnView::nameFilter() const
+{
+    return activeColumn()->nameFilter();
+}
+
 KUrl DolphinColumnView::rootUrl() const
 {
     return m_columns[0]->url();
@@ -208,6 +220,10 @@ void DolphinColumnView::showColumn(const KUrl& url)
             columnIndex++;
 
             DolphinColumnWidget* column = new DolphinColumnWidget(viewport(), this, childUrl);
+            const QString filter = nameFilter();
+            if (!filter.isEmpty()) {
+                column->setNameFilter(filter);
+            }
             column->setActive(false);
 
             m_columns.append(column);
index 80228a84cc35261713f383f824872d45758532e1..95a16a80d9c509bdd8f2938c938de3bb854474de 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <QAbstractItemView>
 #include <QList>
+#include <QString>
 #include <QStyleOption>
 
 class DolphinColumnWidget;
@@ -69,6 +70,18 @@ public:
     /** Returns the URL of the first column. */
     KUrl rootUrl() const;
 
+    /**
+     * Filters the currently shown items by \a nameFilter. All items
+     * which contain the given filter string will be shown.
+     */
+    void setNameFilter(const QString& nameFilter);
+
+    /**
+     * Returns the currently used name filter. All items
+     * which contain the name filter will be shown.
+     */
+    QString nameFilter() const;
+
 public slots:
     /**
      * Shows the column which represents the URL \a url. If the column
index 38057362929eba3a8793a7b99b2842177f038d18..92fbd4e79064595bbd26090179d9b0f4f8fab91f 100644 (file)
@@ -190,6 +190,26 @@ void DolphinColumnWidget::updateBackground()
     update();
 }
 
+void DolphinColumnWidget::setNameFilter(const QString& nameFilter)
+{
+    // The name filter of KDirLister does a 'hard' filtering, which
+    // means that only the items are shown where the names match
+    // exactly the filter. This is non-transparent for the user, which
+    // just wants to have a 'soft' filtering: does the name contain
+    // the filter string?
+    QString adjustedFilter(nameFilter);
+    adjustedFilter.insert(0, '*');
+    adjustedFilter.append('*');
+
+    m_dirLister->setNameFilter(adjustedFilter);
+    m_dirLister->emitChanges();
+}
+
+QString DolphinColumnWidget::nameFilter() const
+{
+    return m_dirLister->nameFilter();
+}
+
 void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
index 03e0826588b952c154bb8f41a6cbcedafe6fba22..7636655a9383edf3d547be5c968fa8b4620b9533 100644 (file)
@@ -84,6 +84,19 @@ public:
      */
     void updateBackground();
 
+    /**
+     * Filters the currently shown items by \a nameFilter. All items
+     * which contain the given filter string will be shown.
+     */
+    void setNameFilter(const QString& nameFilter);
+
+    /**
+     * Returns the currently used name filter. All items
+     * which contain the name filter will be shown.
+     */
+    QString nameFilter() const;
+
+
 protected:
     virtual QStyleOptionViewItem viewOptions() const;
     virtual void dragEnterEvent(QDragEnterEvent* event);
index 8361ceb068b2710755b82b5429ebf8c7fea6e9fd..59341b65ba1bac676cab7a883cafd98ab6ae08d0 100644 (file)
@@ -493,6 +493,38 @@ void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
     emit startedPathLoading(url);
 }
 
+void DolphinView::setNameFilter(const QString& nameFilter)
+{
+    // The name filter of KDirLister does a 'hard' filtering, which
+    // means that only the items are shown where the names match
+    // exactly the filter. This is non-transparent for the user, which
+    // just wants to have a 'soft' filtering: does the name contain
+    // the filter string?
+    QString adjustedFilter(nameFilter);
+    adjustedFilter.insert(0, '*');
+    adjustedFilter.append('*');
+
+    m_dirLister->setNameFilter(adjustedFilter);
+    m_dirLister->emitChanges();
+
+    if (isColumnViewActive()) {
+        // adjusting the directory lister is not enough in the case of the
+        // column view, as each column has its own directory lister internally...
+        m_columnView->setNameFilter(nameFilter);
+    }
+}
+
+void DolphinView::calculateItemCount(int& fileCount, int& folderCount)
+{
+    foreach (KFileItem item, m_dirLister->items()) {
+        if (item.isDir()) {
+            ++folderCount;
+        } else {
+            ++fileCount;
+        }
+    }
+}
+
 void DolphinView::setUrl(const KUrl& url)
 {
     updateView(url, KUrl());
index 9291ea8b9d14704ccdbf76147d71f1ee294767a3..4e76c87c220788d4aaa75c8d3cdbb3de623c6118 100644 (file)
@@ -304,6 +304,21 @@ public:
      */
     void updateView(const KUrl& url, const KUrl& rootUrl);
 
+    /**
+     * Filters the currently shown items by \a nameFilter. All items
+     * which contain the given filter string will be shown.
+     */
+    void setNameFilter(const QString& nameFilter);
+
+    /**
+     * Calculates the number of currently shown files into
+     * \a fileCount and the number of folders into \a folderCount.
+     * It is recommend using this method instead of asking the
+     * directory lister or the model directly, as it takes
+     * filtering and hierarchical previews into account.
+     */
+    void calculateItemCount(int& fileCount, int& folderCount);
+
 public slots:
     /**
      * Changes the directory to \a url. If the current directory is equal to
@@ -319,6 +334,7 @@ public slots:
      */
     void changeSelection(const KFileItemList& selection);
 
+
 signals:
     /**
      * Is emitted if the view has been activated by e. g. a mouse click.
index 65e587fb244e9b2c9ec1bf7ed3fee143d870e1ac..1f419d099387669dde773e679b3aa33fe573b6fc 100644 (file)
@@ -62,8 +62,6 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
                                            const KUrl& url) :
     QWidget(parent),
     m_showProgress(false),
-    m_folderCount(0),
-    m_fileCount(0),
     m_mainWindow(mainWindow),
     m_topLayout(0),
     m_urlNavigator(0),
@@ -108,7 +106,7 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
     connect(m_dirLister, SIGNAL(deleteItem(const KFileItem&)),
             this, SLOT(updateStatusBar()));
     connect(m_dirLister, SIGNAL(completed()),
-            this, SLOT(updateItemCount()));
+            this, SLOT(slotDirListerCompleted()));
     connect(m_dirLister, SIGNAL(infoMessage(const QString&)),
             this, SLOT(showInfoMessage(const QString&)));
     connect(m_dirLister, SIGNAL(errorMessage(const QString&)),
@@ -148,7 +146,7 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
     m_filterBar = new FilterBar(this);
     m_filterBar->setVisible(settings->filterBar());
     connect(m_filterBar, SIGNAL(filterChanged(const QString&)),
-            this, SLOT(changeNameFilter(const QString&)));
+            this, SLOT(setNameFilter(const QString&)));
     connect(m_filterBar, SIGNAL(closeRequest()),
             this, SLOT(closeFilterBar()));
 
@@ -292,7 +290,7 @@ void DolphinViewContainer::updateProgress(int percent)
     }
 }
 
-void DolphinViewContainer::updateItemCount()
+void DolphinViewContainer::slotDirListerCompleted()
 {
     if (m_showProgress) {
         m_statusBar->setProgressText(QString());
@@ -300,23 +298,6 @@ void DolphinViewContainer::updateItemCount()
         m_showProgress = false;
     }
 
-    KFileItemList items(m_dirLister->items());
-    KFileItemList::const_iterator it = items.begin();
-    const KFileItemList::const_iterator end = items.end();
-
-    m_fileCount = 0;
-    m_folderCount = 0;
-
-    while (it != end) {
-        const KFileItem item = *it;
-        if (item.isDir()) {
-            ++m_folderCount;
-        } else {
-            ++m_fileCount;
-        }
-        ++it;
-    }
-
     updateStatusBar();
 
     QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
@@ -349,24 +330,12 @@ void DolphinViewContainer::closeFilterBar()
 
 QString DolphinViewContainer::defaultStatusBarText() const
 {
-    int m_fileCount = 0;
-    int m_folderCount = 0;
-
-    for (int i = 0; i < m_proxyModel->rowCount(); i++)
-    {
-        if (m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(m_proxyModel->index(i, m_proxyModel->sortColumn()))).isDir())
-        {
-            m_folderCount++;
-        }
-        else
-        {
-            m_fileCount++;
-        }
-    }
-
-    return KIO::itemsSummaryString(m_fileCount + m_folderCount,
-                                   m_fileCount,
-                                   m_folderCount,
+    int folderCount = 0;
+    int fileCount = 0;
+    m_view->calculateItemCount(fileCount, folderCount);
+    return KIO::itemsSummaryString(fileCount + folderCount,
+                                   fileCount,
+                                   folderCount,
                                    0, false);
 }
 
@@ -440,20 +409,9 @@ void DolphinViewContainer::updateStatusBar()
     }
 }
 
-void DolphinViewContainer::changeNameFilter(const QString& nameFilter)
+void DolphinViewContainer::setNameFilter(const QString& nameFilter)
 {
-    // The name filter of KDirLister does a 'hard' filtering, which
-    // means that only the items are shown where the names match
-    // exactly the filter. This is non-transparent for the user, which
-    // just wants to have a 'soft' filtering: does the name contain
-    // the filter string?
-    QString adjustedFilter(nameFilter);
-    adjustedFilter.insert(0, '*');
-    adjustedFilter.append('*');
-
-    m_dirLister->setNameFilter(adjustedFilter);
-    m_dirLister->emitChanges();
-
+    m_view->setNameFilter(nameFilter);
     updateStatusBar();
 }
 
index b908e6ea01f134e3150331bd10ed40b835d65087..abaf2e34e1e09ef8f5a5ca5567919665efce6a79 100644 (file)
@@ -145,10 +145,10 @@ private slots:
     void updateProgress(int percent);
 
     /**
-     * Updates the number of items (= number of directories + number of files)
-     * and shows this information in the statusbar.
+     * Assures that the viewport position is restored and updates the
+     * statusbar to reflect the current content.
      */
-    void updateItemCount();
+    void slotDirListerCompleted();
 
     /**
      * Handles clicking on an item
@@ -173,7 +173,7 @@ private slots:
      * Filters the currently shown items by \a nameFilter. All items
      * which contain the given filter string will be shown.
      */
-    void changeNameFilter(const QString& nameFilter);
+    void setNameFilter(const QString& nameFilter);
 
     /**
      * Opens the context menu on the current mouse position.
@@ -229,9 +229,6 @@ private:
 private:
     bool m_showProgress;
 
-    int m_folderCount;
-    int m_fileCount;
-
     DolphinMainWindow* m_mainWindow;
     QVBoxLayout* m_topLayout;
     KUrlNavigator* m_urlNavigator;