| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef SEARCHSERVICE_H |
| 19 |
#define SEARCHSERVICE_H |
| 20 |
|
| 21 |
#include <QObject> |
| 22 |
#include <QPointer> |
| 23 |
#include <QQueue> |
| 24 |
#include <qmailmessage.h> |
| 25 |
#include <qmailserviceaction.h> |
| 26 |
|
| 27 |
struct QueryConfiguration { |
| 28 |
QString qeury; |
| 29 |
QMailMessageKey key; |
| 30 |
QMailSearchAction::SearchSpecification spec; |
| 31 |
QMailMessageSortKey sortKey; |
| 32 |
|
| 33 |
bool isValid() { |
| 34 |
return !key.isEmpty(); |
| 35 |
} |
| 36 |
}; |
| 37 |
|
| 38 |
struct SearchQuery { |
| 39 |
QPointer<QMailSearchAction> action; |
| 40 |
QueryConfiguration qConfig; |
| 41 |
SearchQuery(QMailSearchAction *sa, const QueryConfiguration &q): action(sa), qConfig(q) {} |
| 42 |
SearchQuery() {} |
| 43 |
void execute(); |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
class SearchService : public QObject |
| 58 |
{ |
| 59 |
Q_OBJECT |
| 60 |
Q_ENUMS(Status) |
| 61 |
public: |
| 62 |
explicit SearchService(QObject *parent = 0); |
| 63 |
|
| 64 |
enum Status { |
| 65 |
Invalid, |
| 66 |
InProgress, |
| 67 |
Done, |
| 68 |
Failed, |
| 69 |
Canceled |
| 70 |
}; |
| 71 |
|
| 72 |
signals: |
| 73 |
void messageIdsMatched(const QMailMessageIdList &idList); |
| 74 |
void statusChanged(Status status, const QString &error = QString()); |
| 75 |
|
| 76 |
public slots: |
| 77 |
void search(QueryConfiguration &config); |
| 78 |
void cancel(); |
| 79 |
|
| 80 |
private slots: |
| 81 |
void processNewQuery(); |
| 82 |
void executeNextQuery(); |
| 83 |
void executeQuery(); |
| 84 |
void searchActivityChanged(QMailServiceAction::Activity activity); |
| 85 |
|
| 86 |
private: |
| 87 |
void reset(); |
| 88 |
|
| 89 |
QPointer<QMailSearchAction> m_searchAction; |
| 90 |
|
| 91 |
QQueue<SearchQuery> m_queue; |
| 92 |
bool m_userTerminated; |
| 93 |
}; |
| 94 |
|
| 95 |
#endif |