summaryrefslogtreecommitdiff
authoralwin <alwin>2005-03-09 14:59:26 (UTC)
committer alwin <alwin>2005-03-09 14:59:26 (UTC)
commit8e618d7a6d195cb737946e89370d5c60f92e8f86 (patch) (unidiff)
treea4cfada2c0420fb40c483ace4dc2a6fce4258d6a
parent84f237fb3b83400a031bf7c2d3025f78c02f28a8 (diff)
downloadopie-8e618d7a6d195cb737946e89370d5c60f92e8f86.zip
opie-8e618d7a6d195cb737946e89370d5c60f92e8f86.tar.gz
opie-8e618d7a6d195cb737946e89370d5c60f92e8f86.tar.bz2
small bugfix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/viewmail.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index 5206220..a89393c 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -103,327 +103,329 @@ void ViewMail::setBody(const RecBodyP&body )
103 int w; 103 int w;
104 w=0; 104 w=0;
105 105
106 while (s>1024) 106 while (s>1024)
107 { 107 {
108 s/=1024; 108 s/=1024;
109 ++w; 109 ++w;
110 if (w>=2) break; 110 if (w>=2) break;
111 } 111 }
112 112
113 QString q=""; 113 QString q="";
114 switch(w) 114 switch(w)
115 { 115 {
116 case 1: 116 case 1:
117 q="k"; 117 q="k";
118 break; 118 break;
119 case 2: 119 case 2:
120 q="M"; 120 q="M";
121 break; 121 break;
122 default: 122 default:
123 break; 123 break;
124 } 124 }
125 125
126 { 126 {
127 /* I did not found a method to make a CONTENT reset on a QTextStream 127 /* I did not found a method to make a CONTENT reset on a QTextStream
128 so I use this construct that the stream will re-constructed in each 128 so I use this construct that the stream will re-constructed in each
129 loop. To let it work, the textstream is packed into a own area of 129 loop. To let it work, the textstream is packed into a own area of
130 code is it will be destructed after finishing its small job. 130 code is it will be destructed after finishing its small job.
131 */ 131 */
132 QTextOStream o(&fsize); 132 QTextOStream o(&fsize);
133 if (w>0) o.precision(2); else o.precision(0); 133 if (w>0) o.precision(2); else o.precision(0);
134 o.setf(QTextStream::fixed); 134 o.setf(QTextStream::fixed);
135 o << s << " " << q << "Byte"; 135 o << s << " " << q << "Byte";
136 } 136 }
137 137
138 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); 138 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist());
139 QString filename = ""; 139 QString filename = "";
140 140
141 for (unsigned int i = 0; i < body->Parts().count();++i) 141 for (unsigned int i = 0; i < body->Parts().count();++i)
142 { 142 {
143 filename = ""; 143 filename = "";
144 type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); 144 type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype();
145 part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); 145 part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin();
146 for (;it!=body->Parts()[i]->Parameters().end();++it) 146 for (;it!=body->Parts()[i]->Parameters().end();++it)
147 { 147 {
148 odebug << it.key() << oendl; 148 odebug << it.key() << oendl;
149 if (it.key().lower()=="name") 149 if (it.key().lower()=="name")
150 { 150 {
151 filename=it.data(); 151 filename=it.data();
152 } 152 }
153 } 153 }
154 s = body->Parts()[i]->Size(); 154 s = body->Parts()[i]->Size();
155 w = 0; 155 w = 0;
156 while (s>1024) 156 while (s>1024)
157 { 157 {
158 s/=1024; 158 s/=1024;
159 ++w; 159 ++w;
160 if (w>=2) break; 160 if (w>=2) break;
161 } 161 }
162 switch(w) 162 switch(w)
163 { 163 {
164 case 1: 164 case 1:
165 q="k"; 165 q="k";
166 break; 166 break;
167 case 2: 167 case 2:
168 q="M"; 168 q="M";
169 break; 169 break;
170 default: 170 default:
171 q=""; 171 q="";
172 break; 172 break;
173 } 173 }
174 QTextOStream o(&fsize); 174 QTextOStream o(&fsize);
175 if (w>0) o.precision(2); else o.precision(0); 175 if (w>0) o.precision(2); else o.precision(0);
176 o.setf(QTextStream::fixed); 176 o.setf(QTextStream::fixed);
177 o << s << " " << q << "Byte"; 177 o << s << " " << q << "Byte";
178 desc = body->Parts()[i]->Description(); 178 desc = body->Parts()[i]->Description();
179 parentItem = searchParent(body->Parts()[i]->Positionlist()); 179 parentItem = searchParent(body->Parts()[i]->Positionlist());
180 if (parentItem) 180 if (parentItem)
181 { 181 {
182 AttachItem*temp = lastChild(parentItem); 182 AttachItem*temp = lastChild(parentItem);
183 if (temp) curItem = temp; 183 if (temp) curItem = temp;
184 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); 184 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist());
185 attachments->setRootIsDecorated(true); 185 attachments->setRootIsDecorated(true);
186 curItem = parentItem; 186 curItem = parentItem;
187 } 187 }
188 else 188 else
189 { 189 {
190 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); 190 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist());
191 } 191 }
192 } 192 }
193} 193}
194 194
195 195
196void ViewMail::slotShowHtml( bool state ) 196void ViewMail::slotShowHtml( bool state )
197{ 197{
198 m_showHtml = state; 198 m_showHtml = state;
199 m_lasttextpart=-2;
199 setMainText(); 200 setMainText();
200} 201}
201 202
202void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) 203void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int )
203{ 204{
204 if (!item ) 205 if (!item )
205 return; 206 return;
206 207
207 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 208 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
208 { 209 {
209 setMainText(); 210 setMainText();
210 return; 211 return;
211 } 212 }
212 QPopupMenu *menu = new QPopupMenu(); 213 QPopupMenu *menu = new QPopupMenu();
213 int ret=0; 214 int ret=0;
214 215
215 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) 216 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" )
216 { 217 {
217 menu->insertItem( tr( "Show Text" ), 1 ); 218 menu->insertItem( tr( "Show Text" ), 1 );
218 } 219 }
219 if (item->text(0).left(6)=="image/") { 220 if (item->text(0).left(6)=="image/") {
220 menu->insertItem(tr("Display image preview"),2); 221 menu->insertItem(tr("Display image preview"),2);
221 } 222 }
222 menu->insertItem( tr( "Save Attachment" ), 0 ); 223 menu->insertItem( tr( "Save Attachment" ), 0 );
223 menu->insertSeparator(1); 224 menu->insertSeparator(1);
224 225
225 ret = menu->exec( point, 0 ); 226 ret = menu->exec( point, 0 );
226 227
227 switch(ret) 228 switch(ret)
228 { 229 {
229 case 0: 230 case 0:
230 { 231 {
231 MimeTypes types; 232 MimeTypes types;
232 types.insert( "all", "*" ); 233 types.insert( "all", "*" );
233 QString str = OFileDialog::getSaveFileName( 1, 234 QString str = OFileDialog::getSaveFileName( 1,
234 "/", item->text( 2 ) , types, 0 ); 235 "/", item->text( 2 ) , types, 0 );
235 236
236 if( !str.isEmpty() ) 237 if( !str.isEmpty() )
237 { 238 {
238 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 239 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
239 if (content) 240 if (content)
240 { 241 {
241 QFile output(str); 242 QFile output(str);
242 output.open(IO_WriteOnly); 243 output.open(IO_WriteOnly);
243 output.writeBlock(content->Content(),content->Length()); 244 output.writeBlock(content->Content(),content->Length());
244 output.close(); 245 output.close();
245 delete content; 246 delete content;
246 } 247 }
247 } 248 }
248 } 249 }
249 break ; 250 break ;
250 251
251 case 2: 252 case 2:
252 { 253 {
253 if (m_lastimagepart== (( AttachItem* )item )->Partnumber()) { 254 if (m_lastimagepart== (( AttachItem* )item )->Partnumber()) {
254 if (m_lastdlg) { 255 if (m_lastdlg) {
255 setUpdatesEnabled(false); 256 setUpdatesEnabled(false);
256 browser->hide(); 257 browser->hide();
257 m_lastdlg->show(); 258 m_lastdlg->show();
258 setUpdatesEnabled(true); 259 setUpdatesEnabled(true);
259 return; 260 return;
260 } 261 }
261 } 262 }
262 QString tmpfile = QString("/tmp/opiemail-image-%1").arg(_icounter++); 263 QString tmpfile = QString("/tmp/opiemail-image-%1").arg(_icounter++);
263 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 264 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
264 if (content && content->Length()) { 265 if (content && content->Length()) {
265 QFile output(tmpfile); 266 QFile output(tmpfile);
266 output.open(IO_WriteOnly); 267 output.open(IO_WriteOnly);
267 output.writeBlock(content->Content(),content->Length()); 268 output.writeBlock(content->Content(),content->Length());
268 output.close(); 269 output.close();
269 delete content; 270 delete content;
270 if (!m_PicsInline) { 271 if (!m_PicsInline) {
271 MailImageDlg iview(""); 272 MailImageDlg iview("");
272 iview.setName(tmpfile); 273 iview.setName(tmpfile);
273 QPEApplication::execDialog(&iview); 274 QPEApplication::execDialog(&iview);
274 } else { 275 } else {
275 if (!m_lastdlg) { 276 if (!m_lastdlg) {
276 m_lastdlg=new Opie::MM::OImageScrollView("",browser->parentWidget(),false); 277 m_lastdlg=new Opie::MM::OImageScrollView("",browser->parentWidget(),false);
277 m_lastdlg->setAutoScale(true); 278 m_lastdlg->setAutoScale(true);
278 } 279 }
279 //m_lastdlg->setImage(""); 280 //m_lastdlg->setImage("");
280 m_lastdlg->setImage(tmpfile); 281 m_lastdlg->setImage(tmpfile);
281 browser->hide(); 282 browser->hide();
282 m_lastdlg->show(); 283 m_lastdlg->show();
283 } 284 }
284 output.remove(); 285 output.remove();
285 } else { 286 } else {
286 QMessageBox::critical(this, tr("Reading attachment"), tr("Could not read content of attachment")); 287 QMessageBox::critical(this, tr("Reading attachment"), tr("Could not read content of attachment"));
287 } 288 }
288 m_lastimagepart=(( AttachItem* )item )->Partnumber(); 289 m_lastimagepart=(( AttachItem* )item )->Partnumber();
289 } 290 }
290 break; 291 break;
291 case 1: 292 case 1:
292 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 293 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
293 { 294 {
294 setMainText(); 295 setMainText();
295 } 296 }
296 else 297 else
297 { 298 {
298 if ( m_recMail->Wrapper() != 0l ) 299 if ( m_recMail->Wrapper() != 0l )
299 { // make sure that there is a wrapper , even after delete or simular actions 300 { // make sure that there is a wrapper , even after delete or simular actions
300 if (m_lastdlg) { 301 if (m_lastdlg) {
301 m_lastdlg->hide(); 302 m_lastdlg->hide();
302 browser->show(); 303 browser->show();
303 } 304 }
304 if (m_lasttextpart == ( ( AttachItem* )item )->Partnumber() ) return; 305 if (m_lasttextpart == ( ( AttachItem* )item )->Partnumber() ) return;
305 m_lasttextpart = ( ( AttachItem* )item )->Partnumber(); 306 m_lasttextpart = ( ( AttachItem* )item )->Partnumber();
306 QString s = m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );; 307 QString s = m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );;
307 if (item->text(0).right(4)!="html") { 308 if (item->text(0).right(4)!="html") {
308 s = QString("<html><body>\n<font face=fixed>%1</font></body></html>").arg(QStyleSheet::convertFromPlainText(s)); 309 s = QString("<html><body>\n<font face=fixed>%1</font></body></html>").arg(QStyleSheet::convertFromPlainText(s));
309 } 310 }
310 browser->setText(s); 311 browser->setText(s);
311 } 312 }
312 } 313 }
313 break; 314 break;
314 } 315 }
315 delete menu; 316 delete menu;
316} 317}
317 318
318 319
319void ViewMail::setMail(const RecMailP&mail ) 320void ViewMail::setMail(const RecMailP&mail )
320{ 321{
321 322
322 m_recMail = mail; 323 m_recMail = mail;
323 324
324 m_mail[0] = mail->getFrom(); 325 m_mail[0] = mail->getFrom();
325 m_mail[1] = mail->getSubject(); 326 m_mail[1] = mail->getSubject();
326 m_mail[3] = mail->getStringDate(); 327 m_mail[3] = mail->getStringDate();
327 m_mail[4] = mail->Msgid(); 328 m_mail[4] = mail->Msgid();
328 329
329 m_mail2[0] = mail->To(); 330 m_mail2[0] = mail->To();
330 m_mail2[1] = mail->CC(); 331 m_mail2[1] = mail->CC();
331 m_mail2[2] = mail->Bcc(); 332 m_mail2[2] = mail->Bcc();
332 333
333 setCaption(tr("E-Mail by %1").arg( m_mail[0] ) ); 334 setCaption(tr("E-Mail by %1").arg( m_mail[0] ) );
335 m_lasttextpart=-2;
334 setMainText(); 336 setMainText();
335} 337}
336 338
337 339
338 340
339ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) 341ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
340 : ViewMailBase(parent, name, fl), _inLoop(false) 342 : ViewMailBase(parent, name, fl), _inLoop(false)
341{ 343{
342 m_gotBody = false; 344 m_gotBody = false;
343 deleted = false; 345 deleted = false;
344 346
345 connect( reply, SIGNAL(activated()), SLOT(slotReply())); 347 connect( reply, SIGNAL(activated()), SLOT(slotReply()));
346 connect( forward, SIGNAL(activated()), SLOT(slotForward())); 348 connect( forward, SIGNAL(activated()), SLOT(slotForward()));
347 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); 349 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) );
348 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); 350 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) );
349 connect( showPicsInline, SIGNAL( toggled(bool) ), SLOT( slotImageInline(bool) ) ); 351 connect( showPicsInline, SIGNAL( toggled(bool) ), SLOT( slotImageInline(bool) ) );
350 352
351 attachments->setEnabled(m_gotBody); 353 attachments->setEnabled(m_gotBody);
352 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); 354 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) );
353 m_lastdlg = 0; 355 m_lastdlg = 0;
354 _icounter = 0; 356 _icounter = 0;
355 m_lastimagepart = -1; 357 m_lastimagepart = -1;
356 m_lasttextpart = -2; 358 m_lasttextpart = -2;
357 359
358 readConfig(); 360 readConfig();
359 attachments->setSorting(-1); 361 attachments->setSorting(-1);
360} 362}
361 363
362void ViewMail::slotImageInline(bool how) 364void ViewMail::slotImageInline(bool how)
363{ 365{
364 Config cfg( "mail" ); 366 Config cfg( "mail" );
365 cfg.writeEntry( "showPicsInline", how); 367 cfg.writeEntry( "showPicsInline", how);
366 m_PicsInline = how; 368 m_PicsInline = how;
367 if (m_lastdlg&&!how) { 369 if (m_lastdlg&&!how) {
368 browser->show(); 370 browser->show();
369 m_lastdlg->hide(); 371 m_lastdlg->hide();
370 m_lastdlg->reparent(0,QPoint(0,0),false); 372 m_lastdlg->reparent(0,QPoint(0,0),false);
371 delete m_lastdlg; 373 delete m_lastdlg;
372 m_lastdlg = 0; 374 m_lastdlg = 0;
373 m_lastimagepart = -1; 375 m_lastimagepart = -1;
374 } 376 }
375} 377}
376 378
377void ViewMail::readConfig() 379void ViewMail::readConfig()
378{ 380{
379 Config cfg( "mail" ); 381 Config cfg( "mail" );
380 cfg.setGroup( "Settings" ); 382 cfg.setGroup( "Settings" );
381 m_showHtml = cfg.readBoolEntry( "showHtml", false ); 383 m_showHtml = cfg.readBoolEntry( "showHtml", false );
382 m_PicsInline = cfg.readBoolEntry( "showPicsInline", true ); 384 m_PicsInline = cfg.readBoolEntry( "showPicsInline", true );
383 showPicsInline->setOn(m_PicsInline); 385 showPicsInline->setOn(m_PicsInline);
384 showHtml->setOn( m_showHtml ); 386 showHtml->setOn( m_showHtml );
385} 387}
386 388
387void ViewMail::setMainText() 389void ViewMail::setMainText()
388{ 390{
389 QString toString; 391 QString toString;
390 QString ccString; 392 QString ccString;
391 QString bccString; 393 QString bccString;
392 QString mailHtml; 394 QString mailHtml;
393 395
394 if (m_lastdlg) { 396 if (m_lastdlg) {
395 m_lastdlg->hide(); 397 m_lastdlg->hide();
396 } 398 }
397 browser->show(); 399 browser->show();
398 if (m_lasttextpart == -1) return; 400 if (m_lasttextpart == -1) return;
399 m_lasttextpart = -1; 401 m_lasttextpart = -1;
400 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) 402 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it )
401 { 403 {
402 toString += (*it); 404 toString += (*it);
403 } 405 }
404 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) 406 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it )
405 { 407 {
406 ccString += (*it); 408 ccString += (*it);
407 } 409 }
408 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) 410 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it )
409 { 411 {
410 bccString += (*it); 412 bccString += (*it);
411 } 413 }
412 browser->setTextFormat(Qt::RichText); 414 browser->setTextFormat(Qt::RichText);
413 mailHtml = "<html><body>" 415 mailHtml = "<html><body>"
414 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" 416 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>"
415 "<div align=left><b>" + deHtml(m_mail[1]) + "</b></div>" 417 "<div align=left><b>" + deHtml(m_mail[1]) + "</b></div>"
416 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" 418 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>"
417 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" 419 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>"
418 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + 420 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" +
419 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" 421 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>"
420 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + 422 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] +
421 "</td></tr></table>"; 423 "</td></tr></table>";
422 if ( !m_showHtml ) { 424 if ( !m_showHtml ) {
423 browser->setText( mailHtml+"<font face=fixed>" + QStyleSheet::convertFromPlainText(m_mail[2]) + "</font></body></html>" ); 425 browser->setText( mailHtml+"<font face=fixed>" + QStyleSheet::convertFromPlainText(m_mail[2]) + "</font></body></html>" );
424 } else { 426 } else {
425 browser->setText(mailHtml+m_mail[2].simplifyWhiteSpace()+"</html>"); 427 browser->setText(mailHtml+m_mail[2].simplifyWhiteSpace()+"</html>");
426 } 428 }
427 // remove later in favor of a real handling 429 // remove later in favor of a real handling
428 m_gotBody = true; 430 m_gotBody = true;
429} 431}