-rw-r--r-- | kmicromail/viewmail.cpp | 23 | ||||
-rw-r--r-- | kmicromail/viewmail.h | 2 |
2 files changed, 22 insertions, 3 deletions
diff --git a/kmicromail/viewmail.cpp b/kmicromail/viewmail.cpp index 726f540..685b4e4 100644 --- a/kmicromail/viewmail.cpp +++ b/kmicromail/viewmail.cpp @@ -54,96 +54,108 @@ AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QStrin setText(0, mime); setText(1, desc); setText(2, file); setText(3, fsize); } bool AttachItem::isParentof(const QValueList<int>&path) { /* if not set, then no parent */ if (path.count()==0||_path.count()==0) return false; /* the parent must have one digit less then a child */ if (path.count()!=_path.count()+1) return false; for (unsigned int i=0; i < _path.count();++i) { if (_path[i]!=path[i]) return false; } return true; } AttachItem* ViewMail::searchParent(const QValueList<int>&path) { QListViewItemIterator it( attachments ); for ( ; it.current(); ++it ) { AttachItem*ati = (AttachItem*)it.current(); if (ati->isParentof(path)) return ati; } return 0; } AttachItem* ViewMail::lastChild(AttachItem*parent) { if (!parent) return 0; AttachItem* item = (AttachItem*)parent->firstChild(); if (!item) return item; AttachItem*temp=0; while( (temp=(AttachItem*)item->nextSibling())) { item = temp; } return item; } void ViewMail::setBody(const RecBodyP&body ) { m_body = body; m_mail[2] = body->Bodytext(); + m_showHtml = KOPrefs::instance()->mViewAsHtml; + if ( m_showHtml ) { + if ( m_mail[2].find ("<html>",0,false ) > -1 ) { + qDebug("html mail "); + } else { + qDebug("no html mail "); + m_showHtml = false; + } + } + showHtml->blockSignals( true ); + showHtml->setOn( m_showHtml ); + showHtml->blockSignals( false ); // qDebug("********text %s ",m_mail[2].latin1() ); attachbutton->setEnabled(body->Parts().count()>0); attachments->setEnabled(body->Parts().count()>0); if (body->Parts().count()==0) { return; } AttachItem * curItem=0; AttachItem * parentItem = 0; QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); QString desc,fsize; double s = body->Description()->Size(); int w; w=0; while (s>1024) { s/=1024; ++w; if (w>=2) break; } QString q=""; switch(w) { case 1: q="k"; break; case 2: q="M"; break; default: break; } { /* I did not found a method to make a CONTENT reset on a QTextStream so I use this construct that the stream will re-constructed in each loop. To let it work, the textstream is packed into a own area of code is it will be destructed after finishing its small job. */ QTextOStream o(&fsize); if (w>0) o.precision(2); else o.precision(0); o.setf(QTextStream::fixed); o << s << " " << q << "Byte"; } curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); @@ -286,117 +298,124 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int if (content) { QFile output(tmpfile); output.open(IO_WriteOnly); output.writeBlock(content->Content(),content->Length()); output.close(); delete content; MailImageDlg iview(""); iview.setName(tmpfile); KApplication::execDialog(&iview); output.remove(); } } break; case 1: if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { setText(); } else { if ( m_recMail->Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); } } break; } delete menu; } void ViewMail::setMail(const RecMailP&mail ) { m_recMail = mail; m_mail[0] = mail->getFrom(); m_mail[1] = mail->getSubject(); m_mail[3] = mail->getDate(); m_mail[4] = mail->Msgid(); m_mail2[0] = mail->To(); m_mail2[1] = mail->CC(); m_mail2[2] = mail->Bcc(); setText(); } - +void ViewMail::slotNextMail() +{ + nextMail->blockSignals( true ); + setCaption(i18n("Displaying next mail...please wait!")); + qApp->processEvents(); + emit showNextMail(this); + nextMail->blockSignals( false ); +} ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) : ViewMailBase(parent, name, fl), _inLoop(false) { m_gotBody = false; deleted = false; sourceOn = false; + readConfig(); connect( reply, SIGNAL(activated()), SLOT(slotReply())); connect( forward, SIGNAL(activated()), SLOT(slotForward())); connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) ); connect( viewSource, SIGNAL( activated() ), SLOT( slotViewSource() ) ); connect( downloadMail, SIGNAL( activated() ), SIGNAL( signalDownloadMail() ) ); attachments->setEnabled(m_gotBody); connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); - readConfig(); attachments->setSorting(-1); } void ViewMail::readConfig() { setFont ( KOPrefs::instance()->mReadFont ); m_showHtml = KOPrefs::instance()->mViewAsHtml; showHtml->setOn( m_showHtml ); } void ViewMail::setText() { viewSource->setText(i18n("View Source")); sourceOn = false; QString toString; QString ccString; QString bccString; toString = m_mail2[0].join(","); ccString = m_mail2[1].join(","); bccString = m_mail2[2].join(","); #ifdef DESKTOP_VERSION setCaption( i18n("Size: ")+m_recMail->MsgsizeString()+" - "+i18n("E-Mail by %1").arg( m_mail[0] ) ); #else setCaption( m_recMail->MsgsizeString()+" - "+m_mail[0] ); #endif m_mailHtml = "<html><body>" "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + "</td></tr></table><font>"; if ( !m_showHtml ) { browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); } else { browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); diff --git a/kmicromail/viewmail.h b/kmicromail/viewmail.h index fc5edcf..bb5b685 100644 --- a/kmicromail/viewmail.h +++ b/kmicromail/viewmail.h @@ -9,85 +9,85 @@ #include <qlistview.h> #include <qmap.h> #include <klocale.h> #include <qstringlist.h> #include <qvaluelist.h> //namespace Opie { namespace MM { class OImageScrollView; } } class AttachItem : public QListViewItem { public: AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, const QString&fsize,int num,const QValueList<int>&path); AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, const QString&fsize,int num,const QValueList<int>&path); int Partnumber() { return _partNum; } bool isParentof(const QValueList<int>&path); private: int _partNum; /* needed for a better display of attachments */ QValueList<int> _path; }; class ViewMail : public ViewMailBase { Q_OBJECT public: ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = 0); ~ViewMail(); void hide(); void exec(); void setMail(const RecMailP&mail ); void setBody(const RecBodyP&body); bool deleted; signals: void showNextMail(ViewMail*); void deleteAndDisplayNextMail(ViewMail *); void signalDownloadMail(); protected: QString deHtml(const QString &string); AttachItem* searchParent(const QValueList<int>&path); AttachItem* lastChild(AttachItem*parent); protected slots: - void slotNextMail() { setCaption(i18n("Displaying next mail...please wait!")); qApp->processEvents();emit showNextMail(this); }; + void slotNextMail(); void slotReply(); void slotForward(); void setText(); void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); void slotDeleteMail( ); void slotShowHtml( bool ); void slotViewSource(); private: void readConfig(); bool sourceOn;; bool _inLoop; QString m_mailHtml; bool m_gotBody; RecBodyP m_body; RecMailP m_recMail; bool m_showHtml; // 0 from 1 subject 2 bodytext 3 date QMap <int,QString> m_mail; // 0 to 1 cc 2 bcc QMap <int,QStringList> m_mail2; }; class MailImageDlg:public QDialog { Q_OBJECT public: MailImageDlg(const QString&,QWidget *parent = 0, const char *name = 0, bool modal = true, WFlags f = 0); ~MailImageDlg(); void setName(const QString&); protected: //Opie::MM::OImageScrollView*m_imageview; }; #endif |