author | alwin <alwin> | 2004-01-02 02:47:12 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-02 02:47:12 (UTC) |
commit | fec64a3eb7b198666eb9937df47323bad94b1ba0 (patch) (side-by-side diff) | |
tree | a781a5999d7efb3b3926aa056bf8bac471f5e484 | |
parent | 5fbf2a6b9cda98ab16fa1f0e1ac848a9bb523a72 (diff) | |
download | opie-fec64a3eb7b198666eb9937df47323bad94b1ba0.zip opie-fec64a3eb7b198666eb9937df47323bad94b1ba0.tar.gz opie-fec64a3eb7b198666eb9937df47323bad94b1ba0.tar.bz2 |
display of attachments has a hierarchic structure (if needed)
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 49 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.h | 9 |
2 files changed, 54 insertions, 4 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index d2e5e29..5e7ffeb 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp @@ -1,47 +1,83 @@ #include <qtextbrowser.h> #include <qmessagebox.h> #include <qtextstream.h> #include <qaction.h> #include <qpopupmenu.h> #include <qfile.h> #include <qapplication.h> +#include <qvaluelist.h> #include <qpe/config.h> #include <opie/ofiledialog.h> #include "settings.h" #include "composemail.h" #include "viewmail.h" #include "abstractmail.h" #include "accountview.h" #include "mailtypes.h" AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, - const QString&fsize,int num) + const QString&fsize,int num,const QValueList<int>&path) : QListViewItem(parent,after),_partNum(num) { + _path=path; setText(0, mime); setText(1, desc); setText(2, file); setText(3, fsize); } +AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, + const QString&fsize,int num,const QValueList<int>&path) + : QListViewItem(parent,after),_partNum(num) +{ + _path=path; + 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; +} + void ViewMail::setBody( RecBody body ) { m_body = body; m_mail[2] = body.Bodytext(); 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; @@ -68,18 +104,19 @@ default: 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); +curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist()); QString filename = ""; + for (unsigned int i = 0; i < body.Parts().count();++i) { type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); for (;it!=body.Parts()[i].Parameters().end();++it) { qDebug(it.key()); if (it.key().lower()=="name") { filename=it.data(); } @@ -102,17 +139,23 @@ for (unsigned int i = 0; i < body.Parts().count();++i) { q=""; break; } QTextOStream o(&fsize); if (w>0) o.precision(2); else o.precision(0); o.setf(QTextStream::fixed); o << s << " " << q << "Byte"; desc = body.Parts()[i].Description(); - curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i); + parentItem = searchParent(body.Parts()[i].Positionlist()); + if (parentItem) { + curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); + attachments->setRootIsDecorated(true); + } else { + curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); + } } } void ViewMail::slotShowHtml( bool state ) { m_showHtml = state; setText(); } diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h index bf7a4dd..b3d3b4e 100644 --- a/noncore/net/mail/viewmail.h +++ b/noncore/net/mail/viewmail.h @@ -1,27 +1,33 @@ #ifndef VIEWMAIL_H #define VIEWMAIL_H #include <qlistview.h> #include <qmap.h> #include <qstringlist.h> +#include <qvaluelist.h> #include "viewmailbase.h" #include "mailtypes.h" 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 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 = Qt::WType_Modal); @@ -30,16 +36,17 @@ public: void hide(); void exec(); void setMail( RecMail mail ); void setBody( RecBody body ); bool deleted; protected: QString deHtml(const QString &string); + AttachItem* searchParent(const QValueList<int>&path); protected slots: void slotReply(); void slotForward(); void setText(); void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); void slotDeleteMail( ); void slotShowHtml( bool ); |