--------------Boundary-00=_X1NVRX2XISKL98T12LWT Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit This patch should be better than the 1st one. As Michael suggested, the score is put in the QListViewItems. There is no check for whether there are rules for the group or not yet, but I tried it on a fairly large folder (several thousands of msg) and didn't notice any serious slowdown. -- Guillaume. http://www.telegraph-road.org --------------Boundary-00=_X1NVRX2XISKL98T12LWT Content-Type: text/x-c; charset="iso-8859-1"; name="kmail_score_patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="kmail_score_patch" ? patch ? kmscoring.h ? kmscoring.cpp Index: Makefile.am =================================================================== RCS file: /home/kde/kdenetwork/kmail/Makefile.am,v retrieving revision 1.109 diff -u -r1.109 Makefile.am --- Makefile.am 2001/04/08 15:34:35 1.109 +++ Makefile.am 2001/04/16 08:23:11 @@ -25,6 +25,7 @@ kmnewiostatus.cpp kmnewiostatuswdg.cpp \ kmtopwidget.cpp kmacctimap.cpp \ kmundostack.cpp kmbroadcaststatus.cpp \ + kmscoring.cpp \ kmacctexppop.cpp configuredialog.cpp colorlistbox.cpp \ kmkernel.cpp kmailIface.skel kmailIface.stub main.cpp \ accountdialog.cpp kmfldsearch.cpp addtoaddressbook.cpp \ Index: configuredialog.cpp =================================================================== RCS file: /home/kde/kdenetwork/kmail/configuredialog.cpp,v retrieving revision 1.97 diff -u -r1.97 configuredialog.cpp --- configuredialog.cpp 2001/04/14 09:19:43 1.97 +++ configuredialog.cpp 2001/04/16 08:23:19 @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,8 @@ #include #include #include +#include +#include #include "accountdialog.h" @@ -79,6 +82,7 @@ #include "kmmessage.h" #include "kmsender.h" #include "kmtopwidget.h" +#include "kmscoring.h" #include "configuredialog.moc" @@ -996,6 +1000,17 @@ mAppearance.addressbookLabel->setText(*mAppearance.addressbookStrings.at(0)); vlay->addWidget( mAppearance.addressbookLabel ); vlay->addStretch(10); + + // Score + QWidget *page6 = new QWidget( tabWidget ); + tabWidget->addTab( page6, i18n("Messages Scoring") ); + vlay = new QVBoxLayout( page6, spacingHint() ); + + KScoringRulesConfig* ksc = + new KScoringRulesConfig(KMScoringManager::globalScoringManager(), + false, page6); + vlay->addWidget( ksc ); + } @@ -1435,8 +1450,6 @@ topLevel->addStretch( 10 ); } - - void ConfigureDialog::setup( void ) { setupIdentityPage(); @@ -2248,6 +2261,9 @@ config.writeEntry( "exec-on-mail-cmd", mMisc.mailCommandEdit->text() ); } + + kdDebug() << "KMScoringManager::globalScoringManager()->save();" << endl; + KMScoringManager::globalScoringManager()->save(); // // Always Index: configuredialog.h =================================================================== RCS file: /home/kde/kdenetwork/kmail/configuredialog.h,v retrieving revision 1.37 diff -u -r1.37 configuredialog.h --- configuredialog.h 2001/04/15 09:37:48 1.37 +++ configuredialog.h 2001/04/16 08:23:20 @@ -236,6 +236,8 @@ QString *i18nPath; }; +class KScoringRulesConfig; + class ConfigureDialog : public KDialogBase { Q_OBJECT Index: kmheaders.cpp =================================================================== RCS file: /home/kde/kdenetwork/kmail/kmheaders.cpp,v retrieving revision 1.261 diff -u -r1.261 kmheaders.cpp --- kmheaders.cpp 2001/04/14 09:19:43 1.261 +++ kmheaders.cpp 2001/04/16 08:23:28 @@ -37,7 +37,7 @@ #include "kmundostack.h" #include "kmreaderwin.h" #include "kmacctimap.h" - +#include "kmscoring.h" #include #include #include @@ -79,7 +79,7 @@ public: KMFolder *mFolder; - int mMsgId; + int mMsgId, mScore; QColor *mColor; QString mSortDate, mSortArrival; KMPaintInfo *mPaintInfo; @@ -90,6 +90,7 @@ : QListViewItem( parent ), mFolder( folder ), mMsgId( msgId ), + mScore( 0 ), mPaintInfo( aPaintInfo ) { irefresh(); @@ -101,6 +102,7 @@ : QListViewItem( parent ), mFolder( folder ), mMsgId( msgId ), + mScore( 0 ), mPaintInfo( aPaintInfo ) { irefresh(); @@ -112,6 +114,11 @@ mMsgId = aMsgId; } + void setScore( int aScore ) + { + mScore = aScore; + } + // Profiling note: About 30% of the time taken to initialize the // listview is spent in this function. About 60% is spent in operator // new and QListViewItem::QListViewItem. @@ -150,7 +157,9 @@ setText( mPaintInfo->dateCol, QString( ctime( &mDate )).stripWhiteSpace() ); if (mPaintInfo->showSize) - setText( mPaintInfo->sizeCol, QString( "%1" ).arg( mMsgBase->msgSize())); + setText( mPaintInfo->sizeCol, QString( "%1" ).arg( mMsgBase->msgSize() ) ); + + setText( mPaintInfo->scoreCol, QString( "%1" ).arg( mScore )); mColor = &mPaintInfo->colFore; @@ -321,10 +330,11 @@ readConfig(); mPaintInfo.flagCol = -1; - mPaintInfo.subCol = mPaintInfo.flagCol + 1; - mPaintInfo.senderCol = mPaintInfo.subCol + 1; - mPaintInfo.dateCol = mPaintInfo.senderCol + 1; - mPaintInfo.sizeCol = mPaintInfo.dateCol + 1; + mPaintInfo.subCol = mPaintInfo.flagCol + 1; + mPaintInfo.senderCol = mPaintInfo.subCol + 1; + mPaintInfo.dateCol = mPaintInfo.senderCol + 1; + mPaintInfo.sizeCol = mPaintInfo.dateCol + 1; + mPaintInfo.scoreCol = mPaintInfo.sizeCol + 1; mSortCol = KMMsgList::sfDate; mSortDescending = FALSE; setShowSortIndicator(true); @@ -341,6 +351,8 @@ showingSize = false; } + addColumn( i18n("Score"), 80 ); + if (!pixmapsLoaded) { pixmapsLoaded = TRUE; @@ -625,6 +637,7 @@ readFolderConfig(); mFolder->open(); + //mFolder->scoreMessages(); if ((mNested && !mNestedOverride) || (!mNested && mNestedOverride)) { clear(); @@ -705,6 +718,9 @@ } } + colText = i18n( "Score" ); + setColumnText( mPaintInfo.scoreCol, colText); + } // QListView::setContentsPos doesn't seem to work @@ -2027,12 +2043,69 @@ } } + scoreMessages(); + KMHeadersInherited::setSorting( mSortCol, !mSortDescending ); sort(); connect(this,SIGNAL(currentChanged(QListViewItem*)), this,SLOT(highlightMessage(QListViewItem*))); } + +void +KMHeaders::scoreMessages() +{ + kdDebug() << "KMHeaders::scoreMessages() begin" << endl; + // score messages + // + // TODO : first check if there are rules for this folder + // + KMScoringManager* sm = KMScoringManager::globalScoringManager(); + if (!sm) { + kdDebug() << "KMHeaders::scoreMessages() : no globalScoringManager" + << endl; + return; + } + + if (folder() && folder()->name()) sm->initCache(folder()->name()); + + for (int i = 0; i < folder()->count(); i++) + { + QCString cStr; + + folder()->getMsgString(i, cStr); + + if (!cStr) { + kdDebug() << "KMFolder::scoreMessages() : Skipping msg" << endl; + continue; + } + KMScorableArticle smsg(cStr); + + sm->applyRules(smsg); + + if (smsg.score()) { + KMHeaderItem *msgItem = mItems[i]; // check this ??? + if (msgItem) { + kdDebug() << "KMHeaders::scoreMessages() : setting score " + << smsg.score() << " to msg " + << i << " (" << msgItem->text(1) << ")" << endl; + msgItem->setScore(smsg.score()); + msgItem->irefresh(); + } + else + kdDebug() << "KMHeaders::scoreMessages() : no msgItem at idx " + << i << endl; + + kdDebug() << "KMHeaders::scoreMessages() : score = " + << smsg.score() << endl; + } + + } + + kdDebug() << "KMHeaders::scoreMessages() end" << endl; + +} + //----------------------------------------------------------------------------- // KMail Header list selection/navigation description Index: kmheaders.h =================================================================== RCS file: /home/kde/kdenetwork/kmail/kmheaders.h,v retrieving revision 1.68 diff -u -r1.68 kmheaders.h --- kmheaders.h 2001/04/05 20:19:09 1.68 +++ kmheaders.h 2001/04/16 08:23:29 @@ -49,6 +49,7 @@ int subCol; int dateCol; int sizeCol; + int scoreCol; }; #define KMHeadersInherited QListView @@ -251,6 +252,7 @@ // Is equivalent to clearing the list and inserting an item for // each message in the current folder virtual void updateMessageList(void); + virtual void scoreMessages(void); KMFolder* mFolder; // Currently associated folder KMMainWin* mOwner; // The KMMainWin for status bar updates Index: kmmessage.cpp =================================================================== RCS file: /home/kde/kdenetwork/kmail/kmmessage.cpp,v retrieving revision 1.183 diff -u -r1.183 kmmessage.cpp --- kmmessage.cpp 2001/04/08 15:34:35 1.183 +++ kmmessage.cpp 2001/04/16 08:23:36 @@ -57,12 +57,12 @@ //----------------------------------------------------------------------------- KMMessage::KMMessage(DwMessage* aMsg) + : mMsg(aMsg), + mNeedsAssembly(true), + mIsComplete(false), + mTransferInProgress(false), + mCodec(0) { - mNeedsAssembly = TRUE; - mMsg = aMsg; - mCodec = NULL; - mIsComplete = FALSE; - mTransferInProgress = FALSE; } --------------Boundary-00=_X1NVRX2XISKL98T12LWT Content-Type: text/x-c++; charset="iso-8859-1"; name="kmscoring.h" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="kmscoring.h" /* * kmscoring.h * * kmail: KDE mail client * This file: Copyright (C) 2000 Espen Sand, espen@kde.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US */ #ifndef KMSCORING_H #define KMSCORING_H #include #include class KDialogBase; class KMScorableArticle : public ScorableArticle { public: KMScorableArticle(const QString&); virtual ~KMScorableArticle(); virtual void addScore(short s); virtual QString from() const; virtual QString subject() const; virtual QString getHeaderByType(const QString&) const; int score() const { return mScore; } private: QString mMsgStr; int mScore; mutable QMap mParsedHeaders; }; class KMScorableGroup : public ScorableGroup { public: KMScorableGroup(); virtual ~KMScorableGroup(); }; class KMScoringManager : public KScoringManager { Q_OBJECT public: KMScoringManager(); virtual ~KMScoringManager(); virtual QStringList getGroups() const; void configure(); static KMScoringManager* globalScoringManager(); protected: KDialogBase *mConfDialog; static KMScoringManager *mScoringManager; protected slots: void slotDialogDone(); }; #endif --------------Boundary-00=_X1NVRX2XISKL98T12LWT Content-Type: text/x-c; charset="iso-8859-1"; name="kmscoring.cpp" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="kmscoring.cpp" #include #include #include "kmmessage.h" #include "kmfoldermgr.h" #include "kmkernel.h" #include "kmscoring.h" KMScorableArticle::KMScorableArticle(const QString &msg) : mMsgStr(msg), mScore(0) { } KMScorableArticle::~KMScorableArticle() { } void KMScorableArticle::addScore(short s) { mScore += s; } QString KMScorableArticle::from() const { return getHeaderByType("From:"); } QString KMScorableArticle::subject() const { return getHeaderByType("Subject:"); } QString KMScorableArticle::getHeaderByType(const QString &header) const { if (mParsedHeaders.contains(header)) { return mParsedHeaders[header]; } QString value; int start = 0, stop = 0; char ch = 0; start = mMsgStr.find(header); if (start == -1) return QString::null; if (mMsgStr.find("\n\n") < start) return QString::null; stop = mMsgStr.find("\n", start + 1); while (stop != -1 && (ch = mMsgStr.at(stop + 1)) == ' ' || ch == '\t') stop = mMsgStr.find("\n", stop + 1); if (stop == -1) value = KMMsgBase::decodeRFC2047String(mMsgStr.mid(start)); else value = KMMsgBase::decodeRFC2047String(mMsgStr.mid(start, stop - start)); value.remove(0, header.length()); value = value.stripWhiteSpace(); mParsedHeaders[header] = value; return value; } ////////////////////////////// KMScorableGroup::KMScorableGroup() { } KMScorableGroup::~KMScorableGroup() { } ////////////////////////////// KMScoringManager::KMScoringManager() : mConfDialog(0) { } KMScoringManager::~KMScoringManager() { } class KMFolder; QStringList KMScoringManager::getGroups() const { QValueList > dummy; QStringList res; kernel->folderMgr()->createFolderList( &res, &dummy ); return res; } void KMScoringManager::configure() { } void KMScoringManager::slotDialogDone() { } KMScoringManager* KMScoringManager::globalScoringManager() { if ( !mScoringManager ) mScoringManager = new KMScoringManager; return mScoringManager; } KMScoringManager* KMScoringManager::mScoringManager = 0; --------------Boundary-00=_X1NVRX2XISKL98T12LWT-- _______________________________________________ Kmail Developers mailing list Kmail@master.kde.org http://master.kde.org/mailman/listinfo/kmail