summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mail2/searchdiag.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/mail2/searchdiag.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mail2/searchdiag.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/noncore/unsupported/mail2/searchdiag.cpp b/noncore/unsupported/mail2/searchdiag.cpp
new file mode 100644
index 0000000..33b8afb
--- a/dev/null
+++ b/noncore/unsupported/mail2/searchdiag.cpp
@@ -0,0 +1,128 @@
1#include <qmessagebox.h>
2#include <qpushbutton.h>
3#include <qcombobox.h>
4#include <qlineedit.h>
5
6#include <qpe/qpeapplication.h>
7
8#include "imaphandler.h"
9#include "searchdiag.h"
10#include "viewmail.h"
11
12 #define INMENU_BODY0
13 #define INMENU_HEADERF1
14 #define INMENU_SUBJECT2
15 #define INMENU_FROM3
16 #define INMENU_TO4
17
18SearchDiag::SearchDiag(QWidget *parent, const char *name, WFlags fl)
19 : SearchDiagBase(parent, name, fl)
20 {
21 _selected = false;
22
23 in->insertItem(tr("Body"), INMENU_BODY);
24 in->insertItem(tr("Header Field"), INMENU_HEADERF);
25 in->insertItem(tr("Subject"), INMENU_SUBJECT);
26 in->insertItem(tr("From"), INMENU_FROM);
27 in->insertItem(tr("To"), INMENU_TO);
28
29 connect(folderView, SIGNAL(folderSelected(Folder)), SLOT(folderSelected(Folder)));
30 connect(in, SIGNAL(activated(int)), SLOT(slotInItemActivated(int)));
31 connect(mailTable, SIGNAL(mailClicked(IMAPResponseFETCH, IMAPHandler *)), SLOT(slotMailClicked(IMAPResponseFETCH, IMAPHandler *)));
32}
33
34void SearchDiag::accept()
35{
36 if (searchFor->text().isEmpty()) {
37 QMessageBox::information(this, tr("Error"), tr("<p>Please enter what to search for.</p>"), tr("Ok"));
38 return;
39 }
40
41 if (!_selected) {
42 QMessageBox::information(this, tr("Error"), tr("<p>Please select a folder.</p>"), tr("Ok"));
43 return;
44 }
45
46 if (in->currentItem() == INMENU_HEADERF && other->currentText().isEmpty()) {
47 QMessageBox::information(this, tr("Error"), tr("<p>Please enter a header field to search in.</p>"), tr("Ok"));
48 return;
49 }
50
51 _folder.topFolder().handler()->iSelect(_folder.fullName());
52 connect(_folder.topFolder().handler(), SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPSelect(IMAPResponse &)));
53}
54
55void SearchDiag::folderSelected(Folder folder)
56{
57 _selected = true;
58 _folder = folder;
59}
60
61void SearchDiag::slotIMAPSelect(IMAPResponse &response)
62{
63 disconnect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPSelect(IMAPResponse &)));
64
65 if (response.statusResponse().status() == IMAPResponseEnums::OK) {
66 if (in->currentItem() == INMENU_BODY) {
67 response.imapHandler()->iSearch("BODY \"" + searchFor->text() + "\"");
68 } else if (in->currentItem() == INMENU_HEADERF) {
69 response.imapHandler()->iSearch("HEADER \""+ other->currentText() + "\" \"" + searchFor->text() + "\"");
70 } else if (in->currentItem() == INMENU_SUBJECT) {
71 response.imapHandler()->iSearch("SUBJECT \"" + searchFor->text() + "\"");
72 } else if (in->currentItem() == INMENU_FROM) {
73 response.imapHandler()->iSearch("FROM \"" + searchFor->text() + "\"");
74 } else if (in->currentItem() == INMENU_TO) {
75 response.imapHandler()->iSearch("TO \"" + searchFor->text() + "\"");
76 } else return;
77
78 connect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPSearch(IMAPResponse &)));
79 } else {
80 QMessageBox::warning(this, tr("Error"), tr("<p>Could not select the folder. Aborting. (Server said: %1)").arg(response.statusResponse().comment()), tr("Ok"));
81 }
82}
83
84void SearchDiag::slotIMAPSearch(IMAPResponse &response)
85{
86 disconnect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPSearch(IMAPResponse &)));
87
88 if (response.statusResponse().status() == IMAPResponseEnums::OK) {
89 IMAPResponseSEARCH results = response.SEARCH()[0];
90 if (results.mails().count() == 0) {
91 QMessageBox::information(this, tr("Results"), tr("<p>No mails match your criteria.</p>"), tr("Ok"));
92 return;
93 }
94
95 response.imapHandler()->iFetch(results.mails().join(","), "ENVELOPE FLAGS UID");
96 connect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPFetch(IMAPResponse &)));
97 } else {
98 QMessageBox::warning(this, tr("Error"), tr("<p>Search failed. (Server said: %1)").arg(response.statusResponse().comment()), tr("Ok"));
99 }
100}
101
102void SearchDiag::slotIMAPFetch(IMAPResponse &response)
103{
104 disconnect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPSearch(IMAPResponse &)));
105
106 if (response.statusResponse().status() == IMAPResponseEnums::OK) {
107 mailTable->setHeaders(response.FETCH());
108 } else {
109 QMessageBox::warning(this, tr("Error"), tr("<p>Couldn't fetch the mail headers. (Server said: %1)").arg(response.statusResponse().comment()));
110 }
111}
112
113void SearchDiag::slotMailClicked(IMAPResponseFETCH fetch, IMAPHandler *)
114{
115 ViewMail *viewMail = new ViewMail(fetch, _folder.topFolder().handler());
116 viewMail->showMaximized();
117 viewMail->show();
118}
119
120void SearchDiag::slotInItemActivated(int index)
121{
122 if (index == INMENU_HEADERF) {
123 other->setEnabled(true);
124 } else {
125 other->setEnabled(false);
126 }
127}
128