index.h
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 TQt library by Trolltech AS, Norway (or with modified versions 00024 * of TQt that use the same license as TQt), 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 * TQt. 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 <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, // doing nothing, index waiting 00168 s_willcreate, // just constructed, create() scheduled (mIndex == 0) 00169 s_creating, // creating the index from the messages 00170 s_processing, // has messages to process 00171 s_error, // an error occurred 00172 s_disabled // disabled: the index is not working 00173 } mState; 00174 00175 unsigned mMaintenanceCount; 00176 00177 #ifdef HAVE_INDEXLIB 00178 00182 indexlib::detail::lockfile mLockFile; 00183 //enum e_syncState { ss_none, ss_started, ss_synced } mSyncState; 00184 //TQTimer* mSyncTimer; 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 /* LPC_INDEX_H1110724080_INCLUDE_GUARD_ */