-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 | |||
@@ -2,12 +2,13 @@ | |||
2 | #include <qmessagebox.h> | 2 | #include <qmessagebox.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include <qaction.h> | 4 | #include <qaction.h> |
5 | #include <qpopupmenu.h> | 5 | #include <qpopupmenu.h> |
6 | #include <qfile.h> | 6 | #include <qfile.h> |
7 | #include <qapplication.h> | 7 | #include <qapplication.h> |
8 | #include <qvaluelist.h> | ||
8 | 9 | ||
9 | #include <qpe/config.h> | 10 | #include <qpe/config.h> |
10 | 11 | ||
11 | #include <opie/ofiledialog.h> | 12 | #include <opie/ofiledialog.h> |
12 | 13 | ||
13 | #include "settings.h" | 14 | #include "settings.h" |
@@ -15,31 +16,66 @@ | |||
15 | #include "viewmail.h" | 16 | #include "viewmail.h" |
16 | #include "abstractmail.h" | 17 | #include "abstractmail.h" |
17 | #include "accountview.h" | 18 | #include "accountview.h" |
18 | #include "mailtypes.h" | 19 | #include "mailtypes.h" |
19 | 20 | ||
20 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 21 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
21 | const QString&fsize,int num) | 22 | const QString&fsize,int num,const QValueList<int>&path) |
22 | : QListViewItem(parent,after),_partNum(num) | 23 | : QListViewItem(parent,after),_partNum(num) |
23 | { | 24 | { |
25 | _path=path; | ||
24 | setText(0, mime); | 26 | setText(0, mime); |
25 | setText(1, desc); | 27 | setText(1, desc); |
26 | setText(2, file); | 28 | setText(2, file); |
27 | setText(3, fsize); | 29 | setText(3, fsize); |
28 | } | 30 | } |
29 | 31 | ||
32 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | ||
33 | const QString&fsize,int num,const QValueList<int>&path) | ||
34 | : QListViewItem(parent,after),_partNum(num) | ||
35 | { | ||
36 | _path=path; | ||
37 | setText(0, mime); | ||
38 | setText(1, desc); | ||
39 | setText(2, file); | ||
40 | setText(3, fsize); | ||
41 | } | ||
42 | |||
43 | bool AttachItem::isParentof(const QValueList<int>&path) | ||
44 | { | ||
45 | /* if not set, then no parent */ | ||
46 | if (path.count()==0||_path.count()==0) return false; | ||
47 | /* the parent must have one digit less then a child */ | ||
48 | if (path.count()!=_path.count()+1) return false; | ||
49 | for (unsigned int i=0; i < _path.count();++i) { | ||
50 | if (_path[i]!=path[i]) return false; | ||
51 | } | ||
52 | return true; | ||
53 | } | ||
54 | |||
55 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) | ||
56 | { | ||
57 | QListViewItemIterator it( attachments ); | ||
58 | for ( ; it.current(); ++it ) { | ||
59 | AttachItem*ati = (AttachItem*)it.current(); | ||
60 | if (ati->isParentof(path)) return ati; | ||
61 | } | ||
62 | return 0; | ||
63 | } | ||
64 | |||
30 | void ViewMail::setBody( RecBody body ) { | 65 | void ViewMail::setBody( RecBody body ) { |
31 | 66 | ||
32 | m_body = body; | 67 | m_body = body; |
33 | m_mail[2] = body.Bodytext(); | 68 | m_mail[2] = body.Bodytext(); |
34 | attachbutton->setEnabled(body.Parts().count()>0); | 69 | attachbutton->setEnabled(body.Parts().count()>0); |
35 | attachments->setEnabled(body.Parts().count()>0); | 70 | attachments->setEnabled(body.Parts().count()>0); |
36 | if (body.Parts().count()==0) { | 71 | if (body.Parts().count()==0) { |
37 | return; | 72 | return; |
38 | } | 73 | } |
39 | AttachItem * curItem=0; | 74 | AttachItem * curItem=0; |
75 | AttachItem * parentItem = 0; | ||
40 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); | 76 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); |
41 | QString desc,fsize; | 77 | QString desc,fsize; |
42 | double s = body.Description().Size(); | 78 | double s = body.Description().Size(); |
43 | int w; | 79 | int w; |
44 | w=0; | 80 | w=0; |
45 | 81 | ||
@@ -70,14 +106,15 @@ default: | |||
70 | QTextOStream o(&fsize); | 106 | QTextOStream o(&fsize); |
71 | if (w>0) o.precision(2); else o.precision(0); | 107 | if (w>0) o.precision(2); else o.precision(0); |
72 | o.setf(QTextStream::fixed); | 108 | o.setf(QTextStream::fixed); |
73 | o << s << " " << q << "Byte"; | 109 | o << s << " " << q << "Byte"; |
74 | } | 110 | } |
75 | 111 | ||
76 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1); | 112 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist()); |
77 | QString filename = ""; | 113 | QString filename = ""; |
114 | |||
78 | for (unsigned int i = 0; i < body.Parts().count();++i) { | 115 | for (unsigned int i = 0; i < body.Parts().count();++i) { |
79 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | 116 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); |
80 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | 117 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); |
81 | for (;it!=body.Parts()[i].Parameters().end();++it) { | 118 | for (;it!=body.Parts()[i].Parameters().end();++it) { |
82 | qDebug(it.key()); | 119 | qDebug(it.key()); |
83 | if (it.key().lower()=="name") { | 120 | if (it.key().lower()=="name") { |
@@ -104,13 +141,19 @@ for (unsigned int i = 0; i < body.Parts().count();++i) { | |||
104 | } | 141 | } |
105 | QTextOStream o(&fsize); | 142 | QTextOStream o(&fsize); |
106 | if (w>0) o.precision(2); else o.precision(0); | 143 | if (w>0) o.precision(2); else o.precision(0); |
107 | o.setf(QTextStream::fixed); | 144 | o.setf(QTextStream::fixed); |
108 | o << s << " " << q << "Byte"; | 145 | o << s << " " << q << "Byte"; |
109 | desc = body.Parts()[i].Description(); | 146 | desc = body.Parts()[i].Description(); |
110 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i); | 147 | parentItem = searchParent(body.Parts()[i].Positionlist()); |
148 | if (parentItem) { | ||
149 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); | ||
150 | attachments->setRootIsDecorated(true); | ||
151 | } else { | ||
152 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); | ||
153 | } | ||
111 | } | 154 | } |
112 | } | 155 | } |
113 | 156 | ||
114 | 157 | ||
115 | void ViewMail::slotShowHtml( bool state ) { | 158 | void ViewMail::slotShowHtml( bool state ) { |
116 | m_showHtml = state; | 159 | m_showHtml = state; |
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,25 +1,31 @@ | |||
1 | #ifndef VIEWMAIL_H | 1 | #ifndef VIEWMAIL_H |
2 | #define VIEWMAIL_H | 2 | #define VIEWMAIL_H |
3 | 3 | ||
4 | #include <qlistview.h> | 4 | #include <qlistview.h> |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | #include <qvaluelist.h> | ||
7 | 8 | ||
8 | #include "viewmailbase.h" | 9 | #include "viewmailbase.h" |
9 | #include "mailtypes.h" | 10 | #include "mailtypes.h" |
10 | 11 | ||
11 | class AttachItem : public QListViewItem | 12 | class AttachItem : public QListViewItem |
12 | { | 13 | { |
13 | public: | 14 | public: |
14 | AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 15 | AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
15 | const QString&fsize,int num); | 16 | const QString&fsize,int num,const QValueList<int>&path); |
17 | AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | ||
18 | const QString&fsize,int num,const QValueList<int>&path); | ||
16 | int Partnumber() { return _partNum; } | 19 | int Partnumber() { return _partNum; } |
20 | bool isParentof(const QValueList<int>&path); | ||
17 | 21 | ||
18 | private: | 22 | private: |
19 | int _partNum; | 23 | int _partNum; |
24 | /* needed for a better display of attachments */ | ||
25 | QValueList<int> _path; | ||
20 | }; | 26 | }; |
21 | 27 | ||
22 | class ViewMail : public ViewMailBase | 28 | class ViewMail : public ViewMailBase |
23 | { | 29 | { |
24 | Q_OBJECT | 30 | Q_OBJECT |
25 | 31 | ||
@@ -32,12 +38,13 @@ public: | |||
32 | void setMail( RecMail mail ); | 38 | void setMail( RecMail mail ); |
33 | void setBody( RecBody body ); | 39 | void setBody( RecBody body ); |
34 | bool deleted; | 40 | bool deleted; |
35 | 41 | ||
36 | protected: | 42 | protected: |
37 | QString deHtml(const QString &string); | 43 | QString deHtml(const QString &string); |
44 | AttachItem* searchParent(const QValueList<int>&path); | ||
38 | 45 | ||
39 | protected slots: | 46 | protected slots: |
40 | void slotReply(); | 47 | void slotReply(); |
41 | void slotForward(); | 48 | void slotForward(); |
42 | void setText(); | 49 | void setText(); |
43 | void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); | 50 | void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); |