author | tille <tille> | 2002-06-18 23:53:27 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-18 23:53:27 (UTC) |
commit | 14881bb4baf3ac470a135bdde6ffb115c91ea124 (patch) (unidiff) | |
tree | 6d088cdacd769076e64496abe6b9043168b75928 /noncore/unsupported/mail2/composer.cpp | |
parent | f2ecc05c1156ae0f99ea0528646609d63eaa84c0 (diff) | |
download | opie-14881bb4baf3ac470a135bdde6ffb115c91ea124.zip opie-14881bb4baf3ac470a135bdde6ffb115c91ea124.tar.gz opie-14881bb4baf3ac470a135bdde6ffb115c91ea124.tar.bz2 |
added menu and fix send queued
Diffstat (limited to 'noncore/unsupported/mail2/composer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/mail2/composer.cpp | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/noncore/unsupported/mail2/composer.cpp b/noncore/unsupported/mail2/composer.cpp index 1d793ee..72a7242 100644 --- a/noncore/unsupported/mail2/composer.cpp +++ b/noncore/unsupported/mail2/composer.cpp | |||
@@ -57,25 +57,24 @@ void Composer::hide() | |||
57 | { | 57 | { |
58 | QWidget::hide(); | 58 | QWidget::hide(); |
59 | 59 | ||
60 | if (_inLoop) { | 60 | if (_inLoop) { |
61 | _inLoop = false; | 61 | _inLoop = false; |
62 | qApp->exit_loop(); | 62 | qApp->exit_loop(); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | void Composer::exec() | 66 | void Composer::exec() |
67 | { | 67 | { |
68 | show(); | 68 | show(); |
69 | |||
70 | if (!_inLoop) { | 69 | if (!_inLoop) { |
71 | _inLoop = true; | 70 | _inLoop = true; |
72 | qApp->enter_loop(); | 71 | qApp->enter_loop(); |
73 | } | 72 | } |
74 | } | 73 | } |
75 | 74 | ||
76 | void Composer::setSendMail(SendMail &sendMail) | 75 | void Composer::setSendMail(SendMail &sendMail) |
77 | { | 76 | { |
78 | to->setText(sendMail.to()); | 77 | to->setText(sendMail.to()); |
79 | cc->setText(sendMail.cc()); | 78 | cc->setText(sendMail.cc()); |
80 | bcc->setText(sendMail.bcc()); | 79 | bcc->setText(sendMail.bcc()); |
81 | subject->setText(sendMail.subject()); | 80 | subject->setText(sendMail.subject()); |
@@ -85,29 +84,25 @@ void Composer::setSendMail(SendMail &sendMail) | |||
85 | QValueList<Attachment> attachments = sendMail.attachments(); | 84 | QValueList<Attachment> attachments = sendMail.attachments(); |
86 | QValueList<Attachment>::Iterator it; | 85 | QValueList<Attachment>::Iterator it; |
87 | for (it = attachments.begin(); it != attachments.end(); it++) { | 86 | for (it = attachments.begin(); it != attachments.end(); it++) { |
88 | (void) new AttachViewItem(attachView, *it); | 87 | (void) new AttachViewItem(attachView, *it); |
89 | if (attachView->isHidden()) attachView->show(); | 88 | if (attachView->isHidden()) attachView->show(); |
90 | } | 89 | } |
91 | } | 90 | } |
92 | 91 | ||
93 | void Composer::slotResizing() | 92 | void Composer::slotResizing() |
94 | { | 93 | { |
95 | from->setMaximumWidth(width() - fromBox->width()); | 94 | from->setMaximumWidth(width() - fromBox->width()); |
96 | from->resize(width() - fromBox->width(), y()); | 95 | from->resize(width() - fromBox->width(), y()); |
97 | if (_sendQueued) | 96 | if (_sendQueued) slotSendQueued(); |
98 | { | ||
99 | slotSendQueued(); | ||
100 | close(); | ||
101 | } | ||
102 | } | 97 | } |
103 | 98 | ||
104 | void Composer::slotPopupHandler(int itemid) | 99 | void Composer::slotPopupHandler(int itemid) |
105 | { | 100 | { |
106 | if (attachView->currentItem() == NULL) { | 101 | if (attachView->currentItem() == NULL) { |
107 | QMessageBox::information(this, tr("Error"), tr("Please select an entry first."), tr("Ok")); | 102 | QMessageBox::information(this, tr("Error"), tr("Please select an entry first."), tr("Ok")); |
108 | return; | 103 | return; |
109 | } | 104 | } |
110 | 105 | ||
111 | if (itemid == POPUP_ATTACH_RENAME) { | 106 | if (itemid == POPUP_ATTACH_RENAME) { |
112 | QString tmp = Rename::rename(attachView->currentItem()->text(0), this); | 107 | QString tmp = Rename::rename(attachView->currentItem()->text(0), this); |
113 | if (tmp != QString(0)) attachView->currentItem()->setText(0, tmp); | 108 | if (tmp != QString(0)) attachView->currentItem()->setText(0, tmp); |
@@ -162,33 +157,33 @@ void Composer::slotSendMail() | |||
162 | SmtpHandler *handler = new SmtpHandler(header, message, accountsLoaded[from->currentItem()], to->text()); | 157 | SmtpHandler *handler = new SmtpHandler(header, message, accountsLoaded[from->currentItem()], to->text()); |
163 | connect(handler, SIGNAL(finished()), SLOT(slotSendFinished())); | 158 | connect(handler, SIGNAL(finished()), SLOT(slotSendFinished())); |
164 | connect(handler, SIGNAL(error(const QString &)), SLOT(slotSendError(const QString &))); | 159 | connect(handler, SIGNAL(error(const QString &)), SLOT(slotSendError(const QString &))); |
165 | connect(handler, SIGNAL(status(const QString &)), status, SLOT(setText(const QString &))); | 160 | connect(handler, SIGNAL(status(const QString &)), status, SLOT(setText(const QString &))); |
166 | } | 161 | } |
167 | 162 | ||
168 | void Composer::slotSendQueued() | 163 | void Composer::slotSendQueued() |
169 | { | 164 | { |
170 | 165 | ||
171 | qDebug("Sending queued messages"); | 166 | qDebug("Sending queued messages"); |
172 | Config cfg( "mailqueue", Config::User ); | 167 | Config cfg( "mailqueue", Config::User ); |
173 | cfg.setGroup( "Settings" ); | 168 | cfg.setGroup( "Settings" ); |
174 | int count = cfg.readNumEntry( "count", 0 ); | 169 | _sendCount = 0; |
175 | // tille: should not be here | 170 | _sendError = 0; |
176 | // but no error checking for the moment | 171 | _toSend = cfg.readNumEntry( "count", 0 ); |
177 | cfg.writeEntry( "count", 0 ); | ||
178 | 172 | ||
173 | if (_toSend == 0) close(); | ||
179 | 174 | ||
180 | qDebug("%i messages to send", count); | 175 | qDebug("%i messages to send", _toSend); |
181 | QString str; | 176 | QString str; |
182 | for (int i=1;i<=count;i++) | 177 | for (int i=1;i<=_toSend;i++) |
183 | { | 178 | { |
184 | qDebug("sending message %i",i); | 179 | qDebug("sending message %i",i); |
185 | cfg.setGroup( "Mail_" + QString::number(i) ); | 180 | cfg.setGroup( "Mail_" + QString::number(i) ); |
186 | SendMail smail; | 181 | SendMail smail; |
187 | str = cfg.readEntry("from"); | 182 | str = cfg.readEntry("from"); |
188 | qDebug("setFrom %s",str.latin1()); | 183 | qDebug("setFrom %s",str.latin1()); |
189 | smail.setFrom( str ); | 184 | smail.setFrom( str ); |
190 | str = cfg.readEntry("reply"); | 185 | str = cfg.readEntry("reply"); |
191 | qDebug("setReplyTo %s",str.latin1()); | 186 | qDebug("setReplyTo %s",str.latin1()); |
192 | smail.setReplyTo( str ); | 187 | smail.setReplyTo( str ); |
193 | QString toAdr = cfg.readEntry("to"); | 188 | QString toAdr = cfg.readEntry("to"); |
194 | qDebug("to %s",toAdr.latin1()); | 189 | qDebug("to %s",toAdr.latin1()); |
@@ -240,31 +235,28 @@ void Composer::slotSendQueued() | |||
240 | 235 | ||
241 | qDebug("putting mail together"); | 236 | qDebug("putting mail together"); |
242 | 237 | ||
243 | QString header, message; | 238 | QString header, message; |
244 | MailFactory::genMail(header, message, smail, this); | 239 | MailFactory::genMail(header, message, smail, this); |
245 | if (header.isNull() || message.isNull()) continue;//return;// Aborted. | 240 | if (header.isNull() || message.isNull()) continue;//return;// Aborted. |
246 | 241 | ||
247 | // abort->setEnabled(true); | 242 | // abort->setEnabled(true); |
248 | 243 | ||
249 | qDebug("Sending to %s",toAdr.latin1()); | 244 | qDebug("Sending to %s",toAdr.latin1()); |
250 | SmtpHandler *handler = new SmtpHandler(header, message, accnt ,toAdr); | 245 | SmtpHandler *handler = new SmtpHandler(header, message, accnt ,toAdr); |
251 | 246 | ||
252 | connect(handler, SIGNAL(finished()), SLOT(slotSendFinished())); | 247 | connect(handler, SIGNAL(finished()), SLOT(slotSendQueuedFinished())); |
253 | connect(handler, SIGNAL(error(const QString &)), SLOT(slotSendError(const QString &))); | 248 | connect(handler, SIGNAL(error(const QString &)), SLOT(slotSendQueuedError(const QString &))); |
254 | connect(handler, SIGNAL(status(const QString &)), status, SLOT(setText(const QString &))); | 249 | connect(handler, SIGNAL(status(const QString &)), status, SLOT(setText(const QString &))); |
255 | 250 | ||
256 | qDebug("remove mail %i", i); | ||
257 | cfg.clearGroup(); | ||
258 | cfg.removeEntry( "Mail_" + QString::number(i) ); | ||
259 | } | 251 | } |
260 | } | 252 | } |
261 | 253 | ||
262 | void Composer::slotQueueMail() | 254 | void Composer::slotQueueMail() |
263 | { | 255 | { |
264 | if (to->text().find(QRegExp(".*\\@.*\\..*")) == -1) { | 256 | 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")); | 257 | QMessageBox::information(this, tr("Error"), tr("<p>You have to specify a recipient.<br>(eg: foo@bar.org)</p>"), tr("Ok")); |
266 | return; | 258 | return; |
267 | } | 259 | } |
268 | 260 | ||
269 | Config cfg( "mailqueue", Config::User ); | 261 | Config cfg( "mailqueue", Config::User ); |
270 | 262 | ||
@@ -301,32 +293,61 @@ void Composer::slotQueueMail() | |||
301 | } | 293 | } |
302 | 294 | ||
303 | QMessageBox::information(this, tr("Success"), tr("<p>The mail was queued successfully.</p><p>The queue contains ")+QString::number(count)+tr(" mails.</p>"), tr("Ok")); | 295 | QMessageBox::information(this, tr("Success"), tr("<p>The mail was queued successfully.</p><p>The queue contains ")+QString::number(count)+tr(" mails.</p>"), tr("Ok")); |
304 | 296 | ||
305 | } | 297 | } |
306 | 298 | ||
307 | void Composer::slotSendError(const QString &error) | 299 | void Composer::slotSendError(const QString &error) |
308 | { | 300 | { |
309 | status->setText(tr("<font color=#ff0000>Error occoured during sending.</font>")); | 301 | status->setText(tr("<font color=#ff0000>Error occoured during sending.</font>")); |
310 | QMessageBox::warning(this, tr("Error"), tr("<p>%1</p").arg(error), tr("Ok")); | 302 | QMessageBox::warning(this, tr("Error"), tr("<p>%1</p").arg(error), tr("Ok")); |
311 | } | 303 | } |
312 | 304 | ||
305 | void Composer::slotSendQueuedError(const QString &error) | ||
306 | { | ||
307 | _sendError++; | ||
308 | qDebug("error send mail %i",_sendCount); | ||
309 | status->setText(tr("<font color=#ff0000>Error occoured during sending.</font>")); | ||
310 | QMessageBox::warning(this, tr("Error"), tr("<p>%1</p").arg(error), tr("Ok")); | ||
311 | } | ||
312 | |||
313 | void Composer::slotSendFinished() | 313 | void Composer::slotSendFinished() |
314 | { | 314 | { |
315 | QMessageBox::information(this, tr("Success"), tr("<p>The mail was sent successfully.</p>"), tr("Ok")); | 315 | QMessageBox::information(this, tr("Success"), tr("<p>The mail was sent successfully.</p>"), tr("Ok")); |
316 | 316 | ||
317 | status->setText(QString(0)); | 317 | status->setText(QString(0)); |
318 | abort->setEnabled(false); | 318 | abort->setEnabled(false); |
319 | } | 319 | } |
320 | 320 | ||
321 | void Composer::slotSendQueuedFinished() | ||
322 | { | ||
323 | |||
324 | _sendCount++; | ||
325 | qDebug("finished send mail %i of %i (error %i)",_sendCount,_toSend,_sendError); | ||
326 | if (_sendCount < _toSend) return; | ||
327 | if (_sendError == _toSend) close(); | ||
328 | QMessageBox::information(this, tr("Success"), tr("<p>The queued mails ")+QString::number(_toSend-_sendError)+tr(" of ")+QString::number(_toSend)+(" were sent successfully.</p>"), tr("Ok")); | ||
329 | Config cfg( "mailqueue", Config::User ); | ||
330 | cfg.setGroup( "Settings" ); | ||
331 | cfg.writeEntry( "count", 0 ); | ||
332 | for (int i=1;i<=_sendCount;i++) | ||
333 | { | ||
334 | cfg.setGroup( "Mail_" + QString::number(i) ); | ||
335 | qDebug("remove mail %i", i); | ||
336 | cfg.clearGroup(); | ||
337 | cfg.removeEntry( "Mail_" + QString::number(i) ); | ||
338 | } | ||
339 | close(); | ||
340 | } | ||
341 | |||
321 | void Composer::slotFillStuff() | 342 | void Composer::slotFillStuff() |
322 | { | 343 | { |
323 | QValueList<Account> accounts = ConfigFile::getAccounts(); | 344 | QValueList<Account> accounts = ConfigFile::getAccounts(); |
324 | int i = 0; | 345 | int i = 0; |
325 | 346 | ||
326 | QValueList<Account>::Iterator it; | 347 | QValueList<Account>::Iterator it; |
327 | for (it = accounts.begin(); it != accounts.end(); it++) { | 348 | for (it = accounts.begin(); it != accounts.end(); it++) { |
328 | if (!(*it).email().isEmpty() && !(*it).smtpServer().isEmpty() && !(*it).smtpPort().isEmpty()) { | 349 | if (!(*it).email().isEmpty() && !(*it).smtpServer().isEmpty() && !(*it).smtpPort().isEmpty()) { |
329 | if (!(*it).realName().isEmpty()) | 350 | if (!(*it).realName().isEmpty()) |
330 | from->insertItem((*it).realName() + " <" + (*it).email() + ">", i); | 351 | from->insertItem((*it).realName() + " <" + (*it).email() + ">", i); |
331 | else | 352 | else |
332 | from->insertItem((*it).email()); | 353 | from->insertItem((*it).email()); |