Diffstat (limited to 'noncore/net/mail/viewmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 94 |
1 files changed, 81 insertions, 13 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index 7b8494d..39c9820 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,36 +1,104 @@ | |||
1 | #include <qtextbrowser.h> | 1 | #include <qtextbrowser.h> |
2 | #include <qmessagebox.h> | 2 | #include <qmessagebox.h> |
3 | #include <qtextstream.h> | ||
3 | #include <qaction.h> | 4 | #include <qaction.h> |
4 | #include <qapplication.h> | 5 | #include <qapplication.h> |
5 | 6 | ||
6 | #include "settings.h" | 7 | #include "settings.h" |
7 | #include "composemail.h" | 8 | #include "composemail.h" |
8 | #include "viewmail.h" | 9 | #include "viewmail.h" |
9 | 10 | ||
10 | AttachItem::AttachItem(QListView *parent, AttachItemStore &attachItemStore) | 11 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num) |
11 | : QListViewItem(parent), _attachItemStore(attachItemStore) | 12 | : QListViewItem(parent,after),_partNum(num) |
12 | { | 13 | { |
13 | setText(0, _attachItemStore.mimeType()); | 14 | setText(0, mime); |
14 | setText(1, _attachItemStore.fileName()); | 15 | setText(1, file); |
15 | setText(2, _attachItemStore.description()); | 16 | setText(2, desc); |
16 | } | ||
17 | |||
18 | AttachItem::AttachItem(QListViewItem *parent, AttachItemStore &attachItemStore) | ||
19 | : QListViewItem(parent), _attachItemStore(attachItemStore) | ||
20 | { | ||
21 | setText(0, _attachItemStore.mimeType()); | ||
22 | setText(1, _attachItemStore.fileName()); | ||
23 | setText(2, _attachItemStore.description()); | ||
24 | } | 17 | } |
25 | 18 | ||
26 | 19 | ||
27 | void ViewMail::setBody( RecBody body ) { | 20 | void ViewMail::setBody( RecBody body ) { |
28 | 21 | ||
29 | m_mail[2] = body.Bodytext(); | 22 | m_mail[2] = body.Bodytext(); |
23 | attachbutton->setEnabled(body.Parts().count()>0); | ||
24 | attachments->setEnabled(body.Parts().count()>0); | ||
25 | if (body.Parts().count()==0) { | ||
26 | return; | ||
27 | } | ||
28 | AttachItem * curItem=0; | ||
29 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); | ||
30 | QString desc; | ||
31 | double s = body.Description().Size(); | ||
32 | int w; | ||
33 | w=0; | ||
34 | |||
35 | while (s>1024) { | ||
36 | s/=1024; | ||
37 | ++w; | ||
38 | if (w>=2) break; | ||
39 | } | ||
30 | 40 | ||
41 | QString q=""; | ||
42 | switch(w) { | ||
43 | case 1: | ||
44 | q="k"; | ||
45 | break; | ||
46 | case 2: | ||
47 | q="M"; | ||
48 | break; | ||
49 | default: | ||
50 | break; | ||
51 | } | ||
52 | |||
53 | { | ||
54 | /* I did not found a method to make a CONTENT reset on a QTextStream | ||
55 | so I use this construct that the stream will re-constructed in each | ||
56 | loop. To let it work, the textstream is packed into a own area of | ||
57 | code is it will be destructed after finishing its small job. | ||
58 | */ | ||
59 | QTextOStream o(&desc); | ||
60 | if (w>0) o.precision(2); else o.precision(0); | ||
61 | o.setf(QTextStream::fixed); | ||
62 | o << s << " " << q << "Byte"; | ||
63 | } | ||
64 | |||
65 | curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1); | ||
66 | QString filename = ""; | ||
67 | for (unsigned int i = 0; i < body.Parts().count();++i) { | ||
68 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | ||
69 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | ||
70 | for (;it!=body.Parts()[i].Parameters().end();++it) { | ||
71 | if (it.key().lower()=="name") { | ||
72 | filename=it.data(); | ||
73 | } | ||
74 | } | ||
75 | s = body.Parts()[i].Size(); | ||
76 | w = 0; | ||
77 | while (s>1024) { | ||
78 | s/=1024; | ||
79 | ++w; | ||
80 | if (w>=2) break; | ||
81 | } | ||
82 | switch(w) { | ||
83 | case 1: | ||
84 | q="k"; | ||
85 | break; | ||
86 | case 2: | ||
87 | q="M"; | ||
88 | break; | ||
89 | default: | ||
90 | q=""; | ||
91 | break; | ||
92 | } | ||
93 | QTextOStream o(&desc); | ||
94 | if (w>0) o.precision(2); else o.precision(0); | ||
95 | o.setf(QTextStream::fixed); | ||
96 | o << s << " " << q << "Byte"; | ||
97 | curItem=new AttachItem(attachments,curItem,type,filename,desc,i); | ||
98 | } | ||
31 | } | 99 | } |
32 | 100 | ||
33 | void ViewMail::setMail( RecMail mail ) { | 101 | void ViewMail::setMail( RecMail mail ) { |
34 | 102 | ||
35 | m_mail[0] = mail.getFrom(); | 103 | m_mail[0] = mail.getFrom(); |
36 | m_mail[1] = mail.getSubject(); | 104 | m_mail[1] = mail.getSubject(); |