File indexing completed on 2024-05-19 04:49:17
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef MEMORYFILTER_H 0018 #define MEMORYFILTER_H 0019 0020 #include "amarok_export.h" 0021 #include "core/meta/forward_declarations.h" 0022 #include "core/collections/QueryMaker.h" 0023 0024 #include <QList> 0025 #include <QRegExp> 0026 #include <QString> 0027 0028 class MemoryFilter; 0029 0030 namespace FilterFactory 0031 { 0032 MemoryFilter* filter( qint64 value, const QString &filter, bool matchBegin, bool matchEnd ); 0033 MemoryFilter* numberFilter( qint64 value, qint64 filter, Collections::QueryMaker::NumberComparison compare ); 0034 } 0035 0036 class AMAROK_EXPORT MemoryFilter 0037 { 0038 public: 0039 MemoryFilter(); 0040 virtual ~MemoryFilter(); 0041 virtual bool filterMatches( const Meta::TrackPtr &track ) const = 0; 0042 }; 0043 0044 class AMAROK_EXPORT ContainerMemoryFilter : public MemoryFilter 0045 { 0046 public: 0047 ContainerMemoryFilter(); 0048 ~ContainerMemoryFilter() override; 0049 void addFilter( MemoryFilter *filter ); 0050 protected: 0051 QList<MemoryFilter*> m_filters; 0052 }; 0053 0054 class AMAROK_EXPORT AndContainerMemoryFilter : public ContainerMemoryFilter 0055 { 0056 public: 0057 AndContainerMemoryFilter(); 0058 ~AndContainerMemoryFilter() override; 0059 bool filterMatches( const Meta::TrackPtr &track ) const override; 0060 }; 0061 0062 class AMAROK_EXPORT OrContainerMemoryFilter : public ContainerMemoryFilter 0063 { 0064 public: 0065 OrContainerMemoryFilter(); 0066 ~OrContainerMemoryFilter() override; 0067 bool filterMatches( const Meta::TrackPtr &track ) const override; 0068 }; 0069 0070 class AMAROK_EXPORT NegateMemoryFilter : public MemoryFilter 0071 { 0072 public: 0073 explicit NegateMemoryFilter( MemoryFilter *filter ); 0074 ~NegateMemoryFilter() override; 0075 bool filterMatches( const Meta::TrackPtr &track ) const override; 0076 private: 0077 MemoryFilter *m_filter; 0078 }; 0079 0080 class AMAROK_EXPORT StringMemoryFilter : public MemoryFilter 0081 { 0082 public: 0083 StringMemoryFilter(); 0084 ~StringMemoryFilter() override; 0085 bool filterMatches( const Meta::TrackPtr &track ) const override; 0086 0087 void setFilter( const QString &filter, bool matchBegin, bool matchEnd ); 0088 protected: 0089 virtual QString value( const Meta::TrackPtr &track ) const = 0; 0090 0091 private: 0092 QString m_filter; 0093 bool m_matchBegin; 0094 bool m_matchEnd; 0095 }; 0096 0097 0098 class AMAROK_EXPORT NumberMemoryFilter : public MemoryFilter 0099 { 0100 public: 0101 NumberMemoryFilter(); 0102 ~NumberMemoryFilter() override; 0103 void setFilter( qint64 filter, Collections::QueryMaker::NumberComparison compare ); 0104 bool filterMatches( const Meta::TrackPtr &track ) const override; 0105 protected: 0106 virtual qint64 value( const Meta::TrackPtr &track ) const = 0; 0107 private: 0108 qint64 m_filter; 0109 Collections::QueryMaker::NumberComparison m_compare; 0110 }; 0111 0112 0113 class AMAROK_EXPORT LabelFilter : public MemoryFilter 0114 { 0115 public: 0116 LabelFilter( const QString &filter, bool matchBegin, bool matchEnd ); 0117 ~ LabelFilter() override; 0118 bool filterMatches( const Meta::TrackPtr &track ) const override; 0119 0120 private: 0121 QRegExp m_expression; 0122 }; 0123 0124 #endif