kmail

index.h
1 #ifndef LPC_INDEX_H1110724080_INCLUDE_GUARD_
2 #define LPC_INDEX_H1110724080_INCLUDE_GUARD_
3 
4 /* This file is part of KMail
5  * Copyright (C) 2005 Luís Pedro Coelho <luis@luispedro.org>
6  * (based on the old kmmsgindex by Sam Magnuson)
7  *
8  * KMail is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License, version 2, as
10  * published by the Free Software Foundation.
11  *
12  * KMail is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  * In addition, as a special exception, the copyright holders give
22  * permission to link the code of this program with any edition of
23  * the TQt library by Trolltech AS, Norway (or with modified versions
24  * of TQt that use the same license as TQt), and distribute linked
25  * combinations including the two. You must obey the GNU General
26  * Public License in all respects for all of the code used other than
27  * TQt. If you modify this file, you may extend this exception to
28  * your version of the file, but you are not obligated to do so. If
29  * you do not wish to do so, delete this exception statement from
30  * your version.
31  */
32 
33 
34 #include <tqobject.h>
35 #include <tqcstring.h>
36 #include <tqvaluelist.h>
37 #include <tqtimer.h>
38 #include <config.h>
39 #ifdef HAVE_INDEXLIB
40 #include <indexlib/index.h>
41 #include <indexlib/lockfile.h>
42 #endif
43 #include <vector>
44 #include <set>
45 
46 class KMFolder;
47 
48 class KMSearch;
49 class KMSearchRule;
50 class KMSearchPattern;
51 
52 class KMMsgIndex : public TQObject {
53  TQ_OBJECT
54 
55  public:
56  explicit KMMsgIndex( TQObject* parent );
57  ~KMMsgIndex();
58 
59  public:
60 
67  bool startQuery( KMSearch* );
73  bool stopQuery( KMSearch* );
74 
78  std::vector<TQ_UINT32> simpleSearch( TQString, bool* ) const;
79 
87  bool isIndexable( KMFolder* folder ) const;
88 
95  bool isIndexed( KMFolder* folder ) const;
96 
100  bool isEnabled() const { return mState != s_disabled; }
101  public slots:
111  void setEnabled( bool );
112 
119  void setIndexingEnabled( KMFolder*, bool );
120 
121  private slots:
128  void clear();
129  void create();
130  void maintenance();
131 
132  void act();
133  void removeSearch( TQObject* );
134 
135  void continueCreation();
136 
137  void slotAddMessage( KMFolder*, TQ_UINT32 message );
138  void slotRemoveMessage( KMFolder*, TQ_UINT32 message );
139  private:
140  static TQString defaultPath();
141 
142  bool canHandleQuery( const KMSearchPattern* ) const;
143  int addMessage( TQ_UINT32 );
144  void removeMessage( TQ_UINT32 );
145 
146  void scheduleAction();
147  bool creating() const;
148 
149  public:
157  class Search;
158  private:
159 
160  std::vector<TQ_UINT32> mPendingMsgs;
161  std::vector<KMFolder*> mPendingFolders;
162  std::vector<TQ_UINT32> mAddedMsgs;
163  std::vector<TQ_UINT32> mRemovedMsgs;
164  std::vector<TQ_UINT32> mExisting;
165 
166  enum e_state {
167  s_idle, // doing nothing, index waiting
168  s_willcreate, // just constructed, create() scheduled (mIndex == 0)
169  s_creating, // creating the index from the messages
170  s_processing, // has messages to process
171  s_error, // an error occurred
172  s_disabled // disabled: the index is not working
173  } mState;
174 
175  unsigned mMaintenanceCount;
176 
177 #ifdef HAVE_INDEXLIB
182  indexlib::detail::lockfile mLockFile;
183  //enum e_syncState { ss_none, ss_started, ss_synced } mSyncState;
184  //TQTimer* mSyncTimer;
185 
186  indexlib::index* mIndex;
187 #endif
188  std::set<KMFolder*> mOpenedFolders;
189  std::vector<Search*> mSearches;
190  TQCString mIndexPath;
191  TQTimer* mTimer;
192  bool mSlowDown;
193 };
194 
195 
196 class KMMsgIndex::Search : public TQObject {
197  TQ_OBJECT
198 
199  public:
200  explicit Search( KMSearch* s );
201  ~Search();
202  KMSearch* search() const { return mSearch; }
203  signals:
204  void found( TQ_UINT32 );
205  void finished( bool );
206  private slots:
207  void act();
208  private:
209  KMSearch* mSearch;
210  TQTimer* mTimer;
215  KMSearchPattern* mResidual;
216  std::vector<TQ_UINT32> mValues;
217  enum { s_none = 0, s_starting, s_emitting, s_emitstopped, s_done } mState;
218 };
219 
220 #endif /* LPC_INDEX_H1110724080_INCLUDE_GUARD_ */
Mail folder.
Definition: kmfolder.h:69
This class is an abstraction of a search over messages.
Incoming mail is sent through the list of mail filter rules before it is placed in the associated mai...