kmail

antispamwizard.h

00001 /*  -*- mode: C++ -*-
00002     This file is part of KMail.
00003     Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
00004 
00005     KMail is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU General Public License, version 2, as
00007     published by the Free Software Foundation.
00008 
00009     KMail is distributed in the hope that it will be useful, but
00010     WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018     In addition, as a special exception, the copyright holders give
00019     permission to link the code of this program with any edition of
00020     the Qt library by Trolltech AS, Norway (or with modified versions
00021     of Qt that use the same license as Qt), and distribute linked
00022     combinations including the two.  You must obey the GNU General
00023     Public License in all respects for all of the code used other than
00024     Qt.  If you modify this file, you may extend this exception to
00025     your version of the file, but you are not obligated to do so.  If
00026     you do not wish to do so, delete this exception statement from
00027     your version.
00028 */
00029 #ifndef KMAIL_ANTISPAMWIZARD_H
00030 #define KMAIL_ANTISPAMWIZARD_H
00031 
00032 #include "simplefoldertree.h"
00033 
00034 #include <kconfig.h>
00035 #include <klistbox.h>
00036 #include <kwizard.h>
00037 
00038 #include <qcheckbox.h>
00039 #include <qdict.h>
00040 #include <qlayout.h>
00041 
00042 class KActionCollection;
00043 class KMFolder;
00044 class KMFolderTree;
00045 class QLabel;
00046 
00047 namespace KMail {
00048 
00049   class FolderRequester;
00050 
00051   class ASWizInfoPage;
00052   class ASWizSpamRulesPage;
00053   class ASWizVirusRulesPage;
00054   class ASWizSummaryPage;
00055 
00056   //---------------------------------------------------------------------------
00104   class AntiSpamWizard : public KWizard
00105   {
00106     Q_OBJECT
00107 
00108     public:
00112       enum WizardMode { AntiSpam, AntiVirus };
00113 
00122       AntiSpamWizard( WizardMode mode,
00123                       QWidget * parent, KMFolderTree * mainFolderTree );
00124 
00125     protected:
00131       class SpamToolConfig
00132       {
00133         public:
00134           SpamToolConfig() {}
00135           SpamToolConfig( QString toolId, int configVersion, int prio,
00136                         QString name, QString exec, QString url, QString filter,
00137                         QString detection, QString spam, QString ham,
00138                         QString header, QString pattern, QString pattern2,
00139                         QString serverPattern,
00140                         bool detectionOnly, bool regExp, bool bayesFilter, 
00141                         bool tristateDetection, WizardMode type );
00142 
00143           int getVersion() const { return mVersion; }
00144           int getPrio() const { return mPrio; }
00145           QString getId()  const { return mId; }
00146           QString getVisibleName()  const { return mVisibleName; }
00147           QString getExecutable() const { return mExecutable; }
00148           QString getWhatsThisText() const { return mWhatsThisText; }
00149           QString getFilterName() const { return mFilterName; }
00150           QString getDetectCmd() const { return mDetectCmd; }
00151           QString getSpamCmd() const { return mSpamCmd; }
00152           QString getHamCmd() const { return mHamCmd; }
00153           QString getDetectionHeader() const { return mDetectionHeader; }
00154           QString getDetectionPattern() const { return mDetectionPattern; }
00155           QString getDetectionPattern2() const { return mDetectionPattern2; }
00156           QString getServerPattern() const { return mServerPattern; }
00157           bool isServerBased() const;
00158           bool isDetectionOnly() const { return mDetectionOnly; }
00159           bool isUseRegExp() const { return mUseRegExp; }
00160           bool useBayesFilter() const { return mSupportsBayesFilter; }
00161           bool hasTristateDetection() const { return mSupportsUnsure; }
00162           WizardMode getType() const { return mType; }
00163           // convinience methods for types
00164           bool isSpamTool() const { return ( mType == AntiSpam ); }
00165           bool isVirusTool() const { return ( mType == AntiVirus ); }
00166 
00167         private:
00168           // used to identifiy configs for the same tool
00169           QString mId;
00170           // The version of the config data, used for merging and
00171           // detecting newer configs
00172           int mVersion;
00173           // the priority of the tool in the list presented to the user
00174           int mPrio;
00175           // the name as shown by the checkbox in the dialog page
00176           QString mVisibleName;
00177           // the command to check the existance of the tool
00178           QString mExecutable;
00179           // the What's This help text (e.g. url for the tool)
00180           QString mWhatsThisText;
00181           // name for the created filter in the filter list
00182           QString mFilterName;
00183           // pipe through cmd used to detect spam messages
00184           QString mDetectCmd;
00185           // pipe through cmd to let the tool learn a spam message
00186           QString mSpamCmd;
00187           // pipe through cmd to let the tool learn a ham message
00188           QString mHamCmd;
00189           // by which header are messages marked as spam
00190           QString mDetectionHeader;
00191           // what header pattern is used to mark spam messages
00192           QString mDetectionPattern;
00193           // what header pattern is used to mark unsure messages
00194           QString mDetectionPattern2;
00195           // what header pattern is used in the account to check for a certain server
00196           QString mServerPattern;
00197           // filter cannot search actively but relies on pattern by regExp or contain rule
00198           bool mDetectionOnly;
00199           // filter searches for the pattern by regExp or contain rule
00200           bool mUseRegExp;
00201           // can the tool learn spam and ham, has it a bayesian algorithm
00202           bool mSupportsBayesFilter;
00203           // differentiate between ham, spam and a third "unsure" state
00204           bool mSupportsUnsure;
00205           // Is the tool AntiSpam or AntiVirus
00206           WizardMode mType;
00207       };
00208 
00214       class ConfigReader
00215       {
00216         public:
00217           ConfigReader( WizardMode mode,
00218                         QValueList<SpamToolConfig> & configList );
00219           ~ConfigReader( );
00220 
00221           QValueList<SpamToolConfig> & getToolList() { return mToolList; }
00222 
00223           void readAndMergeConfig();
00224 
00225         private:
00226           QValueList<SpamToolConfig> & mToolList;
00227           KConfig *mConfig;
00228           WizardMode mMode;
00229 
00230           SpamToolConfig readToolConfig( KConfigGroup & configGroup );
00231           SpamToolConfig createDummyConfig();
00232 
00233           void mergeToolConfig( SpamToolConfig config );
00234           void sortToolList();
00235       };
00236 
00238       void accept();
00239 
00240     protected slots:
00242       void checkProgramsSelections();
00244       void checkVirusRulesSelections();
00246       void checkToolAvailability();
00248       void slotHelpClicked();
00250       void slotBuildSummary();
00251 
00252     private:
00253       /* Check for the availability of an executible along the PATH */
00254       int checkForProgram( const QString &executable );
00255       /* generic checks if any option in a page is checked */
00256       bool anyVirusOptionChecked();
00257       /* convenience method calling the appropriate filter manager method */
00258       const QString uniqueNameFor( const QString & name );
00259       /* convenience method to sort out new and existing filters */
00260       void sortFilterOnExistance( const QString & intendedFilterName,
00261                                   QString & newFilters, 
00262                                   QString & replaceFilters );
00263 
00264       /* The pages in the wizard */
00265       ASWizInfoPage * mInfoPage;
00266       ASWizSpamRulesPage * mSpamRulesPage;
00267       ASWizVirusRulesPage * mVirusRulesPage;
00268       ASWizSummaryPage * mSummaryPage;
00269 
00270       /* The configured tools and it's settings to be used in the wizard. */
00271       QValueList<SpamToolConfig> mToolList;
00272 
00273       /* Are any spam tools selected? */
00274       bool mSpamToolsUsed;
00275       /* Are any virus tools selected? */
00276       bool mVirusToolsUsed;
00277 
00278       WizardMode mMode;
00279   };
00280 
00281 
00282   //---------------------------------------------------------------------------
00283   class ASWizPage : public QWidget
00284   {
00285     public:
00286       ASWizPage( QWidget *parent, const char *name, 
00287                  const QString *bannerName = 0);
00288 
00289     protected:
00290       QBoxLayout *mLayout;
00291 
00292     private:
00293       QPixmap *mPixmap;
00294       QLabel *mBannerLabel;
00295   };
00296 
00297 
00298   //---------------------------------------------------------------------------
00299   class ASWizInfoPage : public ASWizPage
00300   {
00301     Q_OBJECT
00302 
00303     public:
00304       ASWizInfoPage( AntiSpamWizard::WizardMode mode,
00305                      QWidget *parent, const char *name );
00306 
00307       void setScanProgressText( const QString &toolName );
00308       void addAvailableTool( const QString &visibleName );
00309       bool isProgramSelected( const QString &visibleName );
00310 
00311     private slots:
00312       void processSelectionChange();
00313 
00314     signals:
00315       void selectionChanged();
00316 
00317     private:
00318       QLabel *mIntroText;
00319       QLabel *mScanProgressText;
00320       QLabel *mSelectionHint;
00321       KListBox *mToolsList;
00322   };
00323 
00324   //---------------------------------------------------------------------------
00325   class ASWizSpamRulesPage : public ASWizPage
00326   {
00327     Q_OBJECT
00328 
00329     public:
00330       ASWizSpamRulesPage( QWidget * parent, const char * name, KMFolderTree * mainFolderTree );
00331 
00332       bool markAsReadSelected() const;
00333       bool moveSpamSelected() const;
00334       bool moveUnsureSelected() const;
00335 
00336       QString selectedSpamFolderName() const;
00337       QString selectedUnsureFolderName() const;
00338 
00339       void allowUnsureFolderSelection( bool enabled );
00340 
00341     private slots:
00342       void processSelectionChange();
00343       void processSelectionChange( KMFolder* );
00344 
00345     signals:
00346       void selectionChanged();
00347 
00348     private:
00349       QCheckBox * mMarkRules;
00350       QCheckBox * mMoveSpamRules;
00351       QCheckBox * mMoveUnsureRules;
00352       FolderRequester *mFolderReqForSpamFolder;
00353       FolderRequester *mFolderReqForUnsureFolder;
00354   };
00355 
00356   //-------------------------------------------------------------------------
00357   class ASWizVirusRulesPage : public ASWizPage
00358   {
00359     Q_OBJECT
00360 
00361     public:
00362       ASWizVirusRulesPage( QWidget * parent, const char * name, KMFolderTree * mainFolderTree );
00363 
00364       bool pipeRulesSelected() const;
00365       bool moveRulesSelected() const;
00366       bool markReadRulesSelected() const;
00367 
00368       QString selectedFolderName() const;
00369 
00370     private slots:
00371       void processSelectionChange();
00372     signals:
00373       void selectionChanged();
00374 
00375     private:
00376       QCheckBox * mPipeRules;
00377       QCheckBox * mMoveRules;
00378       SimpleFolderTree *mFolderTree;
00379       QCheckBox * mMarkRules;
00380   };
00381 
00382   //---------------------------------------------------------------------------
00383   class ASWizSummaryPage : public ASWizPage
00384   {
00385     Q_OBJECT
00386 
00387     public:
00388       ASWizSummaryPage( QWidget * parent, const char * name );
00389 
00390       void setSummaryText( const QString & text );
00391 
00392     private:
00393       QLabel * mSummaryText;
00394   };
00395 
00396 
00397 } // namespace KMail
00398 
00399 #endif // KMAIL_ANTISPAMWIZARD_H
KDE Home | KDE Accessibility Home | Description of Access Keys