[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kdab-post-4.0/kdepim
From:       Marc Mutz <mutz () kde ! org>
Date:       2007-12-19 18:43:50
Message-ID: 1198089830.156890.9815.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 750616 by mutz:

Add a match context (Appearance or Filtering, at this point in time) to \
KeyFilter(Manager). Plug the last shared_ptr-less hole in KeyFilter handling.

 M  +2 -2      kleopatra/models/keylistmodel.cpp  
 M  +1 -1      kleopatra/models/keylistsortfilterproxymodel.cpp  
 M  +35 -1     libkleo/kleo/kconfigbasedkeyfilter.cpp  
 M  +3 -1      libkleo/kleo/kconfigbasedkeyfilter.h  
 M  +16 -1     libkleo/kleo/keyfilter.h  
 M  +13 -7     libkleo/kleo/keyfiltermanager.cpp  
 M  +3 -5      libkleo/kleo/keyfiltermanager.h  


--- branches/work/kdab-post-4.0/kdepim/kleopatra/models/keylistmodel.cpp \
#750615:750616 @@ -220,12 +220,12 @@
         QFont font = qApp->font(); // ### correct font?
         if ( column == Fingerprint )
             font.setFamily( "courier" );
-        if ( const KeyFilter * const filter = \
KeyFilterManager::instance()->filterMatching( key ) ) +        if ( const \
shared_ptr<KeyFilter> & filter = KeyFilterManager::instance()->filterMatching( key, \
KeyFilter::Appearance ) )  return filter->font( font );
         else
             return font;
     } else if ( role == Qt::DecorationRole || role == Qt::BackgroundRole || role == \
                Qt::ForegroundRole ) {
-        if ( const KeyFilter * const filter = \
KeyFilterManager::instance()->filterMatching( key ) ) { +        if ( const \
shared_ptr<KeyFilter> & filter = KeyFilterManager::instance()->filterMatching( key, \
KeyFilter::Appearance ) ) {  switch ( role ) {
             case Qt::DecorationRole: return column == Icon ? returnIfValid( QIcon( \
                filter->icon() ) ) : QVariant() ;
             case Qt::BackgroundRole: return returnIfValid( filter->bgColor() );
--- branches/work/kdab-post-4.0/kdepim/kleopatra/models/keylistsortfilterproxymodel.cpp \
#750615:750616 @@ -115,7 +115,7 @@
 
         const Key key = klm->key( nameIndex );
 
-        return d->keyFilter->matches( key );
+        return d->keyFilter->matches( key, KeyFilter::Filtering );
     }
 
     // 3. match by default:
--- branches/work/kdab-post-4.0/kdepim/libkleo/kleo/kconfigbasedkeyfilter.cpp \
#750615:750616 @@ -70,6 +70,7 @@
 
 KeyFilterImplBase::KeyFilterImplBase()
   : KeyFilter(),
+    mMatchContexts( AnyMatchContext ),
     mSpecificity( 0 ),
     mItalic( false ),
     mBold( false ),
@@ -161,9 +162,42 @@
       break;
     }
   }
+  static const struct {
+      const char * key;
+      MatchContext context;
+  } matchMap[] = {
+      { "any", AnyMatchContext },
+      { "appearance", Appearance },
+      { "filtering", Filtering },
+  };
+  const QStringList contexts = config.readEntry( "match-contexts", "any" \
).toLower().split( QRegExp( "[^a-zA-Z0-9_-!]+" ), QString::SkipEmptyParts ); +  \
mMatchContexts = NoMatchContext; +  Q_FOREACH( const QString & ctx, contexts ) {
+      bool found = false;
+      for ( unsigned int i = 0 ; i < sizeof matchMap / sizeof *matchMap ; ++i )
+          if ( ctx == matchMap[i].key ) {
+              mMatchContexts |= matchMap[i].context;
+              found = true;
+              break;
+          } else if ( ctx.startsWith( '!' ) && ctx.mid( 1 ) == matchMap[i].key ) {
+              mMatchContexts &= ~matchMap[i].context;
+              found = true;
+              break;
+          }
+      if ( !found )   
+          qWarning( "KConfigBasedKeyFilter: found unknown match context '%s' in \
group '%s'", +                    qPrintable( ctx ), qPrintable( config.name() ) );
+  }
+  if ( mMatchContexts == NoMatchContext ) {
+      qWarning( "KConfigBasedKeyFilter: match context in group '%s' evaluates to \
NoMatchContext, " +                "replaced by AnyMatchContext", qPrintable( \
config.name() ) ); +      mMatchContexts = AnyMatchContext;
+  }
 }
 
-bool KeyFilterImplBase::matches( const Key & key ) const {
+bool KeyFilterImplBase::matches( const Key & key, MatchContexts contexts ) const {
+  if ( !( mMatchContexts & contexts ) )
+    return false;
 #ifdef MATCH
 #undef MATCH
 #endif
--- branches/work/kdab-post-4.0/kdepim/libkleo/kleo/kconfigbasedkeyfilter.h \
#750615:750616 @@ -50,10 +50,11 @@
     KeyFilterImplBase();
     ~KeyFilterImplBase();
 
-    bool matches( const GpgME::Key & key ) const;
+    bool matches( const GpgME::Key & key, MatchContexts ctx ) const;
 
     unsigned int specificity() const { return mSpecificity; }
     QString id() const { return mId; }
+    MatchContexts availableMatchContexts() const { return mMatchContexts; }
 
     QColor fgColor() const { return mFgColor; }
     QColor bgColor() const { return mBgColor; }
@@ -66,6 +67,7 @@
     QString mName;
     QString mIcon;
     QString mId;
+    MatchContexts mMatchContexts;
     unsigned int mSpecificity;
     bool mItalic;
     bool mBold;
--- branches/work/kdab-post-4.0/kdepim/libkleo/kleo/keyfilter.h #750615:750616
@@ -33,6 +33,8 @@
 #ifndef __KLEO_KEYFILTER_H__
 #define __KLEO_KEYFILTER_H__
 
+#include <QFlags>
+
 namespace GpgME {
   class Key;
 }
@@ -50,10 +52,21 @@
   class KeyFilter {
   public:
     virtual ~KeyFilter() {}
-    virtual bool matches( const GpgME::Key & key ) const = 0;
 
+    enum MatchContext {
+        NoMatchContext = 0x0,
+        Appearance = 0x1,
+        Filtering = 0x2,
+
+        AnyMatchContext = Appearance|Filtering
+    };
+    Q_DECLARE_FLAGS( MatchContexts, MatchContext )
+
+    virtual bool matches( const GpgME::Key & key, MatchContexts ctx ) const = 0;
+
     virtual unsigned int specificity() const = 0;
     virtual QString id() const = 0;
+    virtual MatchContexts availableMatchContexts() const = 0;
 
     // not sure if we want these here, but for the time being, it's
     // the easiest way:
@@ -64,6 +77,8 @@
     virtual QString icon() const = 0;
   };
 
+  Q_DECLARE_OPERATORS_FOR_FLAGS( KeyFilter::MatchContexts )
+
 }
 
 #endif // __KLEO_KEYFILTER_H__
--- branches/work/kdab-post-4.0/kdepim/libkleo/kleo/keyfiltermanager.cpp \
#750615:750616 @@ -77,6 +77,7 @@
 
             mName = i18n("My Certificates");
             mId = "my-certificates";
+            mMatchContexts = AnyMatchContext;
             mBold = true;
         }
     };
@@ -94,6 +95,7 @@
 
             mName = i18n("Trusted Certificates");
             mId = "trusted-certificates";
+            mMatchContexts = Filtering;
         }
     };
 
@@ -109,6 +111,7 @@
 
             mName = i18n("Other Certificates");
             mId = "other-certificates";
+            mMatchContexts = Filtering;
         }
     };
 }
@@ -161,11 +164,14 @@
   return mSelf;
 }
 
-const KeyFilter * KeyFilterManager::filterMatching( const Key & key ) const {
+const shared_ptr<KeyFilter> & KeyFilterManager::filterMatching( const Key & key, \
KeyFilter::MatchContexts contexts ) const {  const std::vector< shared_ptr<KeyFilter> \
>::const_iterator it  = std::find_if( d->filters.begin(), d->filters.end(),
-                        bind( &KeyFilter::matches, _1, cref( key ) ) );
-    return it == d->filters.end() ? 0 : it->get();
+                        bind( &KeyFilter::matches, _1, cref( key ), contexts ) );
+    if ( it != d->filters.end() )
+        return *it;
+    static const shared_ptr<KeyFilter> null;
+    return null;
 }
 
 namespace {
@@ -202,15 +208,15 @@
                         bind( &KeyFilter::id, _1 ) == id );
     if ( it != d->filters.end() )
         return *it;
-    static const shared_ptr<KeyFilter> empty;
-    return empty;
+    static const shared_ptr<KeyFilter> null;
+    return null;
 }
 
 const shared_ptr<KeyFilter> & KeyFilterManager::fromModelIndex( const QModelIndex & \
idx ) const {  if ( !idx.isValid() || idx.model() != &d->model || idx.row() < 0 ||
          static_cast<unsigned>(idx.row()) >= d->filters.size() ) {
-        static const shared_ptr<KeyFilter> empty;
-        return empty;
+        static const shared_ptr<KeyFilter> null;
+        return null;
     }
     return d->filters[idx.row()];
 }
--- branches/work/kdab-post-4.0/kdepim/libkleo/kleo/keyfiltermanager.h #750615:750616
@@ -38,14 +38,12 @@
 
 #include <boost/shared_ptr.hpp>
 
+#include <kleo/keyfilter.h>
+
 namespace GpgME {
   class Key;
 }
 
-namespace Kleo {
-  class KeyFilter;
-}
-
 class QAbstractItemModel;
 class QModelIndex;
 
@@ -60,7 +58,7 @@
   public:
     static KeyFilterManager * instance();
 
-    const KeyFilter * filterMatching( const GpgME::Key & key ) const;
+    const boost::shared_ptr<KeyFilter> & filterMatching( const GpgME::Key & key, \
KeyFilter::MatchContexts contexts ) const;  
     QAbstractItemModel * model() const;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic