summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mail2/composer.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/mail2/composer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mail2/composer.cpp215
1 files changed, 215 insertions, 0 deletions
diff --git a/noncore/unsupported/mail2/composer.cpp b/noncore/unsupported/mail2/composer.cpp
new file mode 100644
index 0000000..2f13604
--- a/dev/null
+++ b/noncore/unsupported/mail2/composer.cpp
@@ -0,0 +1,215 @@
1#include <qmultilineedit.h>
2#include <qmessagebox.h>
3#include <qpopupmenu.h>
4#include <qcombobox.h>
5#include <qlineedit.h>
6#include <qaction.h>
7#include <qtimer.h>
8#include <qlabel.h>
9
10#include <qpe/resource.h>
11
12#include "addresspicker.h"
13#include "listviewplus.h"
14#include "smtphandler.h"
15#include "attachdiag.h"
16#include "composer.h"
17#include "rename.h"
18
19AttachViewItem::AttachViewItem(QListView *parent, Attachment &attachment)
20 : QListViewItem(parent), _attachment(attachment)
21{
22 setPixmap(0, _attachment.docLnk()->pixmap().isNull() ? Resource::loadPixmap("UnknownDocument-14") : _attachment.docLnk()->pixmap());
23 setText(0, _attachment.newName().isEmpty() ? _attachment.fileName() : _attachment.newName());
24 setText(1, _attachment.description());
25}
26
27Composer::Composer(QWidget *parent, const char *name, WFlags fl)
28 : ComposerBase(parent, name, fl)
29{
30 abort->setEnabled(false);
31 to->setFocus();
32
33 connect(sendmail, SIGNAL(activated()), SLOT(slotSendMail()));
34 connect(addressbook, SIGNAL(activated()), SLOT(slotOpenAddressPicker()));
35 connect(addattach, SIGNAL(activated()), SLOT(slotAddAttach()));
36 connect(delattach, SIGNAL(activated()), SLOT(slotDelAttach()));
37
38 connect(from, SIGNAL(activated(int)), SLOT(slotFromChanged(int)));
39
40 connect(attachPopup, SIGNAL(activated(int)), SLOT(slotPopupHandler(int)));
41
42 QTimer::singleShot(0, this, SLOT(slotFillStuff()));
43 QTimer::singleShot(0, this, SLOT(slotResizing()));
44}
45
46void Composer::setSendMail(SendMail &sendMail)
47{
48 to->setText(sendMail.to());
49 cc->setText(sendMail.cc());
50 bcc->setText(sendMail.bcc());
51 subject->setText(sendMail.subject());
52 message->setText(sendMail.message());
53 _inReplyTo = sendMail.inReplyTo();
54
55 QValueList<Attachment> attachments = sendMail.attachments();
56 QValueList<Attachment>::Iterator it;
57 for (it = attachments.begin(); it != attachments.end(); it++) {
58 (void) new AttachViewItem(attachView, *it);
59 if (attachView->isHidden()) attachView->show();
60 }
61}
62
63void Composer::slotResizing()
64{
65 from->setMaximumWidth(width() - fromBox->width());
66 from->resize(width() - fromBox->width(), y());
67}
68
69void Composer::slotPopupHandler(int itemid)
70{
71 if (attachView->currentItem() == NULL) {
72 QMessageBox::information(this, tr("Error"), tr("Please select an entry first."), tr("Ok"));
73 return;
74 }
75
76 if (itemid == POPUP_ATTACH_RENAME) {
77 QString tmp = Rename::rename(attachView->currentItem()->text(0), this);
78 if (tmp != QString(0)) attachView->currentItem()->setText(0, tmp);
79 } else if (itemid == POPUP_ATTACH_DESC) {
80 QString tmp = Rename::getText(tr("Set Description"), tr("<div align=center>Description"), this);
81 if (tmp != QString(0)) attachView->currentItem()->setText(1, tmp);
82 } else if (itemid == POPUP_ATTACH_REMOVE) {
83 attachView->takeItem(attachView->currentItem());
84 }
85}
86
87void Composer::slotSendMail()
88{
89 if (to->text().find(QRegExp(".*\\@.*\\..*")) == -1) {
90 QMessageBox::information(this, tr("Error"), tr("<p>You have to specify a recipient.<br>(eg: foo@bar.org)</p>"), tr("Ok"));
91 return;
92 }
93
94 SendMail smail;
95 smail.setFrom(from->currentText());
96 smail.setReplyTo(replyto->text());
97 smail.setTo(to->text());
98 smail.setCc(cc->text());
99 smail.setBcc(bcc->text());
100 smail.setSubject(subject->text());
101 smail.setMessage(message->text());
102 smail.setNeedsMime(attachView->childCount() == 0 ? false : true);
103 smail.setAccount(accountsLoaded[from->currentItem()]);
104
105 if (priority->currentItem() == POPUP_PRIO_LOW) {
106 smail.setPriority("Low");// No i18n on purpose
107 } else if (priority->currentItem() == POPUP_PRIO_NORMAL) {
108 smail.setPriority("Normal");// No i18n on purpose
109 } else if (priority->currentItem() == POPUP_PRIO_HIGH) {
110 smail.setPriority("High");// No i18n on purpose
111 }
112
113 QValueList<Attachment> attachments;
114 QListViewItem *item;
115 for (item = attachView->firstChild(); item != 0; item = item->itemBelow()) {
116 attachments.append(((AttachViewItem *)item)->attachment());
117 }
118
119 smail.setAttachments(attachments);
120
121 QString header, message;
122 MailFactory::genMail(header, message, smail, this);
123
124 abort->setEnabled(true);
125
126 SmtpHandler *handler = new SmtpHandler(header, message, accountsLoaded[from->currentItem()], to->text());
127 connect(handler, SIGNAL(finished()), SLOT(slotSendFinished()));
128 connect(handler, SIGNAL(error(const QString &)), SLOT(slotSendError(const QString &)));
129 connect(handler, SIGNAL(status(const QString &)), status, SLOT(setText(const QString &)));
130}
131
132void Composer::slotSendError(const QString &error)
133{
134 status->setText(tr("<font color=#ff0000>Error occoured during sending.</font>"));
135 QMessageBox::warning(this, tr("Error"), tr("<p>%1</p").arg(error), tr("Ok"));
136}
137
138void Composer::slotSendFinished()
139{
140 status->setText(QString(0));
141 abort->setEnabled(false);
142}
143
144void Composer::slotFillStuff()
145{
146 QValueList<Account> accounts = ConfigFile::getAccounts();
147 int i = 0;
148
149 QValueList<Account>::Iterator it;
150 for (it = accounts.begin(); it != accounts.end(); it++) {
151 if (!(*it).email().isEmpty() && !(*it).smtpServer().isEmpty() && !(*it).smtpPort().isEmpty()) {
152 if (!(*it).realName().isEmpty())
153 from->insertItem((*it).realName() + " <" + (*it).email() + ">", i);
154 else
155 from->insertItem((*it).email());
156
157 accountsLoaded.append(*it);
158 i++;
159 }
160 }
161}
162
163void Composer::slotFromChanged(int id)
164{
165 Account account = accountsLoaded[id];
166
167 if (account.defaultCc()) cc->setText(account.cc());
168 if (account.defaultBcc()) bcc->setText(account.bcc());
169 if (account.defaultReplyTo()) replyto->setText(account.replyTo());
170 if (!account.signature().isEmpty())
171 message->setText(message->text() + "\n\n-- \n" + account.signature());
172}
173
174void Composer::slotOpenAddressPicker()
175{
176 if (!to->isHidden() && cc->isHidden() && bcc->isHidden()) {
177 if (to->text().isEmpty()) {
178 to->setText(AddressPicker::getNames());
179 } else {
180 to->setText(to->text() + ", " + AddressPicker::getNames());
181 }
182 } else if (to->isHidden() && !cc->isHidden() && bcc->isHidden()) {
183 if (cc->text().isEmpty()) {
184 cc->setText(AddressPicker::getNames());
185 } else {
186 cc->setText(cc->text() + ", " + AddressPicker::getNames());
187 }
188 } else if (to->isHidden() && cc->isHidden() && !bcc->isHidden()) {
189 if (bcc->text().isEmpty()) {
190 bcc->setText(AddressPicker::getNames());
191 } else {
192 bcc->setText(bcc->text() + ", " + AddressPicker::getNames());
193 }
194 }
195}
196
197void Composer::slotAddAttach()
198{
199 DocLnk lnk = AttachDiag::getFile();
200 if (lnk.name().isEmpty()) return;
201
202 Attachment attachment;
203 attachment.setFileName(lnk.file());
204 attachment.setNewName(lnk.name());
205 attachment.setDocLnk(&lnk);
206
207 (void) new AttachViewItem(attachView, attachment);
208}
209
210void Composer::slotDelAttach()
211{
212 if (attachView->currentItem() == NULL) return;
213 attachView->takeItem(attachView->currentItem());
214}
215