-rw-r--r-- | noncore/net/mail/composemail.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp index b9c9cbc..445cc5e 100644 --- a/noncore/net/mail/composemail.cpp +++ b/noncore/net/mail/composemail.cpp | |||
@@ -1,301 +1,300 @@ | |||
1 | #include <qt.h> | 1 | #include <qt.h> |
2 | 2 | ||
3 | #include <opie2/ofiledialog.h> | 3 | #include <opie2/ofiledialog.h> |
4 | #include <qpe/resource.h> | 4 | #include <qpe/resource.h> |
5 | #include <qpe/config.h> | 5 | #include <qpe/config.h> |
6 | #include <qpe/global.h> | 6 | #include <qpe/global.h> |
7 | #include <qpe/contact.h> | 7 | #include <qpe/contact.h> |
8 | 8 | ||
9 | #include "composemail.h" | 9 | #include "composemail.h" |
10 | 10 | ||
11 | #include <libmailwrapper/smtpwrapper.h> | 11 | #include <libmailwrapper/smtpwrapper.h> |
12 | #include <libmailwrapper/storemail.h> | 12 | #include <libmailwrapper/storemail.h> |
13 | #include <libmailwrapper/abstractmail.h> | 13 | #include <libmailwrapper/abstractmail.h> |
14 | #include <libmailwrapper/mailtypes.h> | 14 | #include <libmailwrapper/mailtypes.h> |
15 | 15 | ||
16 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 16 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
17 | : ComposeMailUI( parent, name, modal, flags ) | 17 | : ComposeMailUI( parent, name, modal, flags ) |
18 | { | 18 | { |
19 | settings = s; | 19 | settings = s; |
20 | m_replyid = ""; | 20 | m_replyid = ""; |
21 | 21 | ||
22 | QString vfilename = Global::applicationFileName("addressbook", | 22 | QString vfilename = Global::applicationFileName("addressbook", |
23 | "businesscard.vcf"); | 23 | "businesscard.vcf"); |
24 | Contact c; | 24 | Contact c; |
25 | if (QFile::exists(vfilename)) { | 25 | if (QFile::exists(vfilename)) { |
26 | c = Contact::readVCard( vfilename )[0]; | 26 | c = Contact::readVCard( vfilename )[0]; |
27 | } | 27 | } |
28 | 28 | ||
29 | QStringList mails = c.emailList(); | 29 | QStringList mails = c.emailList(); |
30 | QString defmail = c.defaultEmail(); | 30 | QString defmail = c.defaultEmail(); |
31 | 31 | ||
32 | if (defmail.length()!=0) { | 32 | if (defmail.length()!=0) { |
33 | fromBox->insertItem(defmail); | 33 | fromBox->insertItem(defmail); |
34 | } | 34 | } |
35 | QStringList::ConstIterator sit = mails.begin(); | 35 | QStringList::ConstIterator sit = mails.begin(); |
36 | for (;sit!=mails.end();++sit) { | 36 | for (;sit!=mails.end();++sit) { |
37 | if ( (*sit)==defmail) | 37 | if ( (*sit)==defmail) |
38 | continue; | 38 | continue; |
39 | fromBox->insertItem((*sit)); | 39 | fromBox->insertItem((*sit)); |
40 | } | 40 | } |
41 | senderNameEdit->setText(c.firstName()+" "+c.lastName()); | 41 | senderNameEdit->setText(c.firstName()+" "+c.lastName()); |
42 | Config cfg( "mail" ); | 42 | Config cfg( "mail" ); |
43 | cfg.setGroup( "Compose" ); | 43 | cfg.setGroup( "Compose" ); |
44 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 44 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); |
45 | 45 | ||
46 | attList->addColumn( tr( "Name" ) ); | 46 | attList->addColumn( tr( "Name" ) ); |
47 | attList->addColumn( tr( "Size" ) ); | 47 | attList->addColumn( tr( "Size" ) ); |
48 | 48 | ||
49 | QList<Account> accounts = settings->getAccounts(); | 49 | QList<Account> accounts = settings->getAccounts(); |
50 | 50 | ||
51 | Account *it; | 51 | Account *it; |
52 | for ( it = accounts.first(); it; it = accounts.next() ) { | 52 | for ( it = accounts.first(); it; it = accounts.next() ) { |
53 | if ( it->getType()==MAILLIB::A_SMTP ) { | 53 | if ( it->getType()==MAILLIB::A_SMTP ) { |
54 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | 54 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); |
55 | smtpAccountBox->insertItem( smtp->getAccountName() ); | 55 | smtpAccountBox->insertItem( smtp->getAccountName() ); |
56 | smtpAccounts.append( smtp ); | 56 | smtpAccounts.append( smtp ); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | if ( smtpAccounts.count() > 0 ) { | 60 | if ( smtpAccounts.count() > 0 ) { |
61 | fillValues( smtpAccountBox->currentItem() ); | 61 | fillValues( smtpAccountBox->currentItem() ); |
62 | } else { | 62 | } else { |
63 | QMessageBox::information( this, tr( "Problem" ), | 63 | QMessageBox::information( this, tr( "Problem" ), |
64 | tr( "<p>Please create an SMTP account first.</p>" ), | 64 | tr( "<p>Please create an SMTP account first.</p>" ), |
65 | tr( "Ok" ) ); | 65 | tr( "Ok" ) ); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | 68 | ||
69 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); | 69 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); |
70 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | 70 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); |
71 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | 71 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); |
72 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 72 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
73 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 73 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
74 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 74 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
75 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 75 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
76 | } | 76 | } |
77 | 77 | ||
78 | void ComposeMail::pickAddress( QLineEdit *line ) | 78 | void ComposeMail::pickAddress( QLineEdit *line ) |
79 | { | 79 | { |
80 | QString names = AddressPicker::getNames(); | 80 | QString names = AddressPicker::getNames(); |
81 | if ( line->text().isEmpty() ) { | 81 | if ( line->text().isEmpty() ) { |
82 | line->setText( names ); | 82 | line->setText( names ); |
83 | } else if ( !names.isEmpty() ) { | 83 | } else if ( !names.isEmpty() ) { |
84 | line->setText( line->text() + ", " + names ); | 84 | line->setText( line->text() + ", " + names ); |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
89 | void ComposeMail::setTo( const QString & to ) | 89 | void ComposeMail::setTo( const QString & to ) |
90 | { | 90 | { |
91 | toLine->setText( to ); | 91 | toLine->setText( to ); |
92 | } | 92 | } |
93 | 93 | ||
94 | void ComposeMail::setSubject( const QString & subject ) | 94 | void ComposeMail::setSubject( const QString & subject ) |
95 | { | 95 | { |
96 | subjectLine->setText( subject ); | 96 | subjectLine->setText( subject ); |
97 | } | 97 | } |
98 | 98 | ||
99 | void ComposeMail::setInReplyTo( const QString & messageId ) | 99 | void ComposeMail::setInReplyTo( const QString & messageId ) |
100 | { | 100 | { |
101 | m_replyid = messageId; | 101 | m_replyid = messageId; |
102 | } | 102 | } |
103 | 103 | ||
104 | void ComposeMail::setMessage( const QString & text ) | 104 | void ComposeMail::setMessage( const QString & text ) |
105 | { | 105 | { |
106 | message->setText( text ); | 106 | message->setText( text ); |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | void ComposeMail::pickAddressTo() | 110 | void ComposeMail::pickAddressTo() |
111 | { | 111 | { |
112 | pickAddress( toLine ); | 112 | pickAddress( toLine ); |
113 | } | 113 | } |
114 | 114 | ||
115 | void ComposeMail::pickAddressCC() | 115 | void ComposeMail::pickAddressCC() |
116 | { | 116 | { |
117 | pickAddress( ccLine ); | 117 | pickAddress( ccLine ); |
118 | } | 118 | } |
119 | 119 | ||
120 | void ComposeMail::pickAddressBCC() | 120 | void ComposeMail::pickAddressBCC() |
121 | { | 121 | { |
122 | pickAddress( bccLine ); | 122 | pickAddress( bccLine ); |
123 | } | 123 | } |
124 | 124 | ||
125 | void ComposeMail::pickAddressReply() | 125 | void ComposeMail::pickAddressReply() |
126 | { | 126 | { |
127 | pickAddress( replyLine ); | 127 | pickAddress( replyLine ); |
128 | } | 128 | } |
129 | 129 | ||
130 | void ComposeMail::fillValues( int ) | 130 | void ComposeMail::fillValues( int ) |
131 | { | 131 | { |
132 | #if 0 | 132 | #if 0 |
133 | SMTPaccount *smtp = smtpAccounts.at( current ); | 133 | SMTPaccount *smtp = smtpAccounts.at( current ); |
134 | ccLine->clear(); | 134 | ccLine->clear(); |
135 | if ( smtp->getUseCC() ) { | 135 | if ( smtp->getUseCC() ) { |
136 | ccLine->setText( smtp->getCC() ); | 136 | ccLine->setText( smtp->getCC() ); |
137 | } | 137 | } |
138 | bccLine->clear(); | 138 | bccLine->clear(); |
139 | if ( smtp->getUseBCC() ) { | 139 | if ( smtp->getUseBCC() ) { |
140 | bccLine->setText( smtp->getBCC() ); | 140 | bccLine->setText( smtp->getBCC() ); |
141 | } | 141 | } |
142 | replyLine->clear(); | 142 | replyLine->clear(); |
143 | if ( smtp->getUseReply() ) { | 143 | if ( smtp->getUseReply() ) { |
144 | replyLine->setText( smtp->getReply() ); | 144 | replyLine->setText( smtp->getReply() ); |
145 | } | 145 | } |
146 | sigMultiLine->setText( smtp->getSignature() ); | 146 | sigMultiLine->setText( smtp->getSignature() ); |
147 | #endif | 147 | #endif |
148 | } | 148 | } |
149 | 149 | ||
150 | void ComposeMail::slotAdjustColumns() | 150 | void ComposeMail::slotAdjustColumns() |
151 | { | 151 | { |
152 | int currPage = tabWidget->currentPageIndex(); | 152 | int currPage = tabWidget->currentPageIndex(); |
153 | 153 | ||
154 | tabWidget->showPage( attachTab ); | 154 | tabWidget->showPage( attachTab ); |
155 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); | 155 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); |
156 | attList->setColumnWidth( 1, 80 ); | 156 | attList->setColumnWidth( 1, 80 ); |
157 | 157 | ||
158 | tabWidget->setCurrentPage( currPage ); | 158 | tabWidget->setCurrentPage( currPage ); |
159 | } | 159 | } |
160 | 160 | ||
161 | void ComposeMail::addAttachment() | 161 | void ComposeMail::addAttachment() |
162 | { | 162 | { |
163 | DocLnk lnk = Opie::OFileDialog::getOpenFileName( 1, "/" ); | 163 | DocLnk lnk = Opie::OFileDialog::getOpenFileName( 1, "/" ); |
164 | if ( !lnk.name().isEmpty() ) { | 164 | if ( !lnk.name().isEmpty() ) { |
165 | Attachment *att = new Attachment( lnk ); | 165 | Attachment *att = new Attachment( lnk ); |
166 | (void) new AttachViewItem( attList, att ); | 166 | (void) new AttachViewItem( attList, att ); |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | void ComposeMail::removeAttachment() | 170 | void ComposeMail::removeAttachment() |
171 | { | 171 | { |
172 | if ( !attList->currentItem() ) { | 172 | if ( !attList->currentItem() ) { |
173 | QMessageBox::information( this, tr( "Error" ), | 173 | QMessageBox::information( this, tr( "Error" ), |
174 | tr( "<p>Please select a File.</p>" ), | 174 | tr( "<p>Please select a File.</p>" ), |
175 | tr( "Ok" ) ); | 175 | tr( "Ok" ) ); |
176 | } else { | 176 | } else { |
177 | attList->takeItem( attList->currentItem() ); | 177 | attList->takeItem( attList->currentItem() ); |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | void ComposeMail::accept() | 181 | void ComposeMail::accept() |
182 | { | 182 | { |
183 | if ( checkBoxLater->isChecked() ) { | 183 | if ( checkBoxLater->isChecked() ) { |
184 | qDebug( "Send later" ); | 184 | qDebug( "Send later" ); |
185 | } | 185 | } |
186 | 186 | ||
187 | #if 0 | 187 | #if 0 |
188 | qDebug( "Sending Mail with " + | 188 | qDebug( "Sending Mail with " + |
189 | smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() ); | 189 | smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() ); |
190 | #endif | 190 | #endif |
191 | Mail mail; | 191 | Opie::osmart_pointer<Mail> mail=new Mail; |
192 | 192 | ||
193 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); | 193 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); |
194 | mail.setMail(fromBox->currentText()); | 194 | mail->setMail(fromBox->currentText()); |
195 | 195 | ||
196 | if ( !toLine->text().isEmpty() ) { | 196 | if ( !toLine->text().isEmpty() ) { |
197 | mail.setTo( toLine->text() ); | 197 | mail->setTo( toLine->text() ); |
198 | } else { | 198 | } else { |
199 | QMessageBox::warning(0,tr("Sending mail"), | 199 | QMessageBox::warning(0,tr("Sending mail"), |
200 | tr("No Receiver spezified" ) ); | 200 | tr("No Receiver spezified" ) ); |
201 | return; | 201 | return; |
202 | } | 202 | } |
203 | mail.setName(senderNameEdit->text()); | 203 | mail->setName(senderNameEdit->text()); |
204 | mail.setCC( ccLine->text() ); | 204 | mail->setCC( ccLine->text() ); |
205 | mail.setBCC( bccLine->text() ); | 205 | mail->setBCC( bccLine->text() ); |
206 | mail.setReply( replyLine->text() ); | 206 | mail->setReply( replyLine->text() ); |
207 | mail.setSubject( subjectLine->text() ); | 207 | mail->setSubject( subjectLine->text() ); |
208 | if (!m_replyid.isEmpty()) { | 208 | if (!m_replyid.isEmpty()) { |
209 | QStringList ids; | 209 | QStringList ids; |
210 | ids.append(m_replyid); | 210 | ids.append(m_replyid); |
211 | mail.setInreply(ids); | 211 | mail->setInreply(ids); |
212 | } | 212 | } |
213 | QString txt = message->text(); | 213 | QString txt = message->text(); |
214 | if ( !sigMultiLine->text().isEmpty() ) { | 214 | if ( !sigMultiLine->text().isEmpty() ) { |
215 | txt.append( "\n--\n" ); | 215 | txt.append( "\n--\n" ); |
216 | txt.append( sigMultiLine->text() ); | 216 | txt.append( sigMultiLine->text() ); |
217 | } | 217 | } |
218 | qDebug(txt); | 218 | mail->setMessage( txt ); |
219 | mail.setMessage( txt ); | ||
220 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 219 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
221 | while ( it != NULL ) { | 220 | while ( it != NULL ) { |
222 | mail.addAttachment( it->getAttachment() ); | 221 | mail->addAttachment( it->getAttachment() ); |
223 | it = (AttachViewItem *) it->nextSibling(); | 222 | it = (AttachViewItem *) it->nextSibling(); |
224 | } | 223 | } |
225 | 224 | ||
226 | SMTPwrapper wrapper( smtp ); | 225 | SMTPwrapper wrapper( smtp ); |
227 | wrapper.sendMail( mail,checkBoxLater->isChecked() ); | 226 | wrapper.sendMail( mail,checkBoxLater->isChecked() ); |
228 | 227 | ||
229 | QDialog::accept(); | 228 | QDialog::accept(); |
230 | } | 229 | } |
231 | 230 | ||
232 | void ComposeMail::reject() | 231 | void ComposeMail::reject() |
233 | { | 232 | { |
234 | int yesno = QMessageBox::warning(0,tr("Store message"), | 233 | int yesno = QMessageBox::warning(0,tr("Store message"), |
235 | tr("Store message into drafts?"), | 234 | tr("Store message into drafts?"), |
236 | tr("Yes"), | 235 | tr("Yes"), |
237 | tr("No"),QString::null,0,1); | 236 | tr("No"),QString::null,0,1); |
238 | 237 | ||
239 | if (yesno == 0) { | 238 | if (yesno == 0) { |
240 | Mail mail; | 239 | Opie::osmart_pointer<Mail> mail=new Mail(); |
241 | mail.setMail(fromBox->currentText()); | 240 | mail->setMail(fromBox->currentText()); |
242 | mail.setTo( toLine->text() ); | 241 | mail->setTo( toLine->text() ); |
243 | mail.setName(senderNameEdit->text()); | 242 | mail->setName(senderNameEdit->text()); |
244 | mail.setCC( ccLine->text() ); | 243 | mail->setCC( ccLine->text() ); |
245 | mail.setBCC( bccLine->text() ); | 244 | mail->setBCC( bccLine->text() ); |
246 | mail.setReply( replyLine->text() ); | 245 | mail->setReply( replyLine->text() ); |
247 | mail.setSubject( subjectLine->text() ); | 246 | mail->setSubject( subjectLine->text() ); |
248 | if (!m_replyid.isEmpty()) { | 247 | if (!m_replyid.isEmpty()) { |
249 | QStringList ids; | 248 | QStringList ids; |
250 | ids.append(m_replyid); | 249 | ids.append(m_replyid); |
251 | mail.setInreply(ids); | 250 | mail->setInreply(ids); |
252 | } | 251 | } |
253 | QString txt = message->text(); | 252 | QString txt = message->text(); |
254 | if ( !sigMultiLine->text().isEmpty() ) { | 253 | if ( !sigMultiLine->text().isEmpty() ) { |
255 | txt.append( "\n--\n" ); | 254 | txt.append( "\n--\n" ); |
256 | txt.append( sigMultiLine->text() ); | 255 | txt.append( sigMultiLine->text() ); |
257 | } | 256 | } |
258 | qDebug(txt); | 257 | qDebug(txt); |
259 | mail.setMessage( txt ); | 258 | mail->setMessage( txt ); |
260 | 259 | ||
261 | /* only use the default drafts folder name! */ | 260 | /* only use the default drafts folder name! */ |
262 | Storemail wrapper(AbstractMail::draftFolder()); | 261 | Storemail wrapper(AbstractMail::draftFolder()); |
263 | wrapper.storeMail(mail); | 262 | wrapper.storeMail(mail); |
264 | 263 | ||
265 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 264 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
266 | /* attachments we will ignore! */ | 265 | /* attachments we will ignore! */ |
267 | if ( it != NULL ) { | 266 | if ( it != NULL ) { |
268 | QMessageBox::warning(0,tr("Store message"), | 267 | QMessageBox::warning(0,tr("Store message"), |
269 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); | 268 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); |
270 | } | 269 | } |
271 | } | 270 | } |
272 | QDialog::reject(); | 271 | QDialog::reject(); |
273 | } | 272 | } |
274 | 273 | ||
275 | ComposeMail::~ComposeMail() | 274 | ComposeMail::~ComposeMail() |
276 | { | 275 | { |
277 | } | 276 | } |
278 | 277 | ||
279 | void ComposeMail::reEditMail(const RecMail¤t) | 278 | void ComposeMail::reEditMail(const RecMail¤t) |
280 | { | 279 | { |
281 | RecMail data = current; | 280 | RecMail data = current; |
282 | message->setText(data.Wrapper()->fetchBody(current).Bodytext()); | 281 | message->setText(data.Wrapper()->fetchBody(current).Bodytext()); |
283 | subjectLine->setText( data.getSubject()); | 282 | subjectLine->setText( data.getSubject()); |
284 | toLine->setText(data.To().join(",")); | 283 | toLine->setText(data.To().join(",")); |
285 | ccLine->setText(data.CC().join(",")); | 284 | ccLine->setText(data.CC().join(",")); |
286 | bccLine->setText(data.Bcc().join(",")); | 285 | bccLine->setText(data.Bcc().join(",")); |
287 | replyLine->setText(data.Replyto()); | 286 | replyLine->setText(data.Replyto()); |
288 | } | 287 | } |
289 | 288 | ||
290 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) | 289 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) |
291 | : QListViewItem( parent ) | 290 | : QListViewItem( parent ) |
292 | { | 291 | { |
293 | attachment = att; | 292 | attachment = att; |
294 | qDebug( att->getMimeType() ); | 293 | qDebug( att->getMimeType() ); |
295 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? | 294 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? |
296 | Resource::loadPixmap( "UnknownDocument-14" ) : | 295 | Resource::loadPixmap( "UnknownDocument-14" ) : |
297 | attachment->getDocLnk().pixmap() ); | 296 | attachment->getDocLnk().pixmap() ); |
298 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); | 297 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); |
299 | setText( 1, QString::number( att->getSize() ) ); | 298 | setText( 1, QString::number( att->getSize() ) ); |
300 | } | 299 | } |
301 | 300 | ||