[vlmc-devel] commit: MediaLibrary: Enable filtering by name. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Fri May 14 18:51:25 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Thu May 13 20:51:54 2010 +0200| [eb9b7604360bd2d206b2d544d610a6e57956166c] | committer: Hugo Beauzée-Luyssen 

MediaLibrary: Enable filtering by name.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=eb9b7604360bd2d206b2d544d610a6e57956166c
---

 src/Gui/library/MediaCellView.cpp  |    6 ++++++
 src/Gui/library/MediaCellView.h    |    1 +
 src/Gui/library/MediaLibrary.cpp   |   33 +++++++++++++++++++++++++++++----
 src/Gui/library/MediaLibrary.h     |   15 +++++++++++++++
 src/Gui/library/MediaListView.cpp  |    6 ++++++
 src/Gui/library/MediaListView.h    |    6 +++++-
 src/Gui/library/ui/MediaLibrary.ui |   14 +++++++-------
 7 files changed, 69 insertions(+), 12 deletions(-)

diff --git a/src/Gui/library/MediaCellView.cpp b/src/Gui/library/MediaCellView.cpp
index 3ad0c3b..3960f1b 100644
--- a/src/Gui/library/MediaCellView.cpp
+++ b/src/Gui/library/MediaCellView.cpp
@@ -255,3 +255,9 @@ MediaCellView::uuid() const
 {
     return m_clip->uuid();
 }
+
+const Clip*
+MediaCellView::clip() const
+{
+    return m_clip;
+}
diff --git a/src/Gui/library/MediaCellView.h b/src/Gui/library/MediaCellView.h
index 12c2d87..acba3b9 100644
--- a/src/Gui/library/MediaCellView.h
+++ b/src/Gui/library/MediaCellView.h
@@ -54,6 +54,7 @@ public:
     void                setLength( qint64 length, bool mSecs = true );
     QString             title() const;
     const QUuid         &uuid() const;
+    const Clip*         clip() const;
 
 private:
     Ui::MediaCellView   *m_ui;
diff --git a/src/Gui/library/MediaLibrary.cpp b/src/Gui/library/MediaLibrary.cpp
index 38d74d7..73f1073 100644
--- a/src/Gui/library/MediaLibrary.cpp
+++ b/src/Gui/library/MediaLibrary.cpp
@@ -22,7 +22,10 @@
 
 #include "MediaLibrary.h"
 
+#include "Clip.h"
 #include "Library.h"
+#include "Media.h"
+#include "MediaCellView.h"
 #include "MediaListView.h"
 #include "StackViewController.h"
 
@@ -33,12 +36,12 @@ MediaLibrary::MediaLibrary(QWidget *parent) : QWidget(parent),
 {
     m_ui->setupUi( this );
     StackViewController *nav = new StackViewController( m_ui->mediaListContainer );
-    MediaListView       *mediaListView = new MediaListView( nav, Library::getInstance() );
-    nav->pushViewController( mediaListView );
+    m_mediaListView = new MediaListView( nav, Library::getInstance() );
+    nav->pushViewController( m_mediaListView );
 
     connect( m_ui->importButton, SIGNAL( clicked() ),
              this, SIGNAL( importRequired() ) );
-    connect( mediaListView, SIGNAL( clipSelected( Clip* ) ),
+    connect( m_mediaListView, SIGNAL( clipSelected( Clip* ) ),
              this, SIGNAL( clipSelected( Clip* ) ) );
     connect( m_ui->filterInput, SIGNAL( textChanged( const QString& ) ),
              this, SLOT( filterUpdated( const QString& ) ) );
@@ -49,7 +52,17 @@ MediaLibrary::MediaLibrary(QWidget *parent) : QWidget(parent),
 void
 MediaLibrary::filterUpdated( const QString &filter )
 {
-    qDebug() << "Filter updated:" << filter;
+    const MediaListView::MediaList  &medias = m_mediaListView->mediaList();
+    MediaListView::MediaList::const_iterator        it = medias.begin();
+    MediaListView::MediaList::const_iterator        ite = medias.end();
+
+    while ( it != ite )
+    {
+        MediaCellView  *mcv = it.value();
+
+        mcv->setVisible( currentFilter()( mcv->clip(), filter ) );
+        ++it;
+    }
 }
 
 void
@@ -57,3 +70,15 @@ MediaLibrary::clearFilter()
 {
     m_ui->filterInput->setText( "" );
 }
+
+MediaLibrary::Filter
+MediaLibrary::currentFilter()
+{
+    return &filterByName;
+}
+
+bool
+MediaLibrary::filterByName( const Clip *clip, const QString &filter )
+{
+    return ( clip->getMedia()->fileName().contains( filter, Qt::CaseInsensitive ) );
+}
diff --git a/src/Gui/library/MediaLibrary.h b/src/Gui/library/MediaLibrary.h
index 1f7ce74..5c08a7e 100644
--- a/src/Gui/library/MediaLibrary.h
+++ b/src/Gui/library/MediaLibrary.h
@@ -27,6 +27,7 @@
 
 #include "ui_MediaLibrary.h"
 class   Clip;
+class   MediaListView;
 
 class MediaLibrary : public QWidget
 {
@@ -34,10 +35,24 @@ class MediaLibrary : public QWidget
     Q_DISABLE_COPY( MediaLibrary );
 
     public:
+        typedef bool    (*Filter)( const Clip*, const QString& filter );
         explicit MediaLibrary( QWidget *parent = 0);
 
     private:
+        /**
+         *  \return     The appropriate filter function
+         *
+         *  This will evaluate the currently selected filter, and return the appropriate
+         *  function.
+         */
+        Filter              currentFilter();
+
+    //Filters list :
+        static bool         filterByName( const Clip *clip, const QString &filter );
+
+    private:
         Ui::MediaLibrary    *m_ui;
+        MediaListView       *m_mediaListView;
 
     private slots:
         void                filterUpdated( const QString &filter );
diff --git a/src/Gui/library/MediaListView.cpp b/src/Gui/library/MediaListView.cpp
index 4a499ed..3380a07 100644
--- a/src/Gui/library/MediaListView.cpp
+++ b/src/Gui/library/MediaListView.cpp
@@ -115,3 +115,9 @@ MediaListView::showSubClips( const QUuid &uuid )
     Clip    *clip = m_mediaContainer->clip( uuid );
     m_nav->pushViewController( new MediaListView( m_nav, clip->getChilds() ) );
 }
+
+const MediaListView::MediaList&
+MediaListView::mediaList() const
+{
+    return m_cells;
+}
diff --git a/src/Gui/library/MediaListView.h b/src/Gui/library/MediaListView.h
index 113be78..0878dbd 100644
--- a/src/Gui/library/MediaListView.h
+++ b/src/Gui/library/MediaListView.h
@@ -42,13 +42,17 @@ class MediaListView : public ListViewController
     Q_OBJECT
 
 public:
+    typedef     QHash<QUuid, MediaCellView*>    MediaList;
+
     MediaListView( StackViewController *nav, MediaContainer *mc );
     virtual ~MediaListView();
 
+    const MediaList                 &mediaList() const;
+
 private:
     StackViewController             *m_nav;
     QUuid                           m_currentUuid;
-    QHash<QUuid, MediaCellView*>    m_cells;
+    MediaList                       m_cells;
     QUuid                           m_lastUuidClipListAsked;
     MediaContainer                  *m_mediaContainer;
 
diff --git a/src/Gui/library/ui/MediaLibrary.ui b/src/Gui/library/ui/MediaLibrary.ui
index 32caa6c..89aab70 100644
--- a/src/Gui/library/ui/MediaLibrary.ui
+++ b/src/Gui/library/ui/MediaLibrary.ui
@@ -32,13 +32,6 @@
      <item row="0" column="1">
       <widget class="QLineEdit" name="filterInput"/>
      </item>
-     <item row="0" column="2">
-      <widget class="QPushButton" name="clearButton">
-       <property name="text">
-        <string>clear</string>
-       </property>
-      </widget>
-     </item>
      <item row="1" column="2">
       <widget class="QComboBox" name="filterType">
        <item>
@@ -58,6 +51,13 @@
        </property>
       </widget>
      </item>
+     <item row="0" column="2">
+      <widget class="QPushButton" name="clearButton">
+       <property name="text">
+        <string>clear</string>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item>



More information about the Vlmc-devel mailing list