00001 #ifndef LPC_INDEX_H1110724080_INCLUDE_GUARD_
00002 #define LPC_INDEX_H1110724080_INCLUDE_GUARD_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <tqobject.h>
00035 #include <tqcstring.h>
00036 #include <tqvaluelist.h>
00037 #include <tqtimer.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 TQObject {
00053 Q_OBJECT
00054
00055 public:
00056 explicit KMMsgIndex( TQObject* parent );
00057 ~KMMsgIndex();
00058
00059 public:
00060
00067 bool startQuery( KMSearch* );
00073 bool stopQuery( KMSearch* );
00074
00078 std::vector<TQ_UINT32> simpleSearch( TQString, bool* ) const;
00079
00087 bool isIndexable( KMFolder* folder ) const;
00088
00095 bool isIndexed( KMFolder* folder ) const;
00096
00100 bool isEnabled() const { return mState != s_disabled; }
00101 public slots:
00111 void setEnabled( bool );
00112
00119 void setIndexingEnabled( KMFolder*, bool );
00120
00121 private slots:
00128 void clear();
00129 void create();
00130 void maintenance();
00131
00132 void act();
00133 void removeSearch( TQObject* );
00134
00135 void continueCreation();
00136
00137 void slotAddMessage( KMFolder*, TQ_UINT32 message );
00138 void slotRemoveMessage( KMFolder*, TQ_UINT32 message );
00139 private:
00140 static TQString defaultPath();
00141
00142 bool canHandleQuery( const KMSearchPattern* ) const;
00143 int addMessage( TQ_UINT32 );
00144 void removeMessage( TQ_UINT32 );
00145
00146 void scheduleAction();
00147 bool creating() const;
00148
00149 public:
00157 class Search;
00158 private:
00159
00160 std::vector<TQ_UINT32> mPendingMsgs;
00161 std::vector<KMFolder*> mPendingFolders;
00162 std::vector<TQ_UINT32> mAddedMsgs;
00163 std::vector<TQ_UINT32> mRemovedMsgs;
00164 std::vector<TQ_UINT32> mExisting;
00165
00166 enum e_state {
00167 s_idle,
00168 s_willcreate,
00169 s_creating,
00170 s_processing,
00171 s_error,
00172 s_disabled
00173 } mState;
00174
00175 unsigned mMaintenanceCount;
00176
00177 #ifdef HAVE_INDEXLIB
00178
00182 indexlib::detail::lockfile mLockFile;
00183
00184
00185
00186 indexlib::index* mIndex;
00187 #endif
00188 std::set<KMFolder*> mOpenedFolders;
00189 std::vector<Search*> mSearches;
00190 TQCString mIndexPath;
00191 TQTimer* mTimer;
00192 bool mSlowDown;
00193 };
00194
00195
00196 class KMMsgIndex::Search : public TQObject {
00197 Q_OBJECT
00198
00199 public:
00200 explicit Search( KMSearch* s );
00201 ~Search();
00202 KMSearch* search() const { return mSearch; }
00203 signals:
00204 void found( TQ_UINT32 );
00205 void finished( bool );
00206 private slots:
00207 void act();
00208 private:
00209 KMSearch* mSearch;
00210 TQTimer* mTimer;
00215 KMSearchPattern* mResidual;
00216 std::vector<TQ_UINT32> mValues;
00217 enum { s_none = 0, s_starting, s_emitting, s_emitstopped, s_done } mState;
00218 };
00219
00220 #endif