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

List:       kmail-devel
Subject:    new addressbook-filterrule (patch)
From:       Martin =?iso-8859-15?q?K=F6bele?= <martin () mkoebele ! de>
Date:       2004-01-27 11:29:15
Message-ID: 200401271229.15421.martin () mkoebele ! de
[Download RAW message or body]

Hi,

I wrote a patch which contains a new filterrule "is in addressbook" and "is 
not in addressbook".
The check is against the standard addressbook.

It works fine.

There is one little bug though, which I can't find:

if you click on your filter with the addressbook in the listbox "available 
filters" then you see on the right side your addressbook filter. This filter 
sets the lineedit mRuleValue to "Addressbook" and disables it, because this 
value needs to be set for the config-file and it is disabled because it won't 
make any sense to write something in it.
If you click now on another filter, the lineedit mRuleValue is not updated. 
"Addressbook" is now in the lineedit instead of the rule value of the filter 
you just clicked on. Another click on another filter is not a problem 
anymore. Just the first click on another filter when the filter with the 
addressbook was selected is a problem.

So I don't know how to fix that.

I would be glad if you could have a look at that filter and maybe find the 
bug. And after that it would be great if it is committed. It is a good filter 
for something like "play sound if an email arrives from somebody in the 
addressbook" or better sorting.


Thank you!

Martin
(irc: mkoebele)

["addressbookfilter.patch" (text/x-diff)]

? addressbookfilter.patch
? kmail-signals
? kmail.kdevelop
Index: kmsearchpattern.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpattern.cpp,v
retrieving revision 1.48
diff -u -3 -p -r1.48 kmsearchpattern.cpp
--- kmsearchpattern.cpp	10 Jan 2004 13:33:57 -0000	1.48
+++ kmsearchpattern.cpp	27 Jan 2004 11:20:11 -0000
@@ -14,6 +14,7 @@
 #include <kdebug.h>
 #include <kconfig.h>
 
+#include <kabc/stdaddressbook.h>
 #include <qregexp.h>
 
 #include <mimelib/string.h>
@@ -23,7 +24,8 @@
 
 static const char* funcConfigNames[] =
   { "contains", "contains-not", "equals", "not-equal", "regexp",
-    "not-regexp", "greater", "less-or-equal", "less", "greater-or-equal" };
+    "not-regexp", "greater", "less-or-equal", "less", "greater-or-equal",
+     "is-in-addressbook", "is-not-in-addressbook" };
 static const int numFuncConfigNames = sizeof funcConfigNames / sizeof \
*funcConfigNames;  
 
@@ -281,8 +283,17 @@ bool KMSearchRuleString::matches( const 
     msgContents = msg->headerField("To") + msg->headerField("Cc")
                 + msg->headerField("Bcc");
   }  else {
-    msgContents = msg->headerField( field() );
+  	  msgContents = msg->headerField( field() );
   }
+  
+  if (function() == FuncIsInAddressbook || function() == FuncIsNotInAddressbook) 
+  {
+    // I think only the "from"-field makes sense.
+      msgContents = msg->getEmailAddr(msg->headerField(field()));
+      if (msgContents.isEmpty())
+        return false;
+  }
+  	
   return matchesInternal( msgContents );
 }
 
@@ -325,6 +336,19 @@ bool KMSearchRuleString::matchesInternal
 
   case FuncIsGreaterOrEqual:
       return ( QString::compare( msgContents.lower(), contents().lower() ) >= 0 );
+      
+  case FuncIsInAddressbook:
+  	{
+          KABC::AddressBook *stdAb = KABC::StdAddressBook::self();
+	  return ( !(stdAb->findByEmail(msgContents.lower())).empty());
+	}
+	
+  case FuncIsNotInAddressbook:
+  	{
+          KABC::AddressBook *stdAb = KABC::StdAddressBook::self();
+          return ((stdAb->findByEmail(msgContents.lower())).empty());
+	}
+	
   }
 
   return false;
@@ -412,8 +436,14 @@ bool KMSearchRuleNumerical::matchesInter
 
   case FuncIsGreaterOrEqual:
       return ( numericalMsgContents >= numericalValue );
-  }
-
+   
+  case FuncIsInAddressbook:  // since email-addresses are not numerical, I settle \
for false here +	return ( false);
+	
+  case FuncIsNotInAddressbook:
+	return (false);
+ }
+		
   return false;
 }
 
Index: kmsearchpattern.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpattern.h,v
retrieving revision 1.18
diff -u -3 -p -r1.18 kmsearchpattern.h
--- kmsearchpattern.h	16 Sep 2003 07:51:06 -0000	1.18
+++ kmsearchpattern.h	27 Jan 2004 11:20:11 -0000
@@ -40,7 +40,8 @@ public:
 		  FuncEquals, FuncNotEqual,
 		  FuncRegExp, FuncNotRegExp,
 		  FuncIsGreater, FuncIsLessOrEqual,
-		  FuncIsLess, FuncIsGreaterOrEqual };
+		  FuncIsLess, FuncIsGreaterOrEqual, 
+		  FuncIsInAddressbook, FuncIsNotInAddressbook};
   KMSearchRule ( const QCString & field=0, Function=FuncContains,
                  const QString &contents=QString::null );
   KMSearchRule ( const KMSearchRule &other );
Index: kmsearchpatternedit.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpatternedit.cpp,v
retrieving revision 1.48
diff -u -3 -p -r1.48 kmsearchpatternedit.cpp
--- kmsearchpatternedit.cpp	29 Nov 2003 14:30:05 -0000	1.48
+++ kmsearchpatternedit.cpp	27 Jan 2004 11:20:12 -0000
@@ -31,7 +31,9 @@
 KMSearchRuleWidget::KMSearchRuleWidget(QWidget *parent, KMSearchRule *aRule, const \
char *name, bool headersOnly, bool absoluteDates)  : QHBox(parent,name),
     mRuleEditBut(0),
-    mRegExpEditDialog(0)
+    mRegExpEditDialog(0),
+    mChangeValue(false),
+    mOldValue("")
 {
   initLists( headersOnly, absoluteDates ); // sFilter{Func,Field}List are local to \
KMSearchRuleWidget  initWidget();
@@ -96,7 +98,22 @@ void KMSearchRuleWidget::editRegExp()
 
 void KMSearchRuleWidget::functionChanged( int which )
 {
-  mRuleEditBut->setEnabled( which == 4 || which == 5 );
+  mRuleEditBut->setEnabled( which == 4 || which == 5 ); //FuncRegExp, FuncNotRegExp
+  
+  //we don't need the lineedit mRuleValue in that case:
+  mRuleValue->setEnabled(which != 10 && which != 11);  //FuncIsInAddressbook, \
FuncIsNotInAddressbook +  if (which == 10 || which == 11) 
+  {
+    if (!mChangeValue)
+      mOldValue = mRuleValue->text();
+    mRuleValue->setText("Addressbook"); //just a dummy-value, otherwise the rule is \
not saved to kmailrc +    mChangeValue = true;
+  }
+  else  if (mChangeValue)
+  {
+    mRuleValue->setText(mOldValue);
+    mChangeValue = false;
+  }
 }
 
 
@@ -235,6 +252,8 @@ void KMSearchRuleWidget::initLists(bool 
     mFilterFuncList.append(i18n("is less than or equal to"));
     mFilterFuncList.append(i18n("is less than"));
     mFilterFuncList.append(i18n("is greater than or equal to"));
+    mFilterFuncList.append(i18n("is in addressbook"));
+    mFilterFuncList.append(i18n("is not in addressbook"));
   }
 
   //---------- initialize list of filter operators
@@ -460,7 +479,7 @@ void KMSearchPatternEdit::setSearchPatte
   assert( aPattern );
 
   mRuleLister->setRuleList( aPattern );
-
+  
   mPattern = aPattern;
 
   blockSignals(TRUE);
Index: kmsearchpatternedit.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpatternedit.h,v
retrieving revision 1.17
diff -u -3 -p -r1.17 kmsearchpatternedit.h
--- kmsearchpatternedit.h	3 Oct 2003 15:45:29 -0000	1.17
+++ kmsearchpatternedit.h	27 Jan 2004 11:20:12 -0000
@@ -97,6 +97,8 @@ private:
   QPushButton* mRuleEditBut;
   QDialog* mRegExpEditDialog;
   QStringList mFilterFieldList, mFilterFuncList, mStatiList;
+  bool mChangeValue; //used for the new is-in-addressbook-filter
+  QString mOldValue;
 };
 
 



_______________________________________________
KMail developers mailing list
KMail-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmail-devel


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

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