diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-09 10:18:22 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-09 10:18:22 +0000 |
commit | a4e1f41de249a24f3a3607b3ed5d5f02c094e8b5 (patch) | |
tree | 7e484840aaf31fc0d4780295b342592f3dd87a72 /adept/libadept/easytagfilter.h | |
download | adept-a4e1f41de249a24f3a3607b3ed5d5f02c094e8b5.tar.gz adept-a4e1f41de249a24f3a3607b3ed5d5f02c094e8b5.zip |
Added adept (KDE3 version abandoned by original author)
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/adept@1072021 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'adept/libadept/easytagfilter.h')
-rw-r--r-- | adept/libadept/easytagfilter.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/adept/libadept/easytagfilter.h b/adept/libadept/easytagfilter.h new file mode 100644 index 0000000..edbe8b5 --- /dev/null +++ b/adept/libadept/easytagfilter.h @@ -0,0 +1,93 @@ +/** -*- C++ -*- + @file adept/quickfilter.h + @author Peter Rockai <me@mornfall.net> +*/ + +#include <klocale.h> +#include <qlayout.h> +#include <kdebug.h> + +#include <apt-front/cache/entity/entity.h> +#include <apt-front/cache/entity/package.h> +#include <apt-front/cache/component/tags.h> +#include <apt-front/predicate/factory.h> + +#include <adept/easytagfilterui.h> +#include <adept/filterlist.h> +#include <adept/lister.h> + +#ifndef EPT_EASYTAGFILTER_H +#define EPT_EASYTAGFILTER_H + +namespace adept { + +template< typename T > +struct EasyTagFilter : predicate::Implementation< T, EasyTagFilter< T > >, + InterfacingPredicate +{ + typedef std::map< std::string, std::string > Tags; + + EasyTagFilter() { + setupPredicate(); + } + + void setupPredicate() { + Cache &cache = cache::Global::get(); // FIXME? + m_op = predicate::True< T >(); + for (Tags::iterator i = m_tags.begin(); i != m_tags.end(); ++i ) { + m_op = m_op and predicate::Factory< T >::tag( + cache.tags().tagByName( i->first + "::" + i->second ) ); + // kdDebug() << t.summary() << endl; + } + } + + std::string summary() const { + std::string r( i18n( "EasyTag filter: " ).local8Bit() ); + for (Tags::const_iterator j, i = m_tags.begin(); + i != m_tags.end(); ++i ) { + j = i; ++j; + r += i->first + ": " + i->second; + if (j != m_tags.end()) + r += ", "; + } + return r; + } + + void parseArguments( const predicate::ArgumentList & ) {} + + bool operator==( const EasyTagFilter &o ) const { + return o.m_tags == m_tags; + } + + bool operator()( const T &p ) { + return m_op( p ); + } + + void set( const std::string &f, const std::string &t ) { + m_tags[f] = t; + setupPredicate(); + } + + std::string get( const std::string &f ) { + return m_tags[ f ]; + } + +protected: + Tags m_tags; + predicate::Predicate< T > m_op; +}; + +class EasyTagFilterWidget : public EasyTagFilterUi +{ + Q_OBJECT +public: + EasyTagFilterWidget( QWidget *parent, const char *name = 0 ); + virtual Predicate predicate(); +public slots: + void predicateChanged(); + void reset(); +}; + +} + +#endif |