-rw-r--r-- | kmicromail/viewmail.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/kmicromail/viewmail.cpp b/kmicromail/viewmail.cpp index 726f540..685b4e4 100644 --- a/kmicromail/viewmail.cpp +++ b/kmicromail/viewmail.cpp | |||
@@ -38,128 +38,140 @@ | |||
38 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 38 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
39 | const QString&fsize,int num,const QValueList<int>&path) | 39 | const QString&fsize,int num,const QValueList<int>&path) |
40 | : QListViewItem(parent,after),_partNum(num) | 40 | : QListViewItem(parent,after),_partNum(num) |
41 | { | 41 | { |
42 | _path=path; | 42 | _path=path; |
43 | setText(0, mime); | 43 | setText(0, mime); |
44 | setText(1, desc); | 44 | setText(1, desc); |
45 | setText(2, file); | 45 | setText(2, file); |
46 | setText(3, fsize); | 46 | setText(3, fsize); |
47 | } | 47 | } |
48 | 48 | ||
49 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 49 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
50 | const QString&fsize,int num,const QValueList<int>&path) | 50 | const QString&fsize,int num,const QValueList<int>&path) |
51 | : QListViewItem(parent,after),_partNum(num) | 51 | : QListViewItem(parent,after),_partNum(num) |
52 | { | 52 | { |
53 | _path=path; | 53 | _path=path; |
54 | setText(0, mime); | 54 | setText(0, mime); |
55 | setText(1, desc); | 55 | setText(1, desc); |
56 | setText(2, file); | 56 | setText(2, file); |
57 | setText(3, fsize); | 57 | setText(3, fsize); |
58 | } | 58 | } |
59 | 59 | ||
60 | bool AttachItem::isParentof(const QValueList<int>&path) | 60 | bool AttachItem::isParentof(const QValueList<int>&path) |
61 | { | 61 | { |
62 | /* if not set, then no parent */ | 62 | /* if not set, then no parent */ |
63 | if (path.count()==0||_path.count()==0) return false; | 63 | if (path.count()==0||_path.count()==0) return false; |
64 | /* the parent must have one digit less then a child */ | 64 | /* the parent must have one digit less then a child */ |
65 | if (path.count()!=_path.count()+1) return false; | 65 | if (path.count()!=_path.count()+1) return false; |
66 | for (unsigned int i=0; i < _path.count();++i) | 66 | for (unsigned int i=0; i < _path.count();++i) |
67 | { | 67 | { |
68 | if (_path[i]!=path[i]) return false; | 68 | if (_path[i]!=path[i]) return false; |
69 | } | 69 | } |
70 | return true; | 70 | return true; |
71 | } | 71 | } |
72 | 72 | ||
73 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) | 73 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) |
74 | { | 74 | { |
75 | QListViewItemIterator it( attachments ); | 75 | QListViewItemIterator it( attachments ); |
76 | for ( ; it.current(); ++it ) | 76 | for ( ; it.current(); ++it ) |
77 | { | 77 | { |
78 | AttachItem*ati = (AttachItem*)it.current(); | 78 | AttachItem*ati = (AttachItem*)it.current(); |
79 | if (ati->isParentof(path)) return ati; | 79 | if (ati->isParentof(path)) return ati; |
80 | } | 80 | } |
81 | return 0; | 81 | return 0; |
82 | } | 82 | } |
83 | 83 | ||
84 | AttachItem* ViewMail::lastChild(AttachItem*parent) | 84 | AttachItem* ViewMail::lastChild(AttachItem*parent) |
85 | { | 85 | { |
86 | if (!parent) return 0; | 86 | if (!parent) return 0; |
87 | AttachItem* item = (AttachItem*)parent->firstChild(); | 87 | AttachItem* item = (AttachItem*)parent->firstChild(); |
88 | if (!item) return item; | 88 | if (!item) return item; |
89 | AttachItem*temp=0; | 89 | AttachItem*temp=0; |
90 | while( (temp=(AttachItem*)item->nextSibling())) | 90 | while( (temp=(AttachItem*)item->nextSibling())) |
91 | { | 91 | { |
92 | item = temp; | 92 | item = temp; |
93 | } | 93 | } |
94 | return item; | 94 | return item; |
95 | } | 95 | } |
96 | 96 | ||
97 | void ViewMail::setBody(const RecBodyP&body ) | 97 | void ViewMail::setBody(const RecBodyP&body ) |
98 | { | 98 | { |
99 | 99 | ||
100 | m_body = body; | 100 | m_body = body; |
101 | m_mail[2] = body->Bodytext(); | 101 | m_mail[2] = body->Bodytext(); |
102 | m_showHtml = KOPrefs::instance()->mViewAsHtml; | ||
103 | if ( m_showHtml ) { | ||
104 | if ( m_mail[2].find ("<html>",0,false ) > -1 ) { | ||
105 | qDebug("html mail "); | ||
106 | } else { | ||
107 | qDebug("no html mail "); | ||
108 | m_showHtml = false; | ||
109 | } | ||
110 | } | ||
111 | showHtml->blockSignals( true ); | ||
112 | showHtml->setOn( m_showHtml ); | ||
113 | showHtml->blockSignals( false ); | ||
102 | // qDebug("********text %s ",m_mail[2].latin1() ); | 114 | // qDebug("********text %s ",m_mail[2].latin1() ); |
103 | attachbutton->setEnabled(body->Parts().count()>0); | 115 | attachbutton->setEnabled(body->Parts().count()>0); |
104 | attachments->setEnabled(body->Parts().count()>0); | 116 | attachments->setEnabled(body->Parts().count()>0); |
105 | if (body->Parts().count()==0) | 117 | if (body->Parts().count()==0) |
106 | { | 118 | { |
107 | return; | 119 | return; |
108 | } | 120 | } |
109 | AttachItem * curItem=0; | 121 | AttachItem * curItem=0; |
110 | AttachItem * parentItem = 0; | 122 | AttachItem * parentItem = 0; |
111 | QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); | 123 | QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); |
112 | QString desc,fsize; | 124 | QString desc,fsize; |
113 | double s = body->Description()->Size(); | 125 | double s = body->Description()->Size(); |
114 | int w; | 126 | int w; |
115 | w=0; | 127 | w=0; |
116 | 128 | ||
117 | while (s>1024) | 129 | while (s>1024) |
118 | { | 130 | { |
119 | s/=1024; | 131 | s/=1024; |
120 | ++w; | 132 | ++w; |
121 | if (w>=2) break; | 133 | if (w>=2) break; |
122 | } | 134 | } |
123 | 135 | ||
124 | QString q=""; | 136 | QString q=""; |
125 | switch(w) | 137 | switch(w) |
126 | { | 138 | { |
127 | case 1: | 139 | case 1: |
128 | q="k"; | 140 | q="k"; |
129 | break; | 141 | break; |
130 | case 2: | 142 | case 2: |
131 | q="M"; | 143 | q="M"; |
132 | break; | 144 | break; |
133 | default: | 145 | default: |
134 | break; | 146 | break; |
135 | } | 147 | } |
136 | 148 | ||
137 | { | 149 | { |
138 | /* I did not found a method to make a CONTENT reset on a QTextStream | 150 | /* I did not found a method to make a CONTENT reset on a QTextStream |
139 | so I use this construct that the stream will re-constructed in each | 151 | so I use this construct that the stream will re-constructed in each |
140 | loop. To let it work, the textstream is packed into a own area of | 152 | loop. To let it work, the textstream is packed into a own area of |
141 | code is it will be destructed after finishing its small job. | 153 | code is it will be destructed after finishing its small job. |
142 | */ | 154 | */ |
143 | QTextOStream o(&fsize); | 155 | QTextOStream o(&fsize); |
144 | if (w>0) o.precision(2); else o.precision(0); | 156 | if (w>0) o.precision(2); else o.precision(0); |
145 | o.setf(QTextStream::fixed); | 157 | o.setf(QTextStream::fixed); |
146 | o << s << " " << q << "Byte"; | 158 | o << s << " " << q << "Byte"; |
147 | } | 159 | } |
148 | 160 | ||
149 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); | 161 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); |
150 | QString filename = ""; | 162 | QString filename = ""; |
151 | 163 | ||
152 | for (unsigned int i = 0; i < body->Parts().count();++i) | 164 | for (unsigned int i = 0; i < body->Parts().count();++i) |
153 | { | 165 | { |
154 | filename = ""; | 166 | filename = ""; |
155 | type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); | 167 | type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); |
156 | part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); | 168 | part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); |
157 | for (;it!=body->Parts()[i]->Parameters().end();++it) | 169 | for (;it!=body->Parts()[i]->Parameters().end();++it) |
158 | { | 170 | { |
159 | if (it.key().lower()=="name") | 171 | if (it.key().lower()=="name") |
160 | { | 172 | { |
161 | filename=it.data(); | 173 | filename=it.data(); |
162 | } | 174 | } |
163 | } | 175 | } |
164 | s = body->Parts()[i]->Size(); | 176 | s = body->Parts()[i]->Size(); |
165 | w = 0; | 177 | w = 0; |
@@ -270,149 +282,156 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int | |||
270 | output.writeBlock(content->Content(),content->Length()); | 282 | output.writeBlock(content->Content(),content->Length()); |
271 | output.close(); | 283 | output.close(); |
272 | delete content; | 284 | delete content; |
273 | } | 285 | } |
274 | } | 286 | } |
275 | } | 287 | } |
276 | break ; | 288 | break ; |
277 | 289 | ||
278 | case 2: | 290 | case 2: |
279 | { | 291 | { |
280 | #ifdef DESKTOP_VERSION | 292 | #ifdef DESKTOP_VERSION |
281 | QString tmpfile = locateLocal( "tmp", "opiemail-image"); | 293 | QString tmpfile = locateLocal( "tmp", "opiemail-image"); |
282 | #else | 294 | #else |
283 | QString tmpfile = "/tmp/opiemail-image"; | 295 | QString tmpfile = "/tmp/opiemail-image"; |
284 | #endif | 296 | #endif |
285 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 297 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
286 | if (content) { | 298 | if (content) { |
287 | QFile output(tmpfile); | 299 | QFile output(tmpfile); |
288 | output.open(IO_WriteOnly); | 300 | output.open(IO_WriteOnly); |
289 | output.writeBlock(content->Content(),content->Length()); | 301 | output.writeBlock(content->Content(),content->Length()); |
290 | output.close(); | 302 | output.close(); |
291 | delete content; | 303 | delete content; |
292 | MailImageDlg iview(""); | 304 | MailImageDlg iview(""); |
293 | iview.setName(tmpfile); | 305 | iview.setName(tmpfile); |
294 | KApplication::execDialog(&iview); | 306 | KApplication::execDialog(&iview); |
295 | output.remove(); | 307 | output.remove(); |
296 | } | 308 | } |
297 | } | 309 | } |
298 | break; | 310 | break; |
299 | case 1: | 311 | case 1: |
300 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 312 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
301 | { | 313 | { |
302 | setText(); | 314 | setText(); |
303 | } | 315 | } |
304 | else | 316 | else |
305 | { | 317 | { |
306 | if ( m_recMail->Wrapper() != 0l ) | 318 | if ( m_recMail->Wrapper() != 0l ) |
307 | { // make sure that there is a wrapper , even after delete or simular actions | 319 | { // make sure that there is a wrapper , even after delete or simular actions |
308 | browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); | 320 | browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
309 | } | 321 | } |
310 | } | 322 | } |
311 | break; | 323 | break; |
312 | } | 324 | } |
313 | delete menu; | 325 | delete menu; |
314 | } | 326 | } |
315 | 327 | ||
316 | 328 | ||
317 | void ViewMail::setMail(const RecMailP&mail ) | 329 | void ViewMail::setMail(const RecMailP&mail ) |
318 | { | 330 | { |
319 | 331 | ||
320 | m_recMail = mail; | 332 | m_recMail = mail; |
321 | 333 | ||
322 | m_mail[0] = mail->getFrom(); | 334 | m_mail[0] = mail->getFrom(); |
323 | m_mail[1] = mail->getSubject(); | 335 | m_mail[1] = mail->getSubject(); |
324 | m_mail[3] = mail->getDate(); | 336 | m_mail[3] = mail->getDate(); |
325 | m_mail[4] = mail->Msgid(); | 337 | m_mail[4] = mail->Msgid(); |
326 | 338 | ||
327 | m_mail2[0] = mail->To(); | 339 | m_mail2[0] = mail->To(); |
328 | m_mail2[1] = mail->CC(); | 340 | m_mail2[1] = mail->CC(); |
329 | m_mail2[2] = mail->Bcc(); | 341 | m_mail2[2] = mail->Bcc(); |
330 | 342 | ||
331 | setText(); | 343 | setText(); |
332 | } | 344 | } |
333 | 345 | ||
334 | 346 | void ViewMail::slotNextMail() | |
347 | { | ||
348 | nextMail->blockSignals( true ); | ||
349 | setCaption(i18n("Displaying next mail...please wait!")); | ||
350 | qApp->processEvents(); | ||
351 | emit showNextMail(this); | ||
352 | nextMail->blockSignals( false ); | ||
353 | } | ||
335 | 354 | ||
336 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 355 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
337 | : ViewMailBase(parent, name, fl), _inLoop(false) | 356 | : ViewMailBase(parent, name, fl), _inLoop(false) |
338 | { | 357 | { |
339 | m_gotBody = false; | 358 | m_gotBody = false; |
340 | deleted = false; | 359 | deleted = false; |
341 | sourceOn = false; | 360 | sourceOn = false; |
361 | readConfig(); | ||
342 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); | 362 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); |
343 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); | 363 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); |
344 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); | 364 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); |
345 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); | 365 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); |
346 | connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); | 366 | connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); |
347 | connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) ); | 367 | connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) ); |
348 | connect( viewSource, SIGNAL( activated() ), SLOT( slotViewSource() ) ); | 368 | connect( viewSource, SIGNAL( activated() ), SLOT( slotViewSource() ) ); |
349 | connect( downloadMail, SIGNAL( activated() ), SIGNAL( signalDownloadMail() ) ); | 369 | connect( downloadMail, SIGNAL( activated() ), SIGNAL( signalDownloadMail() ) ); |
350 | 370 | ||
351 | attachments->setEnabled(m_gotBody); | 371 | attachments->setEnabled(m_gotBody); |
352 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); | 372 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); |
353 | 373 | ||
354 | readConfig(); | ||
355 | attachments->setSorting(-1); | 374 | attachments->setSorting(-1); |
356 | } | 375 | } |
357 | 376 | ||
358 | void ViewMail::readConfig() | 377 | void ViewMail::readConfig() |
359 | { | 378 | { |
360 | 379 | ||
361 | setFont ( KOPrefs::instance()->mReadFont ); | 380 | setFont ( KOPrefs::instance()->mReadFont ); |
362 | m_showHtml = KOPrefs::instance()->mViewAsHtml; | 381 | m_showHtml = KOPrefs::instance()->mViewAsHtml; |
363 | showHtml->setOn( m_showHtml ); | 382 | showHtml->setOn( m_showHtml ); |
364 | } | 383 | } |
365 | 384 | ||
366 | void ViewMail::setText() | 385 | void ViewMail::setText() |
367 | { | 386 | { |
368 | 387 | ||
369 | viewSource->setText(i18n("View Source")); | 388 | viewSource->setText(i18n("View Source")); |
370 | sourceOn = false; | 389 | sourceOn = false; |
371 | QString toString; | 390 | QString toString; |
372 | QString ccString; | 391 | QString ccString; |
373 | QString bccString; | 392 | QString bccString; |
374 | 393 | ||
375 | 394 | ||
376 | toString = m_mail2[0].join(","); | 395 | toString = m_mail2[0].join(","); |
377 | ccString = m_mail2[1].join(","); | 396 | ccString = m_mail2[1].join(","); |
378 | bccString = m_mail2[2].join(","); | 397 | bccString = m_mail2[2].join(","); |
379 | 398 | ||
380 | #ifdef DESKTOP_VERSION | 399 | #ifdef DESKTOP_VERSION |
381 | setCaption( i18n("Size: ")+m_recMail->MsgsizeString()+" - "+i18n("E-Mail by %1").arg( m_mail[0] ) ); | 400 | setCaption( i18n("Size: ")+m_recMail->MsgsizeString()+" - "+i18n("E-Mail by %1").arg( m_mail[0] ) ); |
382 | #else | 401 | #else |
383 | setCaption( m_recMail->MsgsizeString()+" - "+m_mail[0] ); | 402 | setCaption( m_recMail->MsgsizeString()+" - "+m_mail[0] ); |
384 | #endif | 403 | #endif |
385 | 404 | ||
386 | m_mailHtml = "<html><body>" | 405 | m_mailHtml = "<html><body>" |
387 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 406 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
388 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 407 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
389 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 408 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
390 | "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 409 | "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
391 | "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 410 | "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
392 | i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 411 | i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
393 | "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + | 412 | "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + |
394 | "</td></tr></table><font>"; | 413 | "</td></tr></table><font>"; |
395 | 414 | ||
396 | if ( !m_showHtml ) | 415 | if ( !m_showHtml ) |
397 | { | 416 | { |
398 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 417 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
399 | } | 418 | } |
400 | else | 419 | else |
401 | { | 420 | { |
402 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); | 421 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); |
403 | } | 422 | } |
404 | // remove later in favor of a real handling | 423 | // remove later in favor of a real handling |
405 | m_gotBody = true; | 424 | m_gotBody = true; |
406 | } | 425 | } |
407 | 426 | ||
408 | 427 | ||
409 | ViewMail::~ViewMail() | 428 | ViewMail::~ViewMail() |
410 | { | 429 | { |
411 | m_recMail->Wrapper()->cleanMimeCache(); | 430 | m_recMail->Wrapper()->cleanMimeCache(); |
412 | hide(); | 431 | hide(); |
413 | } | 432 | } |
414 | 433 | ||
415 | void ViewMail::hide() | 434 | void ViewMail::hide() |
416 | { | 435 | { |
417 | QWidget::hide(); | 436 | QWidget::hide(); |
418 | 437 | ||