[prev in list] [next in list] [prev in thread] [next in thread]
List: kmail-devel
Subject: Re: [PATCH] new filterrule: sort by category II
From: Martin =?iso-8859-15?q?K=F6bele?= <martin () mkoebele ! de>
Date: 2004-03-20 22:50:03
Message-ID: 200403202350.04141.martin () mkoebele ! de
[Download RAW message or body]
updated patch after a discussion with Ingo.
changed API of QString TextRuleWidgetHandler::currentTextValue( const
QWidgetStack *valueStack, const KMSearchRule::Function func ) const
new is the const KMSearchRule::Function func .
How is this version?
Martin
On Saturday 20 March 2004 17:47, Martin Köbele wrote:
> Hi,
>
> this patch gives the addressbook feature "Category" a new and more sense :)
>
> This patch allows you to filter by category.
>
> Please review it. When everything is fine, I'll commit it.
>
> Thanks
>
> Martin
["category_filter_rule.patch" (text/x-diff)]
? Doxyfile
? addressbookfilter.patch
? category_filter_rule.patch
? htmlmail.diff
? kmail.kdevelop
? kmail.kdevelop.pcs
? kmail.kdevses
? kmail_67017_2.diff
? kmsearchpattern.cpp-old
? kmsearchpattern.h-old
? kmsearchpatternedit.cpp-old
? kmsearchpatternedit.h-old
? rulewidgethandlers.diff
Index: kmaddrbook.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmaddrbook.cpp,v
retrieving revision 1.84
diff -u -p -r1.84 kmaddrbook.cpp
--- kmaddrbook.cpp 18 Mar 2004 11:53:14 -0000 1.84
+++ kmaddrbook.cpp 20 Mar 2004 22:45:48 -0000
@@ -108,6 +108,7 @@ QString KabcBridge::expandNickName( cons
return QString();
}
+
//-----------------------------------------------------------------------------
QString KabcBridge::expandDistributionList( const QString& listName )
{
@@ -130,6 +131,22 @@ QString KabcBridge::expandDistributionLi
return QString();
}
+QStringList KabcBridge::categories()
+{
+ KABC::AddressBook *addressBook = KABC::StdAddressBook::self();
+ KABC::Addressee::List addresses = addressBook->allAddressees();
+ QStringList allcategories, aux;
+
+ for ( KABC::Addressee::List::Iterator it = addresses.begin(); it != \
addresses.end(); ++it ) { + aux = ( *it ).categories();
+ for ( QStringList::ConstIterator itAux = aux.begin(); itAux != aux.end(); \
++itAux ) { // don't have duplicates in allcategories + if ( \
allcategories.find( *itAux ) == allcategories.end() ) + allcategories += \
*itAux; + }
+ }
+ return allcategories;
+}
+
//-----------------------------------------------------------------------------
void KMAddrBookExternal::openEmail( const QString &addr, QWidget *) {
#if KDE_IS_VERSION( 3, 1, 92 )
Index: kmaddrbook.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmaddrbook.h,v
retrieving revision 1.23
diff -u -p -r1.23 kmaddrbook.h
--- kmaddrbook.h 18 Jan 2004 13:29:30 -0000 1.23
+++ kmaddrbook.h 20 Mar 2004 22:45:48 -0000
@@ -18,6 +18,11 @@ public:
static void addresses(QStringList& result);
static QString expandNickName( const QString& nickName );
static QString expandDistributionList( const QString& listName );
+ /**
+ Returns all categories found in the addressbook.
+ @return A list of the categories
+ */
+ static QStringList categories();
};
class KMAddrBookExternal {
Index: kmheaders.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmheaders.cpp,v
retrieving revision 1.626
diff -u -p -r1.626 kmheaders.cpp
--- kmheaders.cpp 19 Mar 2004 10:48:56 -0000 1.626
+++ kmheaders.cpp 20 Mar 2004 22:45:50 -0000
@@ -2137,6 +2137,7 @@ void KMHeaders::makeHeaderVisible()
//-----------------------------------------------------------------------------
void KMHeaders::highlightMessage(QListViewItem* lvi, bool markitread)
{
+kdDebug(5006) << "WHOA.! " << __FILE__ << ":" << __LINE__ << endl;
// shouldnt happen but will crash if it does
if (lvi && !lvi->isSelectable()) return;
@@ -2189,6 +2190,7 @@ void KMHeaders::resetCurrentTime()
//-----------------------------------------------------------------------------
void KMHeaders::selectMessage(QListViewItem* lvi)
{
+kdDebug(5006) << "WHOA.! " << __FILE__ << ":" << __LINE__ << endl;
KMHeaderItem *item = static_cast<KMHeaderItem*>(lvi);
if (!item)
return;
Index: kmsearchpattern.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpattern.cpp,v
retrieving revision 1.59
diff -u -p -r1.59 kmsearchpattern.cpp
--- kmsearchpattern.cpp 18 Mar 2004 17:37:31 -0000 1.59
+++ kmsearchpattern.cpp 20 Mar 2004 22:45:50 -0000
@@ -5,6 +5,7 @@
#include <config.h>
+#include "kmaddrbook.h"
#include "kmsearchpattern.h"
#include "kmmessage.h"
#include "kmmsgindex.h"
@@ -28,7 +29,7 @@ using KMail::FilterLog;
static const char* funcConfigNames[] =
{ "contains", "contains-not", "equals", "not-equal", "regexp",
"not-regexp", "greater", "less-or-equal", "less", "greater-or-equal",
- "is-in-addressbook", "is-not-in-addressbook" };
+ "is-in-addressbook", "is-not-in-addressbook" , "is-in-category", \
"is-not-in-category"}; static const int numFuncConfigNames = sizeof funcConfigNames \
/ sizeof *funcConfigNames;
@@ -318,6 +319,14 @@ bool KMSearchRuleString::matches( const
if ( msgContents.isEmpty() )
return false;
}
+
+ if ( function() == FuncIsInCategory ||
+ function() == FuncIsNotInCategory) {
+ // I think only the "from"-field makes sense.
+ msgContents = msg->headerField( field() );
+ if ( msgContents.isEmpty() )
+ return false;
+ }
bool rc = matchesInternal( msgContents );
if ( FilterLog::instance()->isLogging() ) {
@@ -397,7 +406,40 @@ bool KMSearchRuleString::matchesInternal
}
return false;
}
-
+
+ case FuncIsInCategory: {
+ QString category = contents();
+ QStringList addressList = KMMessage::splitEmailAddrList( msgContents.lower() );
+ KABC::AddressBook *stdAb = KABC::StdAddressBook::self();
+
+ for( QStringList::ConstIterator it = addressList.begin();
+ it != addressList.end(); ++it ) {
+ KABC::Addressee::List addresses = stdAb->findByEmail( \
KMMessage::getEmailAddr( *it ) ); +
+ for ( KABC::Addressee::List::Iterator itAd = addresses.begin(); itAd != \
addresses.end(); ++itAd ) + if ( (*itAd).hasCategory(category) )
+ return true;
+
+ }
+ return false;
+ }
+
+ case FuncIsNotInCategory: {
+ QString category = contents();
+ QStringList addressList = KMMessage::splitEmailAddrList( msgContents.lower() \
); + KABC::AddressBook *stdAb = KABC::StdAddressBook::self();
+
+ for( QStringList::ConstIterator it = addressList.begin();
+ it != addressList.end(); ++it ) {
+ KABC::Addressee::List addresses = stdAb->findByEmail( \
KMMessage::getEmailAddr( *it ) ); +
+ for ( KABC::Addressee::List::Iterator itAd = addresses.begin(); itAd != \
addresses.end(); ++itAd ) + if ( (*itAd).hasCategory(category) )
+ return false;
+
+ }
+ return true;
+ }
default:
;
}
Index: kmsearchpattern.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpattern.h,v
retrieving revision 1.22
diff -u -p -r1.22 kmsearchpattern.h
--- kmsearchpattern.h 18 Mar 2004 17:37:31 -0000 1.22
+++ kmsearchpattern.h 20 Mar 2004 22:45:50 -0000
@@ -43,8 +43,9 @@ public:
FuncEquals, FuncNotEqual,
FuncRegExp, FuncNotRegExp,
FuncIsGreater, FuncIsLessOrEqual,
- FuncIsLess, FuncIsGreaterOrEqual,
- FuncIsInAddressbook, FuncIsNotInAddressbook};
+ FuncIsLess, FuncIsGreaterOrEqual,
+ FuncIsInAddressbook, FuncIsNotInAddressbook,
+ FuncIsInCategory, FuncIsNotInCategory};
KMSearchRule ( const QCString & field=0, Function=FuncContains,
const QString &contents=QString::null );
KMSearchRule ( const KMSearchRule &other );
Index: rulewidgethandlermanager.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/rulewidgethandlermanager.cpp,v
retrieving revision 1.6
diff -u -p -r1.6 rulewidgethandlermanager.cpp
--- rulewidgethandlermanager.cpp 18 Mar 2004 17:37:31 -0000 1.6
+++ rulewidgethandlermanager.cpp 20 Mar 2004 22:45:51 -0000
@@ -86,7 +86,7 @@ namespace {
private:
KMSearchRule::Function currentFunction( const QWidgetStack *functionStack ) \
const;
- QString currentTextValue( const QWidgetStack *valueStack ) const;
+ QString currentTextValue( const QWidgetStack *valueStack, const \
KMSearchRule::Function func ) const; };
class StatusRuleWidgetHandler : public KMail::RuleWidgetHandler {
@@ -344,6 +344,7 @@ namespace {
// these includes are temporary and should not be needed for the code
// above this line, so they appear only here:
+#include "kmaddrbook.h"
#include "kmsearchpattern.h"
#include "regexplineedit.h"
using KMail::RegExpLineEdit;
@@ -374,7 +375,10 @@ namespace {
{ KMSearchRule::FuncRegExp, I18N_NOOP( "matches regular expr." ) },
{ KMSearchRule::FuncNotRegExp, I18N_NOOP( "does not match reg. expr." ) \
},
{ KMSearchRule::FuncIsInAddressbook, I18N_NOOP( "is in address book" ) },
- { KMSearchRule::FuncIsNotInAddressbook, I18N_NOOP( "is not in address book" ) }
+ { KMSearchRule::FuncIsNotInAddressbook, I18N_NOOP( "is not in address book" ) },
+ { KMSearchRule::FuncIsInCategory, I18N_NOOP( "is in category" ) },
+ { KMSearchRule::FuncIsNotInCategory, I18N_NOOP( "is not in category" ) }
+
};
static const int TextFunctionCount =
sizeof( TextFunctions ) / sizeof( *TextFunctions );
@@ -416,6 +420,15 @@ namespace {
if ( number == 1 ) {
return new QLabel( valueStack, "textRuleValueHider" );
}
+
+ if ( number == 2 ) {
+ QComboBox* combo = new QComboBox( valueStack, "categoryCombo" );
+ QStringList categories = KabcBridge::categories();
+ combo->insertStringList( categories );
+ QObject::connect(combo, SIGNAL( activated( const QString & ) ),
+ receiver, SLOT( slotValueChanged() ) );
+ return combo;
+ }
return 0;
}
@@ -449,21 +462,41 @@ namespace {
//---------------------------------------------------------------------------
- QString TextRuleWidgetHandler::currentTextValue( const QWidgetStack *valueStack ) \
const + QString TextRuleWidgetHandler::currentTextValue( const QWidgetStack \
*valueStack, const KMSearchRule::Function func ) const {
+
+ if ( func == KMSearchRule::FuncIsInCategory || // here we gotta check the \
comobox which contains the categories + func == \
KMSearchRule::FuncIsNotInCategory ) { + const QComboBox *combo=
+ dynamic_cast<QComboBox*>( QObject_child_const( valueStack,
+ "categoryCombo" ) );
+ // FIXME (Qt >= 4.0): Use the following when QObject::child() is const.
+ // dynamic_cast<RegExpLineEdit*>( valueStack->child( "regExpLineEdit",
+ // 0, false ) );
+ if ( combo) {
+ return combo->currentText();
+ }
+ else
+ kdDebug(5006) << "TextRuleWidgetHandler::currentTextValue: "
+ "categoryCombo not found." << endl;
+ }
+
+ //in other cases of func it is a lineedit
const RegExpLineEdit *lineEdit =
- dynamic_cast<RegExpLineEdit*>( QObject_child_const( valueStack,
+ dynamic_cast<RegExpLineEdit*>( QObject_child_const( valueStack,
"regExpLineEdit" ) );
// FIXME (Qt >= 4.0): Use the following when QObject::child() is const.
// dynamic_cast<RegExpLineEdit*>( valueStack->child( "regExpLineEdit",
// 0, false ) );
if ( lineEdit ) {
return lineEdit->text();
- }
- else
- kdDebug(5006) << "TextRuleWidgetHandler::currentTextValue: "
- "regExpLineEdit not found." << endl;
- return QString::null;
+ }
+ else
+ kdDebug(5006) << "TextRuleWidgetHandler::currentTextValue: "
+ "regExpLineEdit not found." << endl;
+
+ // or anything else, like addressbook
+ return QString::null;
}
//---------------------------------------------------------------------------
@@ -478,7 +511,7 @@ namespace {
else if ( func == KMSearchRule::FuncIsNotInAddressbook )
return "is not in address book"; // just a non-empty dummy value
else
- return currentTextValue( valueStack );
+ return currentTextValue( valueStack, func );
}
//---------------------------------------------------------------------------
@@ -493,7 +526,7 @@ namespace {
else if ( func == KMSearchRule::FuncIsNotInAddressbook )
return i18n( "is not in address book" );
else
- return currentTextValue( valueStack );
+ return currentTextValue( valueStack, func );
}
//---------------------------------------------------------------------------
@@ -571,6 +604,17 @@ namespace {
0, false ) );
valueStack->raiseWidget( w );
}
+ else
+ if ( func == KMSearchRule::FuncIsInCategory ||
+ func == KMSearchRule::FuncIsNotInCategory) {
+ QComboBox *combo =
+ static_cast<QComboBox*>( valueStack->child("categoryCombo",
+ 0, false ) );
+ combo->blockSignals( true );
+ combo->setCurrentText( rule->contents() );
+ combo->blockSignals( false );
+ valueStack->raiseWidget( combo );
+ }
else {
RegExpLineEdit *lineEdit =
dynamic_cast<RegExpLineEdit*>( valueStack->child( "regExpLineEdit",
@@ -607,6 +651,13 @@ namespace {
static_cast<QWidget*>( valueStack->child( "textRuleValueHider",
0, false ) ) );
}
+ else
+ if ( func == KMSearchRule::FuncIsInCategory ||
+ func == KMSearchRule::FuncIsNotInCategory) {
+ valueStack->raiseWidget(
+ static_cast<QWidget*>( valueStack->child("categoryCombo",
+ 0, false ) ) );
+ }
else {
RegExpLineEdit *lineEdit =
dynamic_cast<RegExpLineEdit*>( valueStack->child( "regExpLineEdit",
_______________________________________________
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