summaryrefslogtreecommitdiffstats
path: root/kmail/searchjob.h
blob: 0fe6bdf884065655235be638bf03ff2a8cfabc04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (c) 2004 Carsten Burghardt <burghardt@kde.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *  In addition, as a special exception, the copyright holders give
 *  permission to link the code of this program with any edition of
 *  the Qt library by Trolltech AS, Norway (or with modified versions
 *  of Qt that use the same license as Qt), and distribute linked
 *  combinations including the two.  You must obey the GNU General
 *  Public License in all respects for all of the code used other than
 *  Qt.  If you modify this file, you may extend this exception to
 *  your version of the file, but you are not obligated to do so.  If
 *  you do not wish to do so, delete this exception statement from
 *  your version.
 */
#ifndef SEARCHJOB_H
#define SEARCHJOB_H

#include <tqstringlist.h>
#include "folderjob.h"

class KMFolderImap;
class KMSearchPattern;
class KURL;

namespace KIO {
  class Job;
}

namespace KPIM {
  class ProgressItem;
}

namespace KMail {

class ImapAccountBase;

/**
 * Search job
 */
class SearchJob : public FolderJob
{
  Q_OBJECT
public:
  /**
   * Creates a new job
   * @param folder the folder that should be searched
   * @param account the ImapAccountBase of the folder
   * @param pattern the search pattern
   * @param serNum if you specify the serNum only this is checked
   */
  SearchJob( KMFolderImap* folder, ImapAccountBase* account,
             const KMSearchPattern* pattern, TQ_UINT32 serNum = 0 );

  virtual ~SearchJob();

  // Execute
  virtual void execute();

protected:
  // searches the complete folder with the pattern
  void searchCompleteFolder();

  // checks a single message with the pattern
  void searchSingleMessage();

  // creates an imap search command
  TQString searchStringFromPattern( const KMSearchPattern* );

  // returns true if all uids can be mapped to sernums
  bool canMapAllUIDs();

  // if we need to download messages
  bool needsDownload();

protected slots:
  // search the folder
  // is called when all uids can be mapped to sernums
  void slotSearchFolder();

  // processes the server answer
  void slotSearchData( KIO::Job* job, const TQString& data );

  // message is downloaded and searched
  void slotSearchMessageArrived( KMMessage* msg );

  // error handling for all cases
  void slotSearchResult( KIO::Job *job );

  // imap search result from a single message
  void slotSearchDataSingleMessage( KIO::Job* job, const TQString& data );

  // the user cancelled the search progress
  void slotAbortSearch( KPIM::ProgressItem* item );

signals:
  // emitted when a list of matching serial numbers was found
  void searchDone( TQValueList<TQ_UINT32>, const KMSearchPattern*, bool complete );

  // emitted when a single message (identified by the serial number) was checked
  void searchDone( TQ_UINT32, const KMSearchPattern*, bool matches );

protected:
  KMFolderImap* mFolder;
  ImapAccountBase* mAccount;
  const KMSearchPattern* mSearchPattern;
  KMSearchPattern* mLocalSearchPattern;
  TQ_UINT32 mSerNum;
    // saves the results of the imap search
  TQStringList mImapSearchHits;
  // collects the serial numbers from imap and local search
  TQValueList<TQ_UINT32> mSearchSerNums;
  // the remaining messages that have to be downloaded for local search
  uint mRemainingMsgs;
  // progress item for local searches
  KPIM::ProgressItem *mProgress;
  bool mUngetCurrentMsg;

};

} // namespace

#endif /* SEARCHJOB_H */