kmail

index.h

Go to the documentation of this file.
00001 #ifndef LPC_INDEX_H1110724080_INCLUDE_GUARD_
00002 #define LPC_INDEX_H1110724080_INCLUDE_GUARD_
00003 
00004 /* This file is part of KMail
00005  * Copyright (C) 2005 Luís Pedro Coelho <luis@luispedro.org>
00006  * (based on the old kmmsgindex by Sam Magnuson)
00007  *
00008  * KMail is free software; you can redistribute it and/or modify it
00009  * under the terms of the GNU General Public License, version 2, as
00010  * published by the Free Software Foundation.
00011  *
00012  * KMail is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020  *
00021  * In addition, as a special exception, the copyright holders give
00022  * permission to link the code of this program with any edition of
00023  * the Qt library by Trolltech AS, Norway (or with modified versions
00024  * of Qt that use the same license as Qt), and distribute linked
00025  * combinations including the two.  You must obey the GNU General
00026  * Public License in all respects for all of the code used other than
00027  * Qt.  If you modify this file, you may extend this exception to
00028  * your version of the file, but you are not obligated to do so.  If
00029  * you do not wish to do so, delete this exception statement from
00030  * your version.
00031  */
00032 
00033 
00034 #include <qobject.h>
00035 #include <qcstring.h>
00036 #include <qvaluelist.h>
00037 #include <qtimer.h>
00038 #include <config.h>
00039 #ifdef HAVE_INDEXLIB
00040 #include <indexlib/index.h>
00041 #include <indexlib/lockfile.h>
00042 #endif
00043 #include <vector>
00044 #include <set>
00045 
00046 class KMFolder;
00047 
00048 class KMSearch;
00049 class KMSearchRule;
00050 class KMSearchPattern;
00051 
00052 class KMMsgIndex : public QObject {
00053     Q_OBJECT
00054     public:
00055         explicit KMMsgIndex( QObject* parent );
00056         ~KMMsgIndex();
00057 
00058     public:
00059 
00066         bool startQuery( KMSearch* );
00072         bool stopQuery( KMSearch* );
00073 
00077         std::vector<Q_UINT32> simpleSearch( QString, bool* ) const;
00078 
00086         bool isIndexable( KMFolder* folder ) const;
00087 
00094         bool isIndexed( KMFolder* folder ) const;
00095 
00099         bool isEnabled() const { return mState != s_disabled; }
00100     public slots:
00110         void setEnabled( bool );
00111 
00118         void setIndexingEnabled( KMFolder*, bool );
00119 
00120     private slots:
00127         void clear();
00128         void create();
00129         void maintenance();
00130 
00131         void act();
00132         void removeSearch( QObject* );
00133 
00134         void continueCreation();
00135 
00136         void slotAddMessage( Q_UINT32 message );
00137         void slotRemoveMessage( Q_UINT32 message );
00138     private:
00139         static QString defaultPath();
00140 
00141         bool canHandleQuery( const KMSearchPattern* ) const;
00142         int addMessage( Q_UINT32 );
00143         void removeMessage( Q_UINT32 );
00144 
00145         void scheduleAction();
00146         bool creating() const;
00147 
00148     public:
00156         class Search;
00157     private:
00158 
00159         std::vector<Q_UINT32> mPendingMsgs;
00160         std::vector<KMFolder*> mPendingFolders;
00161         std::vector<Q_UINT32> mAddedMsgs;
00162         std::vector<Q_UINT32> mRemovedMsgs;
00163         std::vector<Q_UINT32> mExisting;
00164 
00165         enum e_state {
00166             s_idle, // doing nothing, index waiting
00167             s_willcreate, // just constructed, create() scheduled (mIndex == 0)
00168             s_creating, // creating the index from the messages
00169             s_processing, // has messages to process
00170             s_error, // an error occurred
00171             s_disabled // disabled: the index is not working
00172         } mState;
00173 
00174         unsigned mMaintenanceCount;
00175 
00176 #ifdef HAVE_INDEXLIB
00177 
00181         indexlib::detail::lockfile mLockFile;
00182         //enum e_syncState { ss_none, ss_started, ss_synced } mSyncState;
00183         //QTimer* mSyncTimer;
00184 
00185         indexlib::index* mIndex;
00186 #endif
00187         std::set<KMFolder*> mOpenedFolders;
00188         std::vector<Search*> mSearches;
00189         QCString mIndexPath;
00190         QTimer* mTimer;
00191         bool mSlowDown;
00192 };
00193 
00194 
00195 class KMMsgIndex::Search : public QObject {
00196     Q_OBJECT
00197     public:
00198         explicit Search( KMSearch* s );
00199         ~Search();
00200         KMSearch* search() const { return mSearch; }
00201     signals:
00202         void found( Q_UINT32 );
00203         void finished( bool );
00204     private slots:
00205         void act();
00206     private:
00207         KMSearch* mSearch;
00208         QTimer* mTimer;
00213         KMSearchPattern* mResidual;
00214         std::vector<Q_UINT32> mValues;
00215         enum { s_none = 0, s_starting, s_emitting, s_emitstopped, s_done } mState;
00216 };
00217 
00218 #endif /* LPC_INDEX_H1110724080_INCLUDE_GUARD_ */