[Amarok] 62b7cf7 Fix crash when filtering the collection by format

Daniel Faust hessijames at gmail.com
Tue Sep 7 18:24:35 CEST 2010


commit 62b7cf7b72454d3db8d785ff391791470a393362
Author: Daniel Faust <hessijames at gmail.com>
Date:   Tue Sep 7 18:22:43 2010 +0200

    Fix crash when filtering the collection by format
    CCMAIL: amarok-devel at kde.org
    Since we are close to tagging, please have a look at this

diff --git a/src/core-impl/collections/support/MemoryFilter.cpp b/src/core-impl/collections/support/MemoryFilter.cpp
index a26628d..e329faa 100644
--- a/src/core-impl/collections/support/MemoryFilter.cpp
+++ b/src/core-impl/collections/support/MemoryFilter.cpp
@@ -16,6 +16,8 @@
 
 #include "MemoryFilter.h"
 
+#include "shared/FileType.h"
+
 #include <QDateTime>
 
 namespace FilterFactory
@@ -113,6 +115,9 @@ namespace FilterFactory
             case Meta::valBpm:
                 result = new BpmNumberFilter();
                 break;
+            case Meta::valFormat:
+                result = new FormatNumberFilter();
+                break;
         }
         Q_ASSERT_X( result, "FilterFactory::numberFilter", "called numberFilter with an illegal value, value was " + value );
         if (result)
@@ -644,6 +649,35 @@ BpmNumberFilter::value( const Meta::TrackPtr &track ) const
     return track->bpm();
 }
 
+FormatNumberFilter::FormatNumberFilter()
+    : NumberMemoryFilter()
+{
+}
+
+FormatNumberFilter::~FormatNumberFilter()
+{
+}
+
+qint64
+FormatNumberFilter::value( const Meta::TrackPtr &track ) const
+{
+    if( track->bpm() < 0 )
+        return 0;
+
+    const QString &ftStr = track->type();
+    Amarok::FileType ft = Amarok::Unknown;
+    if( ftStr.compare( "flac", Qt::CaseInsensitive ) == 0 )
+        ft = Amarok::Flac;
+    else if( ftStr.compare( "mp3", Qt::CaseInsensitive ) == 0 )
+        ft = Amarok::Mp3;
+    else if( ftStr.compare( "mp4", Qt::CaseInsensitive ) == 0 )
+        ft = Amarok::Mp4;
+    else if( ftStr.compare( "ogg", Qt::CaseInsensitive ) == 0 )
+        ft = Amarok::Ogg;
+
+    return qint64(ft);
+}
+
 LabelFilter::LabelFilter( const QString &filter, bool matchBegin, bool matchEnd )
     : MemoryFilter()
 {
diff --git a/src/core-impl/collections/support/MemoryFilter.h b/src/core-impl/collections/support/MemoryFilter.h
index 353cad4..7d5f43e 100644
--- a/src/core-impl/collections/support/MemoryFilter.h
+++ b/src/core-impl/collections/support/MemoryFilter.h
@@ -314,6 +314,15 @@ class AMAROK_EXPORT BpmNumberFilter : public NumberMemoryFilter
         virtual qint64 value( const Meta::TrackPtr &track ) const;
 };
 
+class AMAROK_EXPORT FormatNumberFilter : public NumberMemoryFilter
+{
+    public:
+        FormatNumberFilter();
+        virtual ~FormatNumberFilter();
+    protected:
+        virtual qint64 value( const Meta::TrackPtr &track ) const;
+};
+
 class AMAROK_EXPORT LabelFilter : public MemoryFilter
 {
 public:


More information about the Amarok-devel mailing list