Debian Codegraph @

Dekko/backend/mail/SearchService.h

raw symbols SCIP
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
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 /** @short SearchService handles searching the local & remote message stores
47 *
48 * This has been implemented outside of ClientService to ensure results are returned in a speedy fashion
49 * We make use of the second available concurrent service action we can utilize from the messageserver/mailstore
50 * because the ClientService might already have a few queued actions and we would have to wait for
51 * them to complete before our search get's triggered.
52 *
53 * We shouldn't get in the way here and just get the results back to the user asap
54 *
55 * \ingroup group_mail
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 // SEARCHSERVICE_H