-rw-r--r-- | kmicromail/composemail.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/kmicromail/composemail.cpp b/kmicromail/composemail.cpp index ca4f247..c1b58a4 100644 --- a/kmicromail/composemail.cpp +++ b/kmicromail/composemail.cpp | |||
@@ -1,141 +1,141 @@ | |||
1 | 1 | ||
2 | #include "composemail.h" | 2 | #include "composemail.h" |
3 | 3 | ||
4 | #include <libmailwrapper/smtpwrapper.h> | 4 | #include <libmailwrapper/smtpwrapper.h> |
5 | #include <libmailwrapper/storemail.h> | 5 | #include <libmailwrapper/storemail.h> |
6 | #include <libmailwrapper/abstractmail.h> | 6 | #include <libmailwrapper/abstractmail.h> |
7 | #include <libmailwrapper/mailtypes.h> | 7 | #include <libmailwrapper/mailtypes.h> |
8 | 8 | ||
9 | /* OPIE */ | 9 | /* OPIE */ |
10 | //#include <opie2/ofiledialog.h> | 10 | //#include <opie2/ofiledialog.h> |
11 | //#include <opie2/odebug.h> | 11 | //#include <opie2/odebug.h> |
12 | #include <kfiledialog.h> | 12 | #include <kfiledialog.h> |
13 | //#include <qpe/resource.h> | 13 | //#include <qpe/resource.h> |
14 | #include <qpe/config.h> | 14 | #include <qpe/config.h> |
15 | #include <qpe/global.h> | 15 | #include <qpe/global.h> |
16 | //#include <qpe/contact.h> | 16 | //#include <qpe/contact.h> |
17 | 17 | ||
18 | 18 | ||
19 | #include <qcombobox.h> | 19 | #include <qcombobox.h> |
20 | #include <qcheckbox.h> | 20 | #include <qcheckbox.h> |
21 | #include <qtimer.h> | 21 | #include <qtimer.h> |
22 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
23 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
24 | #include <qmultilineedit.h> | 24 | #include <qmultilineedit.h> |
25 | #include <qlabel.h> | 25 | #include <qlabel.h> |
26 | #include <qtabwidget.h> | 26 | #include <qtabwidget.h> |
27 | #include <qlistview.h> | 27 | #include <qlistview.h> |
28 | #include <kabc/addresseedialog.h> | 28 | #include <kabc/addresseedialog.h> |
29 | #include <kabc/stdaddressbook.h> | 29 | #include <kabc/stdaddressbook.h> |
30 | #include <kabc/addressee.h> | 30 | #include <kabc/addressee.h> |
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | //using namespace Opie::Core; | 34 | //using namespace Opie::Core; |
35 | //using namespace Opie::Ui; | 35 | //using namespace Opie::Ui; |
36 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 36 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
37 | : ComposeMailUI( parent, name, modal, flags ) | 37 | : ComposeMailUI( parent, name, modal, flags ) |
38 | { | 38 | { |
39 | 39 | ||
40 | settings = s; | 40 | settings = s; |
41 | m_replyid = ""; | 41 | m_replyid = ""; |
42 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); | 42 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); |
43 | QStringList mails = con.emails(); | 43 | QStringList mails = con.emails(); |
44 | QString defmail = con.preferredEmail(); | 44 | QString defmail = con.preferredEmail(); |
45 | if ( mails.count() == 0) | 45 | if ( mails.count() == 0) |
46 | QMessageBox::information( parentWidget(), tr( "Hint" ), | 46 | QMessageBox::information( 0, tr( "Hint" ), |
47 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!" ), | 47 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), |
48 | tr( "Ok" ) ); | 48 | tr( "Ok" ) ); |
49 | if (defmail.length()!=0) { | 49 | if (defmail.length()!=0) { |
50 | fromBox->insertItem(defmail); | 50 | fromBox->insertItem(defmail); |
51 | } | 51 | } |
52 | QStringList::ConstIterator sit = mails.begin(); | 52 | QStringList::ConstIterator sit = mails.begin(); |
53 | for (;sit!=mails.end();++sit) { | 53 | for (;sit!=mails.end();++sit) { |
54 | if ( (*sit)==defmail) | 54 | if ( (*sit)==defmail) |
55 | continue; | 55 | continue; |
56 | fromBox->insertItem((*sit)); | 56 | fromBox->insertItem((*sit)); |
57 | } | 57 | } |
58 | senderNameEdit->setText(con.formattedName()); | 58 | senderNameEdit->setText(con.formattedName()); |
59 | Config cfg( "mail" ); | 59 | Config cfg( "mail" ); |
60 | cfg.setGroup( "Compose" ); | 60 | cfg.setGroup( "Compose" ); |
61 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 61 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); |
62 | 62 | ||
63 | attList->addColumn( tr( "Name" ) ); | 63 | attList->addColumn( tr( "Name" ) ); |
64 | attList->addColumn( tr( "Size" ) ); | 64 | attList->addColumn( tr( "Size" ) ); |
65 | 65 | ||
66 | QList<Account> accounts = settings->getAccounts(); | 66 | QList<Account> accounts = settings->getAccounts(); |
67 | 67 | ||
68 | Account *it; | 68 | Account *it; |
69 | for ( it = accounts.first(); it; it = accounts.next() ) { | 69 | for ( it = accounts.first(); it; it = accounts.next() ) { |
70 | if ( it->getType()==MAILLIB::A_SMTP ) { | 70 | if ( it->getType()==MAILLIB::A_SMTP ) { |
71 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | 71 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); |
72 | smtpAccountBox->insertItem( smtp->getAccountName() ); | 72 | smtpAccountBox->insertItem( smtp->getAccountName() ); |
73 | smtpAccounts.append( smtp ); | 73 | smtpAccounts.append( smtp ); |
74 | } | 74 | } |
75 | } | 75 | } |
76 | if ( smtpAccounts.count() > 0 ) { | ||
77 | fillValues( smtpAccountBox->currentItem() ); | ||
78 | } else { | ||
79 | QMessageBox::information( parentWidget(), tr( "Problem" ), | ||
80 | tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail." ), | ||
81 | tr( "Ok" ) ); | ||
82 | return; | ||
83 | } | ||
84 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); | 76 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); |
85 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | 77 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); |
86 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | 78 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); |
87 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 79 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
88 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 80 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
89 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 81 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
90 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 82 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
91 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); | 83 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); |
92 | mMail = 0; | 84 | mMail = 0; |
93 | warnAttach = true; | 85 | warnAttach = true; |
86 | if ( smtpAccounts.count() > 0 ) { | ||
87 | fillValues( smtpAccountBox->currentItem() ); | ||
88 | } else { | ||
89 | QMessageBox::information( 0, tr( "Problem" ), | ||
90 | tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail.\n" ), | ||
91 | tr( "Ok" ) ); | ||
92 | return; | ||
93 | } | ||
94 | } | 94 | } |
95 | void ComposeMail::saveAsDraft() | 95 | void ComposeMail::saveAsDraft() |
96 | { | 96 | { |
97 | 97 | ||
98 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); | 98 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); |
99 | mail->setMail(fromBox->currentText()); | 99 | mail->setMail(fromBox->currentText()); |
100 | mail->setTo( toLine->text() ); | 100 | mail->setTo( toLine->text() ); |
101 | mail->setName(senderNameEdit->text()); | 101 | mail->setName(senderNameEdit->text()); |
102 | mail->setCC( ccLine->text() ); | 102 | mail->setCC( ccLine->text() ); |
103 | mail->setBCC( bccLine->text() ); | 103 | mail->setBCC( bccLine->text() ); |
104 | mail->setReply( replyLine->text() ); | 104 | mail->setReply( replyLine->text() ); |
105 | mail->setSubject( subjectLine->text() ); | 105 | mail->setSubject( subjectLine->text() ); |
106 | if (!m_replyid.isEmpty()) { | 106 | if (!m_replyid.isEmpty()) { |
107 | QStringList ids; | 107 | QStringList ids; |
108 | ids.append(m_replyid); | 108 | ids.append(m_replyid); |
109 | mail->setInreply(ids); | 109 | mail->setInreply(ids); |
110 | } | 110 | } |
111 | QString txt = message->text(); | 111 | QString txt = message->text(); |
112 | if ( !sigMultiLine->text().isEmpty() ) { | 112 | if ( !sigMultiLine->text().isEmpty() ) { |
113 | txt.append( "\n--\n" ); | 113 | txt.append( "\n--\n" ); |
114 | txt.append( sigMultiLine->text() ); | 114 | txt.append( sigMultiLine->text() ); |
115 | } | 115 | } |
116 | mail->setMessage( txt ); | 116 | mail->setMessage( txt ); |
117 | 117 | ||
118 | /* only use the default drafts folder name! */ | 118 | /* only use the default drafts folder name! */ |
119 | Storemail wrapper(AbstractMail::draftFolder()); | 119 | Storemail wrapper(AbstractMail::draftFolder()); |
120 | wrapper.storeMail(mail); | 120 | wrapper.storeMail(mail); |
121 | 121 | ||
122 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 122 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
123 | /* attachments we will ignore! */ | 123 | /* attachments we will ignore! */ |
124 | if ( it != 0 ) { | 124 | if ( it != 0 ) { |
125 | if ( warnAttach ) | 125 | if ( warnAttach ) |
126 | QMessageBox::warning(0,tr("Store message"), | 126 | QMessageBox::warning(0,tr("Store message"), |
127 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); | 127 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); |
128 | warnAttach = false; | 128 | warnAttach = false; |
129 | } | 129 | } |
130 | setStatus( tr("Mail saved as draft!") ); | 130 | setStatus( tr("Mail saved as draft!") ); |
131 | } | 131 | } |
132 | void ComposeMail::clearStatus() | 132 | void ComposeMail::clearStatus() |
133 | { | 133 | { |
134 | topLevelWidget()->setCaption( tr("Compose mail") ); | 134 | topLevelWidget()->setCaption( tr("Compose mail") ); |
135 | } | 135 | } |
136 | void ComposeMail::setStatus( QString status ) | 136 | void ComposeMail::setStatus( QString status ) |
137 | { | 137 | { |
138 | topLevelWidget()->setCaption( status ); | 138 | topLevelWidget()->setCaption( status ); |
139 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; | 139 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; |
140 | } | 140 | } |
141 | void ComposeMail::pickAddress( QLineEdit *line ) | 141 | void ComposeMail::pickAddress( QLineEdit *line ) |
@@ -275,89 +275,89 @@ void ComposeMail::accept() | |||
275 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); | 275 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); |
276 | mail->setMail(fromBox->currentText()); | 276 | mail->setMail(fromBox->currentText()); |
277 | 277 | ||
278 | if ( !toLine->text().isEmpty() ) { | 278 | if ( !toLine->text().isEmpty() ) { |
279 | mail->setTo( toLine->text() ); | 279 | mail->setTo( toLine->text() ); |
280 | } else { | 280 | } else { |
281 | QMessageBox::warning(0,tr("Sending mail"), | 281 | QMessageBox::warning(0,tr("Sending mail"), |
282 | tr("No Receiver spezified" ) ); | 282 | tr("No Receiver spezified" ) ); |
283 | return; | 283 | return; |
284 | } | 284 | } |
285 | 285 | ||
286 | mail->setName(senderNameEdit->text()); | 286 | mail->setName(senderNameEdit->text()); |
287 | mail->setCC( ccLine->text() ); | 287 | mail->setCC( ccLine->text() ); |
288 | mail->setBCC( bccLine->text() ); | 288 | mail->setBCC( bccLine->text() ); |
289 | mail->setReply( replyLine->text() ); | 289 | mail->setReply( replyLine->text() ); |
290 | mail->setSubject( subjectLine->text() ); | 290 | mail->setSubject( subjectLine->text() ); |
291 | if (!m_replyid.isEmpty()) { | 291 | if (!m_replyid.isEmpty()) { |
292 | QStringList ids; | 292 | QStringList ids; |
293 | ids.append(m_replyid); | 293 | ids.append(m_replyid); |
294 | mail->setInreply(ids); | 294 | mail->setInreply(ids); |
295 | } | 295 | } |
296 | QString txt = message->text(); | 296 | QString txt = message->text(); |
297 | if ( !sigMultiLine->text().isEmpty() ) { | 297 | if ( !sigMultiLine->text().isEmpty() ) { |
298 | txt.append( "\n--\n" ); | 298 | txt.append( "\n--\n" ); |
299 | txt.append( sigMultiLine->text() ); | 299 | txt.append( sigMultiLine->text() ); |
300 | } | 300 | } |
301 | mail->setMessage( txt ); | 301 | mail->setMessage( txt ); |
302 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 302 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
303 | while ( it != 0 ) { | 303 | while ( it != 0 ) { |
304 | mail->addAttachment( it->getAttachment() ); | 304 | mail->addAttachment( it->getAttachment() ); |
305 | it = (AttachViewItem *) it->nextSibling(); | 305 | it = (AttachViewItem *) it->nextSibling(); |
306 | } | 306 | } |
307 | 307 | ||
308 | SMTPwrapper wrapper( smtp ); | 308 | SMTPwrapper wrapper( smtp ); |
309 | if ( wrapper.sendMail( mail,checkBoxLater->isChecked() ) ) | 309 | if ( wrapper.sendMail( mail,checkBoxLater->isChecked() ) ) |
310 | setStatus( tr ("Mail sent")); | 310 | setStatus( tr ("Mail sent")); |
311 | else { | 311 | else { |
312 | setStatus( tr ("Error: Something went wrong. Nothing sent")); | 312 | setStatus( tr ("Error: Something went wrong. Nothing sent")); |
313 | return; | 313 | return; |
314 | } | 314 | } |
315 | 315 | ||
316 | 316 | ||
317 | QDialog::accept(); | 317 | QDialog::accept(); |
318 | } | 318 | } |
319 | 319 | ||
320 | void ComposeMail::reject() | 320 | void ComposeMail::reject() |
321 | { | 321 | { |
322 | //qDebug("ComposeMail::reject() "); | 322 | //qDebug("ComposeMail::reject() "); |
323 | int yesno = QMessageBox::warning(0,tr("Stop editing message"), | 323 | int yesno = QMessageBox::warning(0,tr("Store message?"), |
324 | tr("Store message into drafts?"), | 324 | tr("Store message into drafts?\n"), |
325 | tr("Yes"), | 325 | tr("Yes"), |
326 | tr("No")); | 326 | tr("No")); |
327 | 327 | ||
328 | //qDebug("button %d ", yesno); | 328 | //qDebug("button %d ", yesno); |
329 | if (yesno == 0) { | 329 | if (yesno == 0) { |
330 | saveAsDraft(); | 330 | saveAsDraft(); |
331 | } | 331 | } |
332 | if (yesno == 2) { | 332 | if (yesno == 2) { |
333 | qDebug("return "); | 333 | qDebug("return "); |
334 | return; | 334 | return; |
335 | } | 335 | } |
336 | QDialog::reject(); | 336 | QDialog::reject(); |
337 | } | 337 | } |
338 | 338 | ||
339 | ComposeMail::~ComposeMail() | 339 | ComposeMail::~ComposeMail() |
340 | { | 340 | { |
341 | } | 341 | } |
342 | 342 | ||
343 | void ComposeMail::reEditMail(const RecMailP¤t) | 343 | void ComposeMail::reEditMail(const RecMailP¤t) |
344 | { | 344 | { |
345 | RecMailP data = current; | 345 | RecMailP data = current; |
346 | message->setText(data->Wrapper()->fetchBody(current)->Bodytext()); | 346 | message->setText(data->Wrapper()->fetchBody(current)->Bodytext()); |
347 | subjectLine->setText( data->getSubject()); | 347 | subjectLine->setText( data->getSubject()); |
348 | toLine->setText(data->To().join(",")); | 348 | toLine->setText(data->To().join(",")); |
349 | ccLine->setText(data->CC().join(",")); | 349 | ccLine->setText(data->CC().join(",")); |
350 | bccLine->setText(data->Bcc().join(",")); | 350 | bccLine->setText(data->Bcc().join(",")); |
351 | replyLine->setText(data->Replyto()); | 351 | replyLine->setText(data->Replyto()); |
352 | } | 352 | } |
353 | 353 | ||
354 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) | 354 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) |
355 | : QListViewItem( parent ) | 355 | : QListViewItem( parent ) |
356 | { | 356 | { |
357 | attachment = att; | 357 | attachment = att; |
358 | if ( !attachment->getPixmap().isNull() ) | 358 | if ( !attachment->getPixmap().isNull() ) |
359 | setPixmap( 0,attachment->getPixmap() ); | 359 | setPixmap( 0,attachment->getPixmap() ); |
360 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); | 360 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); |
361 | setText( 1, QString::number( att->getSize() ) ); | 361 | setText( 1, QString::number( att->getSize() ) ); |
362 | } | 362 | } |
363 | 363 | ||