summaryrefslogtreecommitdiffabout
path: root/kmicromail/composemail.cpp
Unidiff
Diffstat (limited to 'kmicromail/composemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/composemail.cpp58
1 files changed, 35 insertions, 23 deletions
diff --git a/kmicromail/composemail.cpp b/kmicromail/composemail.cpp
index f44100b..49fd14f 100644
--- a/kmicromail/composemail.cpp
+++ b/kmicromail/composemail.cpp
@@ -1,24 +1,24 @@
1// CHANGED 2004-08-06 Lutz Rogowski 1// CHANGED 2004-08-06 Lutz Rogowski
2 2
3#include <kabc/addresseedialog.h> 3
4#include <kabc/stdaddressbook.h>
5#include <kabc/addressee.h>
6#ifdef DESKTOP_VERSION 4#ifdef DESKTOP_VERSION
7#include <qapplication.h> 5#include <qapplication.h>
8#include <kabc/addresseedialog.h> 6#include <kabc/addresseedialog.h>
7#include <kabc/stdaddressbook.h>
8#include <kabc/addressee.h>
9#endif //DESKTOP_VERSION 9#endif //DESKTOP_VERSION
10#include <libkdepim/externalapphandler.h> 10#include <libkdepim/externalapphandler.h>
11 11
12#include "koprefs.h" 12#include "koprefs.h"
13 13
14#ifdef MINIKDE_KDIALOG_H 14#ifdef MINIKDE_KDIALOG_H
15#undef MINIKDE_KDIALOG_H 15#undef MINIKDE_KDIALOG_H
16#endif 16#endif
17 17
18 18
19#include "composemail.h" 19#include "composemail.h"
20 20
21#include <libmailwrapper/smtpwrapper.h> 21#include <libmailwrapper/smtpwrapper.h>
22#include <libmailwrapper/storemail.h> 22#include <libmailwrapper/storemail.h>
23#include <libmailwrapper/abstractmail.h> 23#include <libmailwrapper/abstractmail.h>
24#include <libmailwrapper/mailtypes.h> 24#include <libmailwrapper/mailtypes.h>
@@ -35,33 +35,35 @@
35#include <qcombobox.h> 35#include <qcombobox.h>
36#include <qcheckbox.h> 36#include <qcheckbox.h>
37#include <qiconset.h> 37#include <qiconset.h>
38#include <qtimer.h> 38#include <qtimer.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qlabel.h> 42#include <qlabel.h>
43#include <qtabwidget.h> 43#include <qtabwidget.h>
44#include <qlistview.h> 44#include <qlistview.h>
45 45
46//using namespace Opie::Core; 46//using namespace Opie::Core;
47//using namespace Opie::Ui; 47//using namespace Opie::Ui;
48ComposeMail::ComposeMail( Settings *sett, QWidget *parent, const char *name, bool modal ) 48ComposeMail::ComposeMail( Settings *sett, QWidget *parent, const char *name, bool modal )
49 : ComposeMailUI( parent, name, modal ) 49 : ComposeMailUI( parent, name, modal )
50{ 50{
51
51 mPickLineEdit = 0; 52 mPickLineEdit = 0;
53 mEncoding = KOPrefs::instance()->mCurrentCodeName;
52 connect(ExternalAppHandler::instance(), SIGNAL(receivedNameEmailUidListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&)), 54 connect(ExternalAppHandler::instance(), SIGNAL(receivedNameEmailUidListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&)),
53 this, SLOT(insertAttendees(const QString&, const QStringList&, const QStringList&, const QStringList&))); 55 this, SLOT(insertAttendees(const QString&, const QStringList&, const QStringList&, const QStringList&)));
54 settings = sett; 56 settings = sett;
55 m_replyid = ""; 57 m_replyid = "";
56 if ( KOPrefs::instance()->mUseKapi) { 58 if ( KOPrefs::instance()->mUseKapi) {
57 KConfig config( locateLocal("config", "kabcrc") ); 59 KConfig config( locateLocal("config", "kabcrc") );
58 config.setGroup( "General" ); 60 config.setGroup( "General" );
59 QString whoami_uid = config.readEntry( "WhoAmI" ); 61 QString whoami_uid = config.readEntry( "WhoAmI" );
60 62
61 if ( whoami_uid.isEmpty() ) { 63 if ( whoami_uid.isEmpty() ) {
62 QMessageBox::information( 0, i18n( "Hint" ), 64 QMessageBox::information( 0, i18n( "Hint" ),
63 i18n( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), 65 i18n( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ),
64 i18n( "Ok" ) ); 66 i18n( "Ok" ) );
65 67
66 68
67 fillSettings(); 69 fillSettings();
@@ -152,51 +154,51 @@ void ComposeMail::fillSettings()
152 if ( QApplication::desktop()->width() < 320 ) 154 if ( QApplication::desktop()->width() < 320 )
153 fromBox->setMaximumWidth( 100 ); 155 fromBox->setMaximumWidth( 100 );
154 QStringList mailList = QStringList::split(";",KOPrefs::instance()->mEmail); 156 QStringList mailList = QStringList::split(";",KOPrefs::instance()->mEmail);
155 QStringList::ConstIterator sit = mailList.begin(); 157 QStringList::ConstIterator sit = mailList.begin();
156 int pref = 0; 158 int pref = 0;
157 for (;sit!=mailList.end();++sit) { 159 for (;sit!=mailList.end();++sit) {
158 fromBox->insertItem((*sit)); 160 fromBox->insertItem((*sit));
159 } 161 }
160 senderNameEdit->setText(KOPrefs::instance()->mName); 162 senderNameEdit->setText(KOPrefs::instance()->mName);
161} 163}
162 164
163 165
164void ComposeMail::saveAsDraft() 166void ComposeMail::saveAsDraft()
165{ 167{
166 168
167 Opie::Core::OSmartPointer<Mail> mail= new Mail(); 169 Opie::Core::OSmartPointer<Mail> mail= new Mail();
168 mail->setMail(fromBox->currentText().utf8 ()); 170 mail->setMail(fromBox->currentText());
169 mail->setTo( toLine->text().utf8 () ); 171 mail->setTo( toLine->text() );
170 mail->setName(senderNameEdit->text().utf8 ()); 172 mail->setName(senderNameEdit->text());
171 mail->setCC( ccLine->text().utf8 () ); 173 mail->setCC( ccLine->text() );
172 mail->setBCC( bccLine->text().utf8 () ); 174 mail->setBCC( bccLine->text() );
173 mail->setReply( replyLine->text().utf8 () ); 175 mail->setReply( replyLine->text() );
174 mail->setSubject( subjectLine->text().utf8 () ); 176 mail->setSubject( subjectLine->text() );
175 if (!m_replyid.isEmpty()) { 177 if (!m_replyid.isEmpty()) {
176 QStringList ids; 178 QStringList ids;
177 ids.append(m_replyid); 179 ids.append(m_replyid);
178 mail->setInreply(ids); 180 mail->setInreply(ids);
179 } 181 }
180 QString txt = message->text().utf8 (); 182 QString txt = message->text();
181 if ( !sigMultiLine->text().isEmpty() ) { 183 if ( !sigMultiLine->text().isEmpty() ) {
182 txt.append( "\n--\n" ); 184 txt.append( "\n--\n" );
183 txt.append( sigMultiLine->text() ); 185 txt.append( sigMultiLine->text() );
184 } 186 }
185 mail->setMessage( txt ); 187 mail->setMessage( txt );
186 188 mail->setCharset (mEncoding);
187 /* only use the default drafts folder name! */ 189 /* only use the default drafts folder name! */
188 Storemail wrapper(AbstractMail::draftFolder()); 190 Storemail wrapper(AbstractMail::draftFolder());
189 wrapper.storeMail(mail); 191 wrapper.storeMail(mail);
190 192
191 AttachViewItem *it = (AttachViewItem *) attList->firstChild(); 193 AttachViewItem *it = (AttachViewItem *) attList->firstChild();
192 /* attachments we will ignore! */ 194 /* attachments we will ignore! */
193 if ( it != 0 ) { 195 if ( it != 0 ) {
194 if ( warnAttach ) 196 if ( warnAttach )
195 QMessageBox::warning(0,i18n("Store message"), 197 QMessageBox::warning(0,i18n("Store message"),
196 i18n("<center>Attachments will not be stored in \"Draft\" folder</center>")); 198 i18n("<center>Attachments will not be stored in \"Draft\" folder</center>"));
197 warnAttach = false; 199 warnAttach = false;
198 } 200 }
199 setStatus( i18n("Mail saved as draft!") ); 201 setStatus( i18n("Mail saved as draft!") );
200} 202}
201void ComposeMail::clearStatus() 203void ComposeMail::clearStatus()
202{ 204{
@@ -395,58 +397,59 @@ void ComposeMail::accept()
395 int yesno = QMessageBox::warning(0,i18n("Stop editing message"), 397 int yesno = QMessageBox::warning(0,i18n("Stop editing message"),
396 i18n("Send this message?"), 398 i18n("Send this message?"),
397 i18n("Yes"), 399 i18n("Yes"),
398 i18n("Cancel")); 400 i18n("Cancel"));
399 401
400 if (yesno == 1) { 402 if (yesno == 1) {
401 return; 403 return;
402 } 404 }
403 } 405 }
404#if 0 406#if 0
405 odebug << "Sending Mail with " 407 odebug << "Sending Mail with "
406 << smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() << oendl; 408 << smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() << oendl;
407#endif 409#endif
408 Opie::Core::OSmartPointer<Mail> mail=new Mail; 410 Opie::Core::OSmartPointer<Mail> mail=new Mail;
409 411
410 SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); 412 SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() );
411 mail->setMail(fromBox->currentText().utf8 ()); 413 mail->setMail(fromBox->currentText());
412 414
413 if ( !toLine->text().isEmpty() ) { 415 if ( !toLine->text().isEmpty() ) {
414 mail->setTo( toLine->text().utf8 () ); 416 mail->setTo( toLine->text() );
415 } else { 417 } else {
416 QMessageBox::warning(0,i18n("Sending mail"), 418 QMessageBox::warning(0,i18n("Sending mail"),
417 i18n("No Receiver spezified" ) ); 419 i18n("No Receiver spezified" ) );
418 return; 420 return;
419 } 421 }
420 422
421 mail->setName(senderNameEdit->text().utf8 ()); 423 mail->setName(senderNameEdit->text());
422 mail->setCC( ccLine->text().utf8 () ); 424 mail->setCC( ccLine->text() );
423 mail->setBCC( bccLine->text().utf8 () ); 425 mail->setBCC( bccLine->text() );
424 mail->setReply( replyLine->text().utf8 () ); 426 mail->setReply( replyLine->text() );
425 mail->setSubject( subjectLine->text().utf8 () ); 427 mail->setSubject( subjectLine->text() );
426 if (!m_replyid.isEmpty()) { 428 if (!m_replyid.isEmpty()) {
427 QStringList ids; 429 QStringList ids;
428 ids.append(m_replyid.utf8 ()); 430 ids.append(m_replyid);
429 mail->setInreply(ids); 431 mail->setInreply(ids);
430 } 432 }
431 QString txt = message->text().utf8 (); 433 QString txt = message->text();
432 if ( !sigMultiLine->text().isEmpty() ) { 434 if ( !sigMultiLine->text().isEmpty() ) {
433 txt.append( "\n--\n" ); 435 txt.append( "\n--\n" );
434 txt.append( sigMultiLine->text().utf8 () ); 436 txt.append( sigMultiLine->text() );
435 } 437 }
436 mail->setMessage( txt ); 438 mail->setMessage( txt );
439 mail->setCharset (mEncoding);
437 AttachViewItem *it = (AttachViewItem *) attList->firstChild(); 440 AttachViewItem *it = (AttachViewItem *) attList->firstChild();
438 while ( it != 0 ) { 441 while ( it != 0 ) {
439 mail->addAttachment( it->getAttachment() ); 442 mail->addAttachment( it->getAttachment() );
440 it = (AttachViewItem *) it->nextSibling(); 443 it = (AttachViewItem *) it->nextSibling();
441 } 444 }
442 445
443 SMTPwrapper wrapper( smtp ); 446 SMTPwrapper wrapper( smtp );
444 if ( wrapper.sendMail( mail,checkBoxLater->isChecked() ) ) 447 if ( wrapper.sendMail( mail,checkBoxLater->isChecked() ) )
445 setStatus( tr ("Mail sent")); 448 setStatus( tr ("Mail sent"));
446 else { 449 else {
447 setStatus( tr ("Error: Something went wrong. Nothing sent")); 450 setStatus( tr ("Error: Something went wrong. Nothing sent"));
448 return; 451 return;
449 } 452 }
450 453
451 454
452 QDialog::accept(); 455 QDialog::accept();
@@ -463,41 +466,50 @@ void ComposeMail::reject()
463 //qDebug("button %d ", yesno); 466 //qDebug("button %d ", yesno);
464 if (yesno == 0) { 467 if (yesno == 0) {
465 if ( toLine->text().isEmpty() ) { 468 if ( toLine->text().isEmpty() ) {
466 QMessageBox::warning(0,i18n("Sending mail"), 469 QMessageBox::warning(0,i18n("Sending mail"),
467 i18n("No Receiver spezified" ) ); 470 i18n("No Receiver spezified" ) );
468 return; 471 return;
469 } 472 }
470 saveAsDraft(); 473 saveAsDraft();
471 } 474 }
472 if (yesno == 2) { 475 if (yesno == 2) {
473 qDebug("return "); 476 qDebug("return ");
474 return; 477 return;
475 } 478 }
476 QDialog::reject(); 479 QDialog::reject();
477} 480}
478 481
482void ComposeMail::setCharset(const QString& charset)
483{
484 if ( !charset.isEmpty() )
485 mEncoding = charset;
486 qDebug("ComposeMail::setCharset %s ", mEncoding.latin1());
487}
479ComposeMail::~ComposeMail() 488ComposeMail::~ComposeMail()
480{ 489{
481} 490}
482 491
483void ComposeMail::reEditMail(const RecMailP&current) 492void ComposeMail::reEditMail(const RecMailP&current)
484{ 493{
485 RecMailP data = current; 494 RecMailP data = current;
486 message->setText(data->Wrapper()->fetchBody(current)->Bodytext()); 495 RecBodyP body = data->Wrapper()->fetchBody(current);
496
497 message->setText(body->Bodytext());
487 subjectLine->setText( data->getSubject()); 498 subjectLine->setText( data->getSubject());
488 toLine->setText(data->To().join(",")); 499 toLine->setText(data->To().join(","));
489 ccLine->setText(data->CC().join(",")); 500 ccLine->setText(data->CC().join(","));
490 bccLine->setText(data->Bcc().join(",")); 501 bccLine->setText(data->Bcc().join(","));
491 replyLine->setText(data->Replyto()); 502 replyLine->setText(data->Replyto());
503 setCharset(body->getCharset());
492} 504}
493 505
494AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) 506AttachViewItem::AttachViewItem( QListView *parent, Attachment *att )
495 : QListViewItem( parent ) 507 : QListViewItem( parent )
496{ 508{
497 attachment = att; 509 attachment = att;
498 if ( !attachment->getPixmap().isNull() ) 510 if ( !attachment->getPixmap().isNull() )
499 setPixmap( 0,attachment->getPixmap() ); 511 setPixmap( 0,attachment->getPixmap() );
500 setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); 512 setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() );
501 setText( 1, QString::number( att->getSize() ) ); 513 setText( 1, QString::number( att->getSize() ) );
502} 514}
503 515