-rw-r--r-- | kmicromail/opiemail.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp index 6e54bf4..760e3b0 100644 --- a/kmicromail/opiemail.cpp +++ b/kmicromail/opiemail.cpp | |||
@@ -1,87 +1,88 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | // CHANGED 2004-08-06 Lutz Rogowski | 2 | // CHANGED 2004-08-06 Lutz Rogowski |
3 | 3 | ||
4 | 4 | ||
5 | #define protected public | 5 | #define protected public |
6 | #include <qwidget.h> | 6 | #include <qwidget.h> |
7 | #undef protected | 7 | #undef protected |
8 | #include "koprefsdialog.h" | 8 | #include "koprefsdialog.h" |
9 | #include <kapplication.h> | 9 | #include <kapplication.h> |
10 | #include <libkdepim/externalapphandler.h> | 10 | #include <libkdepim/externalapphandler.h> |
11 | #include <libkdepim/kpimglobalprefs.h> | 11 | #include <libkdepim/kpimglobalprefs.h> |
12 | #ifdef MINIKDE_KDIALOG_H | 12 | #ifdef MINIKDE_KDIALOG_H |
13 | #undef MINIKDE_KDIALOG_H | 13 | #undef MINIKDE_KDIALOG_H |
14 | #endif | 14 | #endif |
15 | #include "settingsdialog.h" | 15 | #include "settingsdialog.h" |
16 | #include "opiemail.h" | 16 | #include "opiemail.h" |
17 | #include "editaccounts.h" | 17 | #include "editaccounts.h" |
18 | #include "composemail.h" | 18 | #include "composemail.h" |
19 | #include "mailistviewitem.h" | 19 | #include "mailistviewitem.h" |
20 | #include "viewmail.h" | 20 | #include "viewmail.h" |
21 | #include "selectstore.h" | 21 | #include "selectstore.h" |
22 | #include "selectsmtp.h" | 22 | #include "selectsmtp.h" |
23 | #include "accountitem.h" | 23 | #include "accountitem.h" |
24 | #include "accountview.h" | ||
24 | #include "klocale.h" | 25 | #include "klocale.h" |
25 | 26 | ||
26 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
27 | #include <qtimer.h> | 28 | #include <qtimer.h> |
28 | #include <qcursor.h> | 29 | #include <qcursor.h> |
29 | #include <qtextbrowser.h> | 30 | #include <qtextbrowser.h> |
30 | #include <qregexp.h> | 31 | #include <qregexp.h> |
31 | #include <qpe/global.h> | 32 | #include <qpe/global.h> |
32 | 33 | ||
33 | #ifdef DESKTOP_VERSION | 34 | #ifdef DESKTOP_VERSION |
34 | #include <qapplication.h> | 35 | #include <qapplication.h> |
35 | #else | 36 | #else |
36 | #include <qpe/qpeapplication.h> | 37 | #include <qpe/qpeapplication.h> |
37 | #endif | 38 | #endif |
38 | #include <libmailwrapper/smtpwrapper.h> | 39 | #include <libmailwrapper/smtpwrapper.h> |
39 | #include <libmailwrapper/mailtypes.h> | 40 | #include <libmailwrapper/mailtypes.h> |
40 | #include <libmailwrapper/abstractmail.h> | 41 | #include <libmailwrapper/abstractmail.h> |
41 | #include "koprefs.h" | 42 | #include "koprefs.h" |
42 | 43 | ||
43 | //using namespace Opie::Core; | 44 | //using namespace Opie::Core; |
44 | 45 | ||
45 | OpieMail::OpieMail( QWidget *parent, const char *name ) | 46 | OpieMail::OpieMail( QWidget *parent, const char *name ) |
46 | : MainWindow( parent, name) //, WStyle_ContextHelp ) | 47 | : MainWindow( parent, name) //, WStyle_ContextHelp ) |
47 | { | 48 | { |
48 | settings = new Settings(); | 49 | settings = new Settings(); |
49 | tb = 0; | 50 | tb = 0; |
50 | setIcon(SmallIcon( "kmicromail" ) ); | 51 | setIcon(SmallIcon( "kmicromail" ) ); |
51 | folderView->populate( settings->getAccounts() ); | 52 | folderView->populate( settings->getAccounts() ); |
52 | 53 | ||
53 | } | 54 | } |
54 | 55 | ||
55 | OpieMail::~OpieMail() | 56 | OpieMail::~OpieMail() |
56 | { | 57 | { |
57 | if (settings) delete settings; | 58 | if (settings) delete settings; |
58 | if ( tb ) | 59 | if ( tb ) |
59 | delete tb; | 60 | delete tb; |
60 | } | 61 | } |
61 | 62 | ||
62 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) | 63 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) |
63 | { | 64 | { |
64 | 65 | ||
65 | } | 66 | } |
66 | #include <stdlib.h> | 67 | #include <stdlib.h> |
67 | void OpieMail::message(const QCString &msg, const QByteArray &data) | 68 | void OpieMail::message(const QCString &msg, const QByteArray &data) |
68 | { | 69 | { |
69 | // copied from old mail2 | 70 | // copied from old mail2 |
70 | static int ii = 0; | 71 | static int ii = 0; |
71 | //qDebug("QCOP CALL ############################# %d ", ii); | 72 | //qDebug("QCOP CALL ############################# %d ", ii); |
72 | //QString mess ( msg ); | 73 | //QString mess ( msg ); |
73 | //qDebug("Message = %s ",mess.latin1()); | 74 | //qDebug("Message = %s ",mess.latin1()); |
74 | ++ii; | 75 | ++ii; |
75 | //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); | 76 | //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); |
76 | 77 | ||
77 | mPendingEmail = QString::null; | 78 | mPendingEmail = QString::null; |
78 | mPendingName = QString::null; | 79 | mPendingName = QString::null; |
79 | if (msg == "writeMail(QString,QString)") | 80 | if (msg == "writeMail(QString,QString)") |
80 | { | 81 | { |
81 | //qDebug("writeMail(QString,QString) "); | 82 | //qDebug("writeMail(QString,QString) "); |
82 | QDataStream stream(data,IO_ReadOnly); | 83 | QDataStream stream(data,IO_ReadOnly); |
83 | stream >> mPendingName >> mPendingEmail; | 84 | stream >> mPendingName >> mPendingEmail; |
84 | // removing the whitespaces at beginning and end is needed! | 85 | // removing the whitespaces at beginning and end is needed! |
85 | QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); | 86 | QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); |
86 | } | 87 | } |
87 | else if (msg == "newMail()") | 88 | else if (msg == "newMail()") |
@@ -252,129 +253,164 @@ void OpieMail::slotEditSettings() | |||
252 | void OpieMail::slotEditAccounts() | 253 | void OpieMail::slotEditAccounts() |
253 | { | 254 | { |
254 | EditAccounts eaDialog( settings, this, 0, true ); | 255 | EditAccounts eaDialog( settings, this, 0, true ); |
255 | eaDialog.slotAdjustColumns(); | 256 | eaDialog.slotAdjustColumns(); |
256 | #ifndef DESKTOP_VERSION | 257 | #ifndef DESKTOP_VERSION |
257 | eaDialog.showMaximized(); | 258 | eaDialog.showMaximized(); |
258 | #endif | 259 | #endif |
259 | eaDialog.exec(); | 260 | eaDialog.exec(); |
260 | if ( settings ) delete settings; | 261 | if ( settings ) delete settings; |
261 | settings = new Settings(); | 262 | settings = new Settings(); |
262 | 263 | ||
263 | folderView->populate( settings->getAccounts() ); | 264 | folderView->populate( settings->getAccounts() ); |
264 | } | 265 | } |
265 | void OpieMail::replyMail() | 266 | void OpieMail::replyMail() |
266 | { | 267 | { |
267 | 268 | ||
268 | QListViewItem*item = mailView->currentItem(); | 269 | QListViewItem*item = mailView->currentItem(); |
269 | if (!item) return; | 270 | if (!item) return; |
270 | RecMailP mail = ((MailListViewItem*)item)->data(); | 271 | RecMailP mail = ((MailListViewItem*)item)->data(); |
271 | RecBodyP body = folderView->fetchBody(mail); | 272 | RecBodyP body = folderView->fetchBody(mail); |
272 | 273 | ||
273 | QString rtext; | 274 | QString rtext; |
274 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 275 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
275 | .arg( mail->getFrom()) | 276 | .arg( mail->getFrom()) |
276 | .arg( mail->getDate()); | 277 | .arg( mail->getDate()); |
277 | 278 | ||
278 | QString text = body->Bodytext(); | 279 | QString text = body->Bodytext(); |
279 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 280 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
280 | QStringList::Iterator it; | 281 | QStringList::Iterator it; |
281 | for (it = lines.begin(); it != lines.end(); it++) | 282 | for (it = lines.begin(); it != lines.end(); it++) |
282 | { | 283 | { |
283 | rtext += "> " + *it + "\n"; | 284 | rtext += "> " + *it + "\n"; |
284 | } | 285 | } |
285 | rtext += "\n"; | 286 | rtext += "\n"; |
286 | 287 | ||
287 | QString prefix; | 288 | QString prefix; |
288 | if ( mail->getSubject().find(QRegExp("^Re: .*$")) != -1) prefix = ""; | 289 | if ( mail->getSubject().find(QRegExp("^Re: .*$")) != -1) prefix = ""; |
289 | else prefix = "Re: "; // no i18n on purpose | 290 | else prefix = "Re: "; // no i18n on purpose |
290 | 291 | ||
291 | Settings *settings = new Settings(); | 292 | Settings *settings = new Settings(); |
292 | ComposeMail composer( settings ,this, 0, true); | 293 | ComposeMail composer( settings ,this, 0, true); |
293 | if (mail->Replyto().isEmpty()) { | 294 | if (mail->Replyto().isEmpty()) { |
294 | composer.setTo( mail->getFrom()); | 295 | composer.setTo( mail->getFrom()); |
295 | } else { | 296 | } else { |
296 | composer.setTo( mail->Replyto()); | 297 | composer.setTo( mail->Replyto()); |
297 | } | 298 | } |
298 | composer.setSubject( prefix + mail->getSubject()); | 299 | composer.setSubject( prefix + mail->getSubject()); |
299 | composer.setMessage( rtext ); | 300 | composer.setMessage( rtext ); |
300 | composer.setInReplyTo( mail->Msgid()); | 301 | composer.setInReplyTo( mail->Msgid()); |
301 | composer.setCharset( body->getCharset() ); | 302 | composer.setCharset( body->getCharset() ); |
302 | if ( QDialog::Accepted == KApplication::execDialog( &composer ) ) | 303 | if ( QDialog::Accepted == KApplication::execDialog( &composer ) ) |
303 | { | 304 | { |
304 | mail->Wrapper()->answeredMail(mail); | 305 | mail->Wrapper()->answeredMail(mail); |
305 | } | 306 | } |
306 | delete settings; | 307 | delete settings; |
307 | 308 | ||
308 | } | 309 | } |
309 | void OpieMail::closeViewMail(ViewMail * vm) | 310 | void OpieMail::closeViewMail(ViewMail * vm) |
310 | { | 311 | { |
311 | vm->hide(); | 312 | vm->hide(); |
312 | } | 313 | } |
313 | 314 | ||
314 | void OpieMail::slotDownloadMail( ) | 315 | void OpieMail::slotDownloadMail( ) |
315 | { | 316 | { |
316 | qDebug("slotDownloadMail( ) "); | 317 | QListViewItem*item = mailView->currentItem(); |
318 | if (!item ) { | ||
319 | Global::statusMessage("Error: No item slected!"); | ||
320 | return; | ||
321 | } | ||
322 | RecMailP mail = ((MailListViewItem*)item)->data(); | ||
323 | Account * acc = mail->Wrapper()->getAccount(); | ||
324 | if ( !acc ) { | ||
325 | Global::statusMessage("Mail is already stored locally!"); | ||
326 | return; | ||
327 | } | ||
328 | QString lfName = acc->getLocalFolder(); | ||
329 | //qDebug("local folder " + lfName ); | ||
330 | if ( lfName.isEmpty() ) | ||
331 | lfName = acc->getAccountName(); | ||
332 | AbstractMail* targetMail = folderView->allAccounts()[0]->getWrapper(); | ||
333 | //qDebug("target %d %d ",targetMail,mail->Wrapper() ); | ||
334 | if ( targetMail == mail->Wrapper() ) { | ||
335 | Global::statusMessage("Mail is already locally stored!"); | ||
336 | return; | ||
337 | } | ||
338 | if ( !targetMail->createMbox(lfName)) { | ||
339 | Global::statusMessage("Error creating folder!"); | ||
340 | return; | ||
341 | } | ||
342 | Global::statusMessage("Fetching mail...please wait!"); | ||
343 | qApp->processEvents(); | ||
344 | encodedString*st = 0; | ||
345 | st = mail->Wrapper()->fetchRawBody(mail); | ||
346 | if ( st ) { | ||
347 | targetMail->storeMessage(st->Content(),st->Length(),lfName); | ||
348 | Global::statusMessage("Mail stored in "+ lfName); | ||
349 | delete st; | ||
350 | } else { | ||
351 | Global::statusMessage("Error: Cannot fetch mail!"); | ||
352 | } | ||
317 | } | 353 | } |
318 | 354 | ||
319 | 355 | ||
320 | void OpieMail::deleteAndDisplayNextMail(ViewMail * vm) | 356 | void OpieMail::deleteAndDisplayNextMail(ViewMail * vm) |
321 | { | 357 | { |
322 | QListViewItem*item = mailView->currentItem(); | 358 | QListViewItem*item = mailView->currentItem(); |
323 | if (!item ) { | 359 | if (!item ) { |
324 | closeViewMail(vm); | 360 | closeViewMail(vm); |
325 | return; | 361 | return; |
326 | } | 362 | } |
327 | RecMailP mail = ((MailListViewItem*)item)->data(); | 363 | RecMailP mail = ((MailListViewItem*)item)->data(); |
328 | mail->Wrapper()->deleteMail( mail ); | 364 | mail->Wrapper()->deleteMail( mail ); |
329 | item = item->itemBelow(); | 365 | item = item->itemBelow(); |
330 | if (!item ) { | 366 | if (!item ) { |
331 | closeViewMail(vm); | 367 | closeViewMail(vm); |
332 | return; | 368 | return; |
333 | } | 369 | } |
334 | mailView->setCurrentItem(item); | 370 | mailView->setCurrentItem(item); |
335 | mail = ((MailListViewItem*)item)->data(); | 371 | mail = ((MailListViewItem*)item)->data(); |
336 | RecBodyP body = folderView->fetchBody(mail); | 372 | RecBodyP body = folderView->fetchBody(mail); |
337 | vm->setBody( body ); | 373 | vm->setBody( body ); |
338 | vm->setMail( mail ); | 374 | vm->setMail( mail ); |
339 | } | 375 | } |
340 | void OpieMail::displayNextMail(ViewMail * vm) | 376 | void OpieMail::displayNextMail(ViewMail * vm) |
341 | { | 377 | { |
342 | QListViewItem*item = mailView->currentItem(); | 378 | QListViewItem*item = mailView->currentItem(); |
343 | if (!item) return; | 379 | if (!item) return; |
344 | ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); | 380 | ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); |
345 | item = item->itemBelow(); | 381 | item = item->itemBelow(); |
346 | if (!item) { | 382 | if (!item) { |
347 | vm->setCaption(i18n("End of List" )); | 383 | vm->setCaption(i18n("End of List" )); |
348 | return; | 384 | return; |
349 | } | 385 | } |
350 | mailView->setCurrentItem(item); | 386 | mailView->setCurrentItem(item); |
351 | RecMailP mail = ((MailListViewItem*)item)->data(); | 387 | RecMailP mail = ((MailListViewItem*)item)->data(); |
352 | RecBodyP body = folderView->fetchBody(mail); | 388 | RecBodyP body = folderView->fetchBody(mail); |
353 | vm->setBody( body ); | 389 | vm->setBody( body ); |
354 | vm->setMail( mail ); | 390 | vm->setMail( mail ); |
355 | } | 391 | } |
356 | void OpieMail::displayMail() | 392 | void OpieMail::displayMail() |
357 | { | 393 | { |
358 | QListViewItem*item = mailView->currentItem(); | 394 | QListViewItem*item = mailView->currentItem(); |
359 | if (!item) return; | 395 | if (!item) return; |
360 | RecMailP mail = ((MailListViewItem*)item)->data(); | 396 | RecMailP mail = ((MailListViewItem*)item)->data(); |
361 | RecBodyP body = folderView->fetchBody(mail); | 397 | RecBodyP body = folderView->fetchBody(mail); |
362 | ViewMail readMail( this,"", Qt::WType_Modal ); | 398 | ViewMail readMail( this,"", Qt::WType_Modal ); |
363 | readMail.setBody( body ); | 399 | readMail.setBody( body ); |
364 | readMail.setMail( mail ); | 400 | readMail.setMail( mail ); |
365 | #ifndef DESKTOP_VERSION | 401 | #ifndef DESKTOP_VERSION |
366 | readMail.showMaximized(); | 402 | readMail.showMaximized(); |
367 | #else | 403 | #else |
368 | readMail.resize( 640, 480); | 404 | readMail.resize( 640, 480); |
369 | #endif | 405 | #endif |
370 | connect( &readMail,SIGNAL( showNextMail(ViewMail *) ), this, SLOT( displayNextMail(ViewMail *) ) ); | 406 | connect( &readMail,SIGNAL( showNextMail(ViewMail *) ), this, SLOT( displayNextMail(ViewMail *) ) ); |
371 | connect( &readMail,SIGNAL( deleteAndDisplayNextMail(ViewMail *) ), this, SLOT(deleteAndDisplayNextMail(ViewMail *) ) ); | 407 | connect( &readMail,SIGNAL( deleteAndDisplayNextMail(ViewMail *) ), this, SLOT(deleteAndDisplayNextMail(ViewMail *) ) ); |
372 | connect( &readMail,SIGNAL( signalDownloadMail() ), this, SLOT( slotDownloadMail() ) ); | 408 | connect( &readMail,SIGNAL( signalDownloadMail() ), this, SLOT( slotDownloadMail() ) ); |
373 | 409 | ||
374 | readMail.exec(); | 410 | readMail.exec(); |
375 | 411 | ||
376 | if ( readMail.deleted ) | 412 | if ( readMail.deleted ) |
377 | { | 413 | { |
378 | folderView->refreshCurrent(); | 414 | folderView->refreshCurrent(); |
379 | } | 415 | } |
380 | else | 416 | else |