Diffstat (limited to 'noncore/unsupported/mail2/composer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/mail2/composer.cpp | 150 |
1 files changed, 148 insertions, 2 deletions
diff --git a/noncore/unsupported/mail2/composer.cpp b/noncore/unsupported/mail2/composer.cpp index c36d973..cabffe5 100644 --- a/noncore/unsupported/mail2/composer.cpp +++ b/noncore/unsupported/mail2/composer.cpp | |||
@@ -1,56 +1,60 @@ | |||
1 | #include <qmultilineedit.h> | 1 | #include <qmultilineedit.h> |
2 | #include <qmessagebox.h> | 2 | #include <qmessagebox.h> |
3 | #include <qpopupmenu.h> | 3 | #include <qpopupmenu.h> |
4 | #include <qcombobox.h> | 4 | #include <qcombobox.h> |
5 | #include <qlineedit.h> | 5 | #include <qlineedit.h> |
6 | #include <qaction.h> | 6 | #include <qaction.h> |
7 | #include <qtimer.h> | 7 | #include <qtimer.h> |
8 | #include <qlabel.h> | 8 | #include <qlabel.h> |
9 | #include <qapplication.h> | 9 | #include <qapplication.h> |
10 | 10 | ||
11 | #include <qpe/resource.h> | 11 | #include <qpe/resource.h> |
12 | #include <qpe/config.h> | ||
12 | 13 | ||
13 | #include "addresspicker.h" | 14 | #include "addresspicker.h" |
14 | #include "listviewplus.h" | 15 | #include "listviewplus.h" |
15 | #include "smtphandler.h" | 16 | #include "smtphandler.h" |
16 | #include "attachdiag.h" | 17 | #include "attachdiag.h" |
17 | #include "composer.h" | 18 | #include "composer.h" |
18 | #include "rename.h" | 19 | #include "rename.h" |
19 | 20 | ||
20 | AttachViewItem::AttachViewItem(QListView *parent, Attachment &attachment) | 21 | AttachViewItem::AttachViewItem(QListView *parent, Attachment &attachment) |
21 | : QListViewItem(parent), _attachment(attachment) | 22 | : QListViewItem(parent), _attachment(attachment) |
22 | { | 23 | { |
23 | setPixmap(0, _attachment.docLnk().pixmap().isNull() ? Resource::loadPixmap("UnknownDocument-14") : _attachment.docLnk().pixmap()); | 24 | setPixmap(0, _attachment.docLnk().pixmap().isNull() ? Resource::loadPixmap("UnknownDocument-14") : _attachment.docLnk().pixmap()); |
24 | setText(0, _attachment.newName().isEmpty() ? _attachment.fileName() : _attachment.newName()); | 25 | setText(0, _attachment.newName().isEmpty() ? _attachment.fileName() : _attachment.newName()); |
25 | setText(1, _attachment.description()); | 26 | setText(1, _attachment.description()); |
26 | } | 27 | } |
27 | 28 | ||
28 | Composer::Composer(QWidget *parent, const char *name, WFlags fl) | 29 | Composer::Composer(QWidget *parent, const char *name, WFlags fl, bool sendQueue) |
29 | : ComposerBase(parent, name, fl), _inLoop(false) | 30 | : ComposerBase(parent, name, fl), _inLoop(false) |
30 | { | 31 | { |
32 | _sendQueued = sendQueue; | ||
31 | abort->setEnabled(false); | 33 | abort->setEnabled(false); |
32 | to->setFocus(); | 34 | to->setFocus(); |
33 | 35 | ||
34 | connect(sendmail, SIGNAL(activated()), SLOT(slotSendMail())); | 36 | connect(sendmail, SIGNAL(activated()), SLOT(slotSendMail())); |
37 | connect(queuemail, SIGNAL(activated()), SLOT(slotQueueMail())); | ||
35 | connect(addressbook, SIGNAL(activated()), SLOT(slotOpenAddressPicker())); | 38 | connect(addressbook, SIGNAL(activated()), SLOT(slotOpenAddressPicker())); |
36 | connect(addattach, SIGNAL(activated()), SLOT(slotAddAttach())); | 39 | connect(addattach, SIGNAL(activated()), SLOT(slotAddAttach())); |
37 | connect(delattach, SIGNAL(activated()), SLOT(slotDelAttach())); | 40 | connect(delattach, SIGNAL(activated()), SLOT(slotDelAttach())); |
38 | 41 | ||
39 | connect(from, SIGNAL(activated(int)), SLOT(slotFromChanged(int))); | 42 | connect(from, SIGNAL(activated(int)), SLOT(slotFromChanged(int))); |
40 | 43 | ||
41 | connect(attachPopup, SIGNAL(activated(int)), SLOT(slotPopupHandler(int))); | 44 | connect(attachPopup, SIGNAL(activated(int)), SLOT(slotPopupHandler(int))); |
42 | 45 | ||
43 | QTimer::singleShot(0, this, SLOT(slotFillStuff())); | 46 | QTimer::singleShot(0, this, SLOT(slotFillStuff())); |
44 | QTimer::singleShot(0, this, SLOT(slotResizing())); | 47 | QTimer::singleShot(0, this, SLOT(slotResizing())); |
48 | |||
45 | } | 49 | } |
46 | 50 | ||
47 | Composer::~Composer() | 51 | Composer::~Composer() |
48 | { | 52 | { |
49 | hide(); | 53 | hide(); |
50 | } | 54 | } |
51 | 55 | ||
52 | void Composer::hide() | 56 | void Composer::hide() |
53 | { | 57 | { |
54 | QWidget::hide(); | 58 | QWidget::hide(); |
55 | 59 | ||
56 | if (_inLoop) { | 60 | if (_inLoop) { |
@@ -81,24 +85,29 @@ void Composer::setSendMail(SendMail &sendMail) | |||
81 | QValueList<Attachment> attachments = sendMail.attachments(); | 85 | QValueList<Attachment> attachments = sendMail.attachments(); |
82 | QValueList<Attachment>::Iterator it; | 86 | QValueList<Attachment>::Iterator it; |
83 | for (it = attachments.begin(); it != attachments.end(); it++) { | 87 | for (it = attachments.begin(); it != attachments.end(); it++) { |
84 | (void) new AttachViewItem(attachView, *it); | 88 | (void) new AttachViewItem(attachView, *it); |
85 | if (attachView->isHidden()) attachView->show(); | 89 | if (attachView->isHidden()) attachView->show(); |
86 | } | 90 | } |
87 | } | 91 | } |
88 | 92 | ||
89 | void Composer::slotResizing() | 93 | void Composer::slotResizing() |
90 | { | 94 | { |
91 | from->setMaximumWidth(width() - fromBox->width()); | 95 | from->setMaximumWidth(width() - fromBox->width()); |
92 | from->resize(width() - fromBox->width(), y()); | 96 | from->resize(width() - fromBox->width(), y()); |
97 | if (_sendQueued) | ||
98 | { | ||
99 | slotSendQueued(); | ||
100 | close(); | ||
101 | } | ||
93 | } | 102 | } |
94 | 103 | ||
95 | void Composer::slotPopupHandler(int itemid) | 104 | void Composer::slotPopupHandler(int itemid) |
96 | { | 105 | { |
97 | if (attachView->currentItem() == NULL) { | 106 | if (attachView->currentItem() == NULL) { |
98 | QMessageBox::information(this, tr("Error"), tr("Please select an entry first."), tr("Ok")); | 107 | QMessageBox::information(this, tr("Error"), tr("Please select an entry first."), tr("Ok")); |
99 | return; | 108 | return; |
100 | } | 109 | } |
101 | 110 | ||
102 | if (itemid == POPUP_ATTACH_RENAME) { | 111 | if (itemid == POPUP_ATTACH_RENAME) { |
103 | QString tmp = Rename::rename(attachView->currentItem()->text(0), this); | 112 | QString tmp = Rename::rename(attachView->currentItem()->text(0), this); |
104 | if (tmp != QString(0)) attachView->currentItem()->setText(0, tmp); | 113 | if (tmp != QString(0)) attachView->currentItem()->setText(0, tmp); |
@@ -147,24 +156,162 @@ void Composer::slotSendMail() | |||
147 | QString header, message; | 156 | QString header, message; |
148 | MailFactory::genMail(header, message, smail, this); | 157 | MailFactory::genMail(header, message, smail, this); |
149 | if (header.isNull() || message.isNull()) return;// Aborted. | 158 | if (header.isNull() || message.isNull()) return;// Aborted. |
150 | 159 | ||
151 | abort->setEnabled(true); | 160 | abort->setEnabled(true); |
152 | 161 | ||
153 | SmtpHandler *handler = new SmtpHandler(header, message, accountsLoaded[from->currentItem()], to->text()); | 162 | SmtpHandler *handler = new SmtpHandler(header, message, accountsLoaded[from->currentItem()], to->text()); |
154 | connect(handler, SIGNAL(finished()), SLOT(slotSendFinished())); | 163 | connect(handler, SIGNAL(finished()), SLOT(slotSendFinished())); |
155 | connect(handler, SIGNAL(error(const QString &)), SLOT(slotSendError(const QString &))); | 164 | connect(handler, SIGNAL(error(const QString &)), SLOT(slotSendError(const QString &))); |
156 | connect(handler, SIGNAL(status(const QString &)), status, SLOT(setText(const QString &))); | 165 | connect(handler, SIGNAL(status(const QString &)), status, SLOT(setText(const QString &))); |
157 | } | 166 | } |
158 | 167 | ||
168 | void Composer::slotSendQueued() | ||
169 | { | ||
170 | |||
171 | qDebug("Sending queued messages"); | ||
172 | Config cfg( "mailqueue", Config::User ); | ||
173 | cfg.setGroup( "Settings" ); | ||
174 | int count = cfg.readNumEntry( "count", 0 ); | ||
175 | // tille: should not be here | ||
176 | // but no error checking for the moment | ||
177 | cfg.writeEntry( "count", 0 ); | ||
178 | |||
179 | |||
180 | qDebug("%i messages to send", count); | ||
181 | QString str; | ||
182 | for (int i=1;i<=count;i++) | ||
183 | { | ||
184 | qDebug("sending message %i",i); | ||
185 | cfg.setGroup( "Mail_" + QString::number(i) ); | ||
186 | SendMail smail; | ||
187 | str = cfg.readEntry("from"); | ||
188 | qDebug("setFrom %s",str.latin1()); | ||
189 | smail.setFrom( str ); | ||
190 | str = cfg.readEntry("reply"); | ||
191 | qDebug("setReplyTo %s",str.latin1()); | ||
192 | smail.setReplyTo( str ); | ||
193 | QString toAdr = cfg.readEntry("to"); | ||
194 | qDebug("to %s",toAdr.latin1()); | ||
195 | smail.setTo( toAdr ); //to->text()); | ||
196 | str = cfg.readEntry("cc"); | ||
197 | qDebug("setCc %s",str.latin1()); | ||
198 | smail.setCc( str ); //cc->text()); | ||
199 | smail.setBcc( cfg.readEntry("bcc") ); //bcc->text()); | ||
200 | str = cfg.readEntry("subject"); | ||
201 | qDebug("setSubject %s",str.latin1()); | ||
202 | smail.setSubject( str ); //subject->text()); | ||
203 | str = cfg.readEntryCrypt("message"); | ||
204 | qDebug("setMessage %s",str.latin1()); | ||
205 | smail.setMessage( str ); //message->text()); | ||
206 | smail.setNeedsMime( cfg.readBoolEntry("mime") ); //attachView->childCount() == 0 ? false : true); | ||
207 | |||
208 | qDebug("setting account [%i]",cfg.readNumEntry("account")); | ||
209 | Account accnt = accountsLoaded[ cfg.readNumEntry("account") ]; | ||
210 | smail.setAccount( accnt ); //accountsLoaded[from->currentItem()]); | ||
211 | |||
212 | |||
213 | int prio = cfg.readNumEntry( "priority" ); | ||
214 | qDebug("setting priority %i",prio); | ||
215 | if (prio == POPUP_PRIO_LOW) { | ||
216 | smail.setPriority("Low");// No i18n on purpose | ||
217 | } else if (prio == POPUP_PRIO_NORMAL) { | ||
218 | smail.setPriority("Normal");// No i18n on purpose | ||
219 | } else if (prio == POPUP_PRIO_HIGH) { | ||
220 | smail.setPriority("High");// No i18n on purpose | ||
221 | } | ||
222 | |||
223 | QValueList<Attachment> attachments; | ||
224 | Attachment a; | ||
225 | QString an; | ||
226 | |||
227 | int ac = cfg.readNumEntry( "attachments", 0 ); | ||
228 | qDebug("%i Attachments",ac); | ||
229 | for (int j = 0; i < ac; ac++) { | ||
230 | an = "Attachment_" + QString::number( j ); | ||
231 | qDebug(an.latin1()); | ||
232 | a.setFileName(cfg.readEntry( an + "fileName" )); | ||
233 | a.setNewName(cfg.readEntry( an + "newName" )); | ||
234 | a.setDescription(cfg.readEntry( an + "description" )); | ||
235 | a.setDocLnk( DocLnk( cfg.readEntry( an + "docLnk" )) ); | ||
236 | attachments.append( a ); | ||
237 | } | ||
238 | |||
239 | smail.setAttachments(attachments); | ||
240 | |||
241 | qDebug("putting mail together"); | ||
242 | |||
243 | QString header, message; | ||
244 | MailFactory::genMail(header, message, smail, this); | ||
245 | if (header.isNull() || message.isNull()) continue;//return;// Aborted. | ||
246 | |||
247 | // abort->setEnabled(true); | ||
248 | |||
249 | qDebug("Sending to %s",toAdr.latin1()); | ||
250 | SmtpHandler *handler = new SmtpHandler(header, message, accnt ,toAdr); | ||
251 | |||
252 | connect(handler, SIGNAL(finished()), SLOT(slotSendFinished())); | ||
253 | connect(handler, SIGNAL(error(const QString &)), SLOT(slotSendError(const QString &))); | ||
254 | connect(handler, SIGNAL(status(const QString &)), status, SLOT(setText(const QString &))); | ||
255 | |||
256 | qDebug("remove mail %i", i); | ||
257 | cfg.clearGroup(); | ||
258 | cfg.removeEntry( "Mail_" + QString::number(i) ); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | void Composer::slotQueueMail() | ||
263 | { | ||
264 | if (to->text().find(QRegExp(".*\\@.*\\..*")) == -1) { | ||
265 | QMessageBox::information(this, tr("Error"), tr("<p>You have to specify a recipient.<br>(eg: foo@bar.org)</p>"), tr("Ok")); | ||
266 | return; | ||
267 | } | ||
268 | |||
269 | Config cfg( "mailqueue", Config::User ); | ||
270 | |||
271 | cfg.setGroup( "Settings" ); | ||
272 | int count = cfg.readNumEntry( "count", 0 ); | ||
273 | count++; | ||
274 | cfg.writeEntry( "count", count ); | ||
275 | qDebug("queueing mail %i",count); | ||
276 | |||
277 | cfg.setGroup( "Mail_" + QString::number( count )); | ||
278 | cfg.writeEntry( "from", from->currentText() ); | ||
279 | cfg.writeEntry( "reply", replyto->text()); | ||
280 | cfg.writeEntry( "to", to->text()); | ||
281 | cfg.writeEntry( "cc", cc->text()); | ||
282 | cfg.writeEntry( "bcc", bcc->text()); | ||
283 | cfg.writeEntry( "subject", subject->text()); | ||
284 | cfg.writeEntryCrypt( "message", message->text()); | ||
285 | cfg.writeEntry( "mime", attachView->childCount() == 0 ); | ||
286 | cfg.writeEntry( "account", from->currentItem()); | ||
287 | cfg.writeEntry( "priority", priority->currentItem() ); | ||
288 | cfg.writeEntry( "attachments", attachView->childCount() ); | ||
289 | |||
290 | Attachment a; | ||
291 | QListViewItem *item; | ||
292 | QString an; | ||
293 | int i = 0; | ||
294 | for (item = attachView->firstChild(); item != 0; item = item->itemBelow()) { | ||
295 | a = ((AttachViewItem *)item)->attachment(); | ||
296 | an = "Attachment_" + QString::number( i++ ); | ||
297 | cfg.writeEntry( an + "fileName", a.fileName() ); | ||
298 | cfg.writeEntry( an + "newName", a.newName() ); | ||
299 | cfg.writeEntry( an + "description", a.description() ); | ||
300 | cfg.writeEntry( an + "docLnk", a.docLnk().file() ); | ||
301 | } | ||
302 | |||
303 | //cfg.close(); | ||
304 | } | ||
305 | |||
159 | void Composer::slotSendError(const QString &error) | 306 | void Composer::slotSendError(const QString &error) |
160 | { | 307 | { |
161 | status->setText(tr("<font color=#ff0000>Error occoured during sending.</font>")); | 308 | status->setText(tr("<font color=#ff0000>Error occoured during sending.</font>")); |
162 | QMessageBox::warning(this, tr("Error"), tr("<p>%1</p").arg(error), tr("Ok")); | 309 | QMessageBox::warning(this, tr("Error"), tr("<p>%1</p").arg(error), tr("Ok")); |
163 | } | 310 | } |
164 | 311 | ||
165 | void Composer::slotSendFinished() | 312 | void Composer::slotSendFinished() |
166 | { | 313 | { |
167 | QMessageBox::information(this, tr("Success"), tr("<p>The mail was sent successfully.</p>"), tr("Ok")); | 314 | QMessageBox::information(this, tr("Success"), tr("<p>The mail was sent successfully.</p>"), tr("Ok")); |
168 | 315 | ||
169 | status->setText(QString(0)); | 316 | status->setText(QString(0)); |
170 | abort->setEnabled(false); | 317 | abort->setEnabled(false); |
@@ -232,13 +379,12 @@ void Composer::slotAddAttach() | |||
232 | attachment.setFileName(lnk.file()); | 379 | attachment.setFileName(lnk.file()); |
233 | attachment.setNewName(lnk.name()); | 380 | attachment.setNewName(lnk.name()); |
234 | attachment.setDocLnk(lnk); | 381 | attachment.setDocLnk(lnk); |
235 | 382 | ||
236 | (void) new AttachViewItem(attachView, attachment); | 383 | (void) new AttachViewItem(attachView, attachment); |
237 | } | 384 | } |
238 | 385 | ||
239 | void Composer::slotDelAttach() | 386 | void Composer::slotDelAttach() |
240 | { | 387 | { |
241 | if (attachView->currentItem() == NULL) return; | 388 | if (attachView->currentItem() == NULL) return; |
242 | attachView->takeItem(attachView->currentItem()); | 389 | attachView->takeItem(attachView->currentItem()); |
243 | } | 390 | } |
244 | |||