summaryrefslogtreecommitdiffabout
path: root/kmicromail/viewmail.cpp
Unidiff
Diffstat (limited to 'kmicromail/viewmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/viewmail.cpp47
1 files changed, 25 insertions, 22 deletions
diff --git a/kmicromail/viewmail.cpp b/kmicromail/viewmail.cpp
index 685b4e4..c9dedb0 100644
--- a/kmicromail/viewmail.cpp
+++ b/kmicromail/viewmail.cpp
@@ -15,73 +15,76 @@
15#include "composemail.h" 15#include "composemail.h"
16#include "viewmail.h" 16#include "viewmail.h"
17 17
18#include <libmailwrapper/settings.h> 18#include <libmailwrapper/settings.h>
19#include <libmailwrapper/abstractmail.h> 19#include <libmailwrapper/abstractmail.h>
20#include <libmailwrapper/mailtypes.h> 20#include <libmailwrapper/mailtypes.h>
21 21
22#include <qdialog.h> 22#include <qdialog.h>
23 23
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25 25
26/* QT */ 26/* QT */
27#include <qtextbrowser.h> 27#include <q3textbrowser.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qtextstream.h> 29#include <q3textstream.h>
30#include <qaction.h> 30#include <qaction.h>
31#include <qpopupmenu.h> 31#include <q3popupmenu.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qlayout.h> 33#include <qlayout.h>
34//Added by qt3to4:
35#include <Q3ValueList>
36#include <Q3VBoxLayout>
34 37
35//using namespace Opie::Ui; 38//using namespace Opie::Ui;
36//using namespace Opie::Core; 39//using namespace Opie::Core;
37 40
38AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 41AttachItem::AttachItem(Q3ListView * parent,Q3ListViewItem *after, const QString&mime,const QString&desc,const QString&file,
39 const QString&fsize,int num,const QValueList<int>&path) 42 const QString&fsize,int num,const Q3ValueList<int>&path)
40 : QListViewItem(parent,after),_partNum(num) 43 : Q3ListViewItem(parent,after),_partNum(num)
41{ 44{
42 _path=path; 45 _path=path;
43 setText(0, mime); 46 setText(0, mime);
44 setText(1, desc); 47 setText(1, desc);
45 setText(2, file); 48 setText(2, file);
46 setText(3, fsize); 49 setText(3, fsize);
47} 50}
48 51
49AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 52AttachItem::AttachItem(Q3ListViewItem * parent,Q3ListViewItem *after, const QString&mime,const QString&desc,const QString&file,
50 const QString&fsize,int num,const QValueList<int>&path) 53 const QString&fsize,int num,const Q3ValueList<int>&path)
51 : QListViewItem(parent,after),_partNum(num) 54 : Q3ListViewItem(parent,after),_partNum(num)
52{ 55{
53 _path=path; 56 _path=path;
54 setText(0, mime); 57 setText(0, mime);
55 setText(1, desc); 58 setText(1, desc);
56 setText(2, file); 59 setText(2, file);
57 setText(3, fsize); 60 setText(3, fsize);
58} 61}
59 62
60bool AttachItem::isParentof(const QValueList<int>&path) 63bool AttachItem::isParentof(const Q3ValueList<int>&path)
61{ 64{
62 /* if not set, then no parent */ 65 /* if not set, then no parent */
63 if (path.count()==0||_path.count()==0) return false; 66 if (path.count()==0||_path.count()==0) return false;
64 /* the parent must have one digit less then a child */ 67 /* the parent must have one digit less then a child */
65 if (path.count()!=_path.count()+1) return false; 68 if (path.count()!=_path.count()+1) return false;
66 for (unsigned int i=0; i < _path.count();++i) 69 for (unsigned int i=0; i < _path.count();++i)
67 { 70 {
68 if (_path[i]!=path[i]) return false; 71 if (_path[i]!=path[i]) return false;
69 } 72 }
70 return true; 73 return true;
71} 74}
72 75
73AttachItem* ViewMail::searchParent(const QValueList<int>&path) 76AttachItem* ViewMail::searchParent(const Q3ValueList<int>&path)
74{ 77{
75 QListViewItemIterator it( attachments ); 78 Q3ListViewItemIterator it( attachments );
76 for ( ; it.current(); ++it ) 79 for ( ; it.current(); ++it )
77 { 80 {
78 AttachItem*ati = (AttachItem*)it.current(); 81 AttachItem*ati = (AttachItem*)it.current();
79 if (ati->isParentof(path)) return ati; 82 if (ati->isParentof(path)) return ati;
80 } 83 }
81 return 0; 84 return 0;
82} 85}
83 86
84AttachItem* ViewMail::lastChild(AttachItem*parent) 87AttachItem* ViewMail::lastChild(AttachItem*parent)
85{ 88{
86 if (!parent) return 0; 89 if (!parent) return 0;
87 AttachItem* item = (AttachItem*)parent->firstChild(); 90 AttachItem* item = (AttachItem*)parent->firstChild();
@@ -145,25 +148,25 @@ void ViewMail::setBody(const RecBodyP&body )
145 default: 148 default:
146 break; 149 break;
147 } 150 }
148 151
149 { 152 {
150 /* I did not found a method to make a CONTENT reset on a QTextStream 153 /* I did not found a method to make a CONTENT reset on a QTextStream
151 so I use this construct that the stream will re-constructed in each 154 so I use this construct that the stream will re-constructed in each
152 loop. To let it work, the textstream is packed into a own area of 155 loop. To let it work, the textstream is packed into a own area of
153 code is it will be destructed after finishing its small job. 156 code is it will be destructed after finishing its small job.
154 */ 157 */
155 QTextOStream o(&fsize); 158 QTextOStream o(&fsize);
156 if (w>0) o.precision(2); else o.precision(0); 159 if (w>0) o.precision(2); else o.precision(0);
157 o.setf(QTextStream::fixed); 160 o.setf(Q3TextStream::fixed);
158 o << s << " " << q << "Byte"; 161 o << s << " " << q << "Byte";
159 } 162 }
160 163
161 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); 164 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist());
162 QString filename = ""; 165 QString filename = "";
163 166
164 for (unsigned int i = 0; i < body->Parts().count();++i) 167 for (unsigned int i = 0; i < body->Parts().count();++i)
165 { 168 {
166 filename = ""; 169 filename = "";
167 type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); 170 type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype();
168 part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); 171 part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin();
169 for (;it!=body->Parts()[i]->Parameters().end();++it) 172 for (;it!=body->Parts()[i]->Parameters().end();++it)
@@ -186,25 +189,25 @@ void ViewMail::setBody(const RecBodyP&body )
186 case 1: 189 case 1:
187 q="k"; 190 q="k";
188 break; 191 break;
189 case 2: 192 case 2:
190 q="M"; 193 q="M";
191 break; 194 break;
192 default: 195 default:
193 q=""; 196 q="";
194 break; 197 break;
195 } 198 }
196 QTextOStream o(&fsize); 199 QTextOStream o(&fsize);
197 if (w>0) o.precision(2); else o.precision(0); 200 if (w>0) o.precision(2); else o.precision(0);
198 o.setf(QTextStream::fixed); 201 o.setf(Q3TextStream::fixed);
199 o << s << " " << q << "Byte"; 202 o << s << " " << q << "Byte";
200 desc = body->Parts()[i]->Description(); 203 desc = body->Parts()[i]->Description();
201 parentItem = searchParent(body->Parts()[i]->Positionlist()); 204 parentItem = searchParent(body->Parts()[i]->Positionlist());
202 if (parentItem) 205 if (parentItem)
203 { 206 {
204 AttachItem*temp = lastChild(parentItem); 207 AttachItem*temp = lastChild(parentItem);
205 if (temp) curItem = temp; 208 if (temp) curItem = temp;
206 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); 209 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist());
207 attachments->setRootIsDecorated(true); 210 attachments->setRootIsDecorated(true);
208 curItem = parentItem; 211 curItem = parentItem;
209 } 212 }
210 else 213 else
@@ -230,35 +233,35 @@ void ViewMail::slotViewSource()
230 } 233 }
231 } else 234 } else
232 setText(); 235 setText();
233 236
234 237
235} 238}
236void ViewMail::slotShowHtml( bool state ) 239void ViewMail::slotShowHtml( bool state )
237{ 240{
238 m_showHtml = state; 241 m_showHtml = state;
239 setText(); 242 setText();
240} 243}
241 244
242void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) 245void ViewMail::slotItemClicked( Q3ListViewItem * item , const QPoint & point, int )
243{ 246{
244 if (!item ) 247 if (!item )
245 return; 248 return;
246 249
247 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 250 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
248 { 251 {
249 setText(); 252 setText();
250 return; 253 return;
251 } 254 }
252 QPopupMenu *menu = new QPopupMenu(); 255 Q3PopupMenu *menu = new Q3PopupMenu();
253 int ret=0; 256 int ret=0;
254 257
255 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) 258 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" )
256 { 259 {
257 menu->insertItem( i18n( "Show Text" ), 1 ); 260 menu->insertItem( i18n( "Show Text" ), 1 );
258 } 261 }
259 if (item->text(0).left(6)=="image/") { 262 if (item->text(0).left(6)=="image/") {
260 menu->insertItem(i18n("Display image preview"),2); 263 menu->insertItem(i18n("Display image preview"),2);
261 } 264 }
262 menu->insertItem( i18n( "Save Attachment" ), 0 ); 265 menu->insertItem( i18n( "Save Attachment" ), 0 );
263 menu->insertSeparator(1); 266 menu->insertSeparator(1);
264 267
@@ -269,44 +272,44 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int
269 case 0: 272 case 0:
270 { 273 {
271 //MimeTypes types; 274 //MimeTypes types;
272 //types.insert( "all", "*" ); 275 //types.insert( "all", "*" );
273 QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this ); 276 QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this );
274 277
275 if( !str.isEmpty() ) 278 if( !str.isEmpty() )
276 { 279 {
277 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 280 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
278 if (content) 281 if (content)
279 { 282 {
280 QFile output(str); 283 QFile output(str);
281 output.open(IO_WriteOnly); 284 output.open(QIODevice::WriteOnly);
282 output.writeBlock(content->Content(),content->Length()); 285 output.writeBlock(content->Content(),content->Length());
283 output.close(); 286 output.close();
284 delete content; 287 delete content;
285 } 288 }
286 } 289 }
287 } 290 }
288 break ; 291 break ;
289 292
290 case 2: 293 case 2:
291 { 294 {
292#ifdef DESKTOP_VERSION 295#ifdef DESKTOP_VERSION
293 QString tmpfile = locateLocal( "tmp", "opiemail-image"); 296 QString tmpfile = locateLocal( "tmp", "opiemail-image");
294#else 297#else
295 QString tmpfile = "/tmp/opiemail-image"; 298 QString tmpfile = "/tmp/opiemail-image";
296#endif 299#endif
297 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 300 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
298 if (content) { 301 if (content) {
299 QFile output(tmpfile); 302 QFile output(tmpfile);
300 output.open(IO_WriteOnly); 303 output.open(QIODevice::WriteOnly);
301 output.writeBlock(content->Content(),content->Length()); 304 output.writeBlock(content->Content(),content->Length());
302 output.close(); 305 output.close();
303 delete content; 306 delete content;
304 MailImageDlg iview(""); 307 MailImageDlg iview("");
305 iview.setName(tmpfile); 308 iview.setName(tmpfile);
306 KApplication::execDialog(&iview); 309 KApplication::execDialog(&iview);
307 output.remove(); 310 output.remove();
308 } 311 }
309 } 312 }
310 break; 313 break;
311 case 1: 314 case 1:
312 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 315 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
@@ -343,42 +346,42 @@ void ViewMail::setMail(const RecMailP&mail )
343 setText(); 346 setText();
344} 347}
345 348
346void ViewMail::slotNextMail() 349void ViewMail::slotNextMail()
347{ 350{
348 nextMail->blockSignals( true ); 351 nextMail->blockSignals( true );
349 setCaption(i18n("Displaying next mail...please wait!")); 352 setCaption(i18n("Displaying next mail...please wait!"));
350 qApp->processEvents(); 353 qApp->processEvents();
351 emit showNextMail(this); 354 emit showNextMail(this);
352 nextMail->blockSignals( false ); 355 nextMail->blockSignals( false );
353} 356}
354 357
355ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) 358ViewMail::ViewMail( QWidget *parent, const char *name, Qt::WFlags fl)
356 : ViewMailBase(parent, name, fl), _inLoop(false) 359 : ViewMailBase(parent, name, fl), _inLoop(false)
357{ 360{
358 m_gotBody = false; 361 m_gotBody = false;
359 deleted = false; 362 deleted = false;
360 sourceOn = false; 363 sourceOn = false;
361 readConfig(); 364 readConfig();
362 connect( reply, SIGNAL(activated()), SLOT(slotReply())); 365 connect( reply, SIGNAL(activated()), SLOT(slotReply()));
363 connect( forward, SIGNAL(activated()), SLOT(slotForward())); 366 connect( forward, SIGNAL(activated()), SLOT(slotForward()));
364 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); 367 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) );
365 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); 368 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) );
366 connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); 369 connect( closeMail, SIGNAL( activated() ), SLOT( close() ) );
367 connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) ); 370 connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) );
368 connect( viewSource, SIGNAL( activated() ), SLOT( slotViewSource() ) ); 371 connect( viewSource, SIGNAL( activated() ), SLOT( slotViewSource() ) );
369 connect( downloadMail, SIGNAL( activated() ), SIGNAL( signalDownloadMail() ) ); 372 connect( downloadMail, SIGNAL( activated() ), SIGNAL( signalDownloadMail() ) );
370 373
371 attachments->setEnabled(m_gotBody); 374 attachments->setEnabled(m_gotBody);
372 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); 375 connect( attachments, SIGNAL( clicked(Q3ListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(Q3ListViewItem*,const QPoint&, int) ) );
373 376
374 attachments->setSorting(-1); 377 attachments->setSorting(-1);
375} 378}
376 379
377void ViewMail::readConfig() 380void ViewMail::readConfig()
378{ 381{
379 382
380 setFont ( KOPrefs::instance()->mReadFont ); 383 setFont ( KOPrefs::instance()->mReadFont );
381 m_showHtml = KOPrefs::instance()->mViewAsHtml; 384 m_showHtml = KOPrefs::instance()->mViewAsHtml;
382 showHtml->setOn( m_showHtml ); 385 showHtml->setOn( m_showHtml );
383} 386}
384 387
@@ -548,28 +551,28 @@ void ViewMail::slotForward()
548 551
549void ViewMail::slotDeleteMail( ) 552void ViewMail::slotDeleteMail( )
550{ 553{
551 if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 554 if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
552 { 555 {
553 emit deleteAndDisplayNextMail( this); 556 emit deleteAndDisplayNextMail( this);
554 //m_recMail->Wrapper()->deleteMail( m_recMail ); 557 //m_recMail->Wrapper()->deleteMail( m_recMail );
555 //hide(); 558 //hide();
556 deleted = true; 559 deleted = true;
557 } 560 }
558} 561}
559 562
560MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, WFlags f) 563MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, Qt::WFlags f)
561 : QDialog(parent,name,modal) 564 : QDialog(parent,name,modal)
562{ 565{
563 QVBoxLayout*dlglayout = new QVBoxLayout(this); 566 Q3VBoxLayout*dlglayout = new Q3VBoxLayout(this);
564 dlglayout->setSpacing(2); 567 dlglayout->setSpacing(2);
565 dlglayout->setMargin(1); 568 dlglayout->setMargin(1);
566 //m_imageview = new Opie::MM::OImageScrollView(this); 569 //m_imageview = new Opie::MM::OImageScrollView(this);
567 //dlglayout->addWidget(m_imageview); 570 //dlglayout->addWidget(m_imageview);
568} 571}
569 572
570MailImageDlg::~MailImageDlg() 573MailImageDlg::~MailImageDlg()
571{ 574{
572} 575}
573 576
574void MailImageDlg::setName(const QString&fname) 577void MailImageDlg::setName(const QString&fname)
575{ 578{