Debian Codegraph @

Dekko/backend/mail/MailboxSearch.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 MAILBOXSEARCH_H
19 #define MAILBOXSEARCH_H
20
21 #include <QObject>
22 #include <QmlObjectListModel.h>
23 #include "Message.h"
24 #include <qmailmessage.h>
25 #include <qmailmessagekey.h>
26 #include <qmailmessagesortkey.h>
27 #include <qmailserviceaction.h>
28 #include "SearchService.h"
29
30 class MailboxSearch : public QObject
31 {
32 Q_OBJECT
33 /** @short Message model containing search results */
34 Q_PROPERTY(QObject *results READ result NOTIFY modelChanged)
35 /** @short Message key to perform the search against. Defaults to QMAilMessageKey::nonMatchingKey() */
36 Q_PROPERTY(QVariant messageKey READ messageKey WRITE setMessageKey NOTIFY messageKeyChanged)
37 /** @short Location to search messages */
38 Q_PROPERTY(Location location READ location WRITE setLocation NOTIFY locationChanged)
39 /** @short number of results to return */
40 Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged)
41 /** @short Order to sort list by */
42 Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged)
43 /** @short key to sort results by */
44 Q_PROPERTY(SortBy sortBy READ sortBy WRITE setSortBy NOTIFY sortByChanged)
45 /** @short Should the query include results from message bodies. note: this may be slow */
46 Q_PROPERTY(bool searchBody READ searchBody WRITE setSearchBody NOTIFY searchBodyChanged)
47 // Bind text field to this property
48 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
49 /** @short Search globally and only exclude messages with the QMailMessage::Removed mask */
50 Q_PROPERTY(bool globalSearch READ globalSearch WRITE setGlobalSearch NOTIFY globalSearchChanged)
51
52 Q_ENUMS(SortBy)
53 Q_ENUMS(Location)
54
55 public:
56 explicit MailboxSearch(QObject *parent = 0);
57
58 enum Location {
59 Local,
60 Remote,
61 LocalAndRemote
62 };
63
64 enum SortBy {
65 Id,
66 Sender,
67 Subject,
68 Recipients,
69 TimeStamp,
70 ListId
71 };
72
73 QObject *result() const;
74 QVariant messageKey() const;
75 void setMessageKey(QVariant &key);
76 Location location() const;
77 int limit() const;
78 Qt::SortOrder sortOrder() const;
79 SortBy sortBy() const;
80 bool searchBody() const;
81 QString searchQuery() const;
82 bool globalSearch() const;
83 QMailMessageSortKey querySortKey();
84 QMailSearchAction::SearchSpecification querySpec();
85 QMailMessageKey searchKey();
86
87 signals:
88 void modelChanged(QObject * results);
89 void messageKeyChanged();
90 void locationChanged(Location location);
91 void limitChanged(int limit);
92 void sortOrderChanged(Qt::SortOrder sortOrder);
93 void sortByChanged(SortBy sortBy);
94 void searchBodyChanged(bool searchBody);
95 void searchQueryChanged(QString searchQuery);
96 void globalSearchChanged(bool globalSearch);
97 void statusChanged(int status, const QString &msg);
98
99 public slots:
100 /** @short Alternative option to trigger a search */
101 void search(const QString &query);
102 /** @short Cancel currently running search action */
103 void cancelSearch();
104 void setLocation(const Location &location);
105 void setLimit(const int &limit);
106 void setSortOrder(const Qt::SortOrder &sortOrder);
107 void setSortBy(const SortBy &sortBy);
108 void setSearchBody(const bool searchBody);
109 void setSearchQuery(const QString &searchQuery);
110 void setGlobalSearch(const bool globalSearch);
111
112 void handleMatchedResults(const QMailMessageIdList &idList);
113
114 private:
115 QQmlObjectListModel<MinimalMessage> *m_results;
116 SearchService *m_service;
117 QMailMessageKey m_msgKey;
118 QMailMessageSortKey m_sortKey;
119 Location m_location;
120 int m_limit;
121 Qt::SortOrder m_sortOrder;
122 SortBy m_sortBy;
123 bool m_searchBody;
124 QString m_searchQuery;
125 bool m_globalSearch;
126 };
127
128 #endif // MAILBOXSEARCH_H