author | harlekin <harlekin> | 2003-12-13 21:49:53 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2003-12-13 21:49:53 (UTC) |
commit | 8290f1a524b6f0051e49f8045d24e508d46868e2 (patch) (unidiff) | |
tree | 6c2acfab918834961c82558224c28b00077bc86f | |
parent | c0e86973b0cd2d01163ccf60340c8d295aa645f4 (diff) | |
download | opie-8290f1a524b6f0051e49f8045d24e508d46868e2.zip opie-8290f1a524b6f0051e49f8045d24e508d46868e2.tar.gz opie-8290f1a524b6f0051e49f8045d24e508d46868e2.tar.bz2 |
possible to show all kind of text attachemnts now
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 10 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.h | 1 |
2 files changed, 7 insertions, 4 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index c24d5d3..a73dac5 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,211 +1,213 @@ | |||
1 | #include <qtextbrowser.h> | 1 | #include <qtextbrowser.h> |
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 <qapplication.h> | 6 | #include <qapplication.h> |
7 | 7 | ||
8 | #include <opie/ofiledialog.h> | 8 | #include <opie/ofiledialog.h> |
9 | 9 | ||
10 | #include "settings.h" | 10 | #include "settings.h" |
11 | #include "composemail.h" | 11 | #include "composemail.h" |
12 | #include "viewmail.h" | 12 | #include "viewmail.h" |
13 | #include "abstractmail.h" | ||
13 | 14 | ||
14 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num) | 15 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num) |
15 | : QListViewItem(parent,after),_partNum(num) | 16 | : QListViewItem(parent,after),_partNum(num) |
16 | { | 17 | { |
17 | setText(0, mime); | 18 | setText(0, mime); |
18 | setText(1, file); | 19 | setText(1, file); |
19 | setText(2, desc); | 20 | setText(2, desc); |
20 | } | 21 | } |
21 | 22 | ||
22 | void ViewMail::setBody( RecBody body ) { | 23 | void ViewMail::setBody( RecBody body ) { |
23 | 24 | ||
24 | m_body = body; | 25 | m_body = body; |
25 | m_mail[2] = body.Bodytext(); | 26 | m_mail[2] = body.Bodytext(); |
26 | attachbutton->setEnabled(body.Parts().count()>0); | 27 | attachbutton->setEnabled(body.Parts().count()>0); |
27 | attachments->setEnabled(body.Parts().count()>0); | 28 | attachments->setEnabled(body.Parts().count()>0); |
28 | if (body.Parts().count()==0) { | 29 | if (body.Parts().count()==0) { |
29 | return; | 30 | return; |
30 | } | 31 | } |
31 | AttachItem * curItem=0; | 32 | AttachItem * curItem=0; |
32 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); | 33 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); |
33 | QString desc; | 34 | QString desc; |
34 | double s = body.Description().Size(); | 35 | double s = body.Description().Size(); |
35 | int w; | 36 | int w; |
36 | w=0; | 37 | w=0; |
37 | 38 | ||
38 | while (s>1024) { | 39 | while (s>1024) { |
39 | s/=1024; | 40 | s/=1024; |
40 | ++w; | 41 | ++w; |
41 | if (w>=2) break; | 42 | if (w>=2) break; |
42 | } | 43 | } |
43 | 44 | ||
44 | QString q=""; | 45 | QString q=""; |
45 | switch(w) { | 46 | switch(w) { |
46 | case 1: | 47 | case 1: |
47 | q="k"; | 48 | q="k"; |
48 | break; | 49 | break; |
49 | case 2: | 50 | case 2: |
50 | q="M"; | 51 | q="M"; |
51 | break; | 52 | break; |
52 | default: | 53 | default: |
53 | break; | 54 | break; |
54 | } | 55 | } |
55 | 56 | ||
56 | { | 57 | { |
57 | /* I did not found a method to make a CONTENT reset on a QTextStream | 58 | /* I did not found a method to make a CONTENT reset on a QTextStream |
58 | so I use this construct that the stream will re-constructed in each | 59 | so I use this construct that the stream will re-constructed in each |
59 | loop. To let it work, the textstream is packed into a own area of | 60 | loop. To let it work, the textstream is packed into a own area of |
60 | code is it will be destructed after finishing its small job. | 61 | code is it will be destructed after finishing its small job. |
61 | */ | 62 | */ |
62 | QTextOStream o(&desc); | 63 | QTextOStream o(&desc); |
63 | if (w>0) o.precision(2); else o.precision(0); | 64 | if (w>0) o.precision(2); else o.precision(0); |
64 | o.setf(QTextStream::fixed); | 65 | o.setf(QTextStream::fixed); |
65 | o << s << " " << q << "Byte"; | 66 | o << s << " " << q << "Byte"; |
66 | } | 67 | } |
67 | 68 | ||
68 | curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1); | 69 | curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1); |
69 | QString filename = ""; | 70 | QString filename = ""; |
70 | for (unsigned int i = 0; i < body.Parts().count();++i) { | 71 | for (unsigned int i = 0; i < body.Parts().count();++i) { |
71 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | 72 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); |
72 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | 73 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); |
73 | for (;it!=body.Parts()[i].Parameters().end();++it) { | 74 | for (;it!=body.Parts()[i].Parameters().end();++it) { |
74 | if (it.key().lower()=="name") { | 75 | if (it.key().lower()=="name") { |
75 | filename=it.data(); | 76 | filename=it.data(); |
76 | } | 77 | } |
77 | } | 78 | } |
78 | s = body.Parts()[i].Size(); | 79 | s = body.Parts()[i].Size(); |
79 | w = 0; | 80 | w = 0; |
80 | while (s>1024) { | 81 | while (s>1024) { |
81 | s/=1024; | 82 | s/=1024; |
82 | ++w; | 83 | ++w; |
83 | if (w>=2) break; | 84 | if (w>=2) break; |
84 | } | 85 | } |
85 | switch(w) { | 86 | switch(w) { |
86 | case 1: | 87 | case 1: |
87 | q="k"; | 88 | q="k"; |
88 | break; | 89 | break; |
89 | case 2: | 90 | case 2: |
90 | q="M"; | 91 | q="M"; |
91 | break; | 92 | break; |
92 | default: | 93 | default: |
93 | q=""; | 94 | q=""; |
94 | break; | 95 | break; |
95 | } | 96 | } |
96 | QTextOStream o(&desc); | 97 | QTextOStream o(&desc); |
97 | if (w>0) o.precision(2); else o.precision(0); | 98 | if (w>0) o.precision(2); else o.precision(0); |
98 | o.setf(QTextStream::fixed); | 99 | o.setf(QTextStream::fixed); |
99 | o << s << " " << q << "Byte"; | 100 | o << s << " " << q << "Byte"; |
100 | curItem=new AttachItem(attachments,curItem,type,filename,desc,i); | 101 | curItem=new AttachItem(attachments,curItem,type,filename,desc,i); |
101 | } | 102 | } |
102 | } | 103 | } |
103 | 104 | ||
104 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int c ) { | 105 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int c ) { |
105 | if (!item ) | 106 | if (!item ) |
106 | return; | 107 | return; |
107 | 108 | ||
108 | QPopupMenu *menu = new QPopupMenu(); | 109 | QPopupMenu *menu = new QPopupMenu(); |
109 | int ret=0; | 110 | int ret=0; |
110 | 111 | ||
111 | if ( item->text( 0 ).left( 4 ) == "text" ) { | 112 | if ( item->text( 0 ).left( 4 ) == "text" ) { |
112 | menu->insertItem( tr( "Show Text" ), 1 ); | 113 | menu->insertItem( tr( "Show Text" ), 1 ); |
113 | } | 114 | } |
114 | menu->insertItem( tr( "Save Attachemt" ), 0 ); | 115 | menu->insertItem( tr( "Save Attachemt" ), 0 ); |
115 | menu->insertSeparator(1); | 116 | menu->insertSeparator(1); |
116 | 117 | ||
117 | ret = menu->exec( point, 0 ); | 118 | ret = menu->exec( point, 0 ); |
118 | 119 | ||
119 | switch(ret) { | 120 | switch(ret) { |
120 | case 0: | 121 | case 0: |
121 | { MimeTypes types; | 122 | { MimeTypes types; |
122 | types.insert( "all", "*" ); | 123 | types.insert( "all", "*" ); |
123 | QString str = OFileDialog::getSaveFileName( 1, | 124 | QString str = OFileDialog::getSaveFileName( 1, |
124 | "/", item->text( 1 ) , types, 0 ); | 125 | "/", item->text( 1 ) , types, 0 ); |
125 | 126 | ||
126 | if( !str.isEmpty() ) { | 127 | if( !str.isEmpty() ) { |
127 | qDebug( " first we will need a MIME wrapper" ); | 128 | qDebug( " first we will need a MIME wrapper" ); |
128 | } | 129 | } |
129 | } | 130 | } |
130 | break ; | 131 | break ; |
131 | 132 | ||
132 | case 1: | 133 | case 1: |
133 | |||
134 | qDebug( QString( "Test selected" ).arg( ( ( AttachItem* )item )->Partnumber() ) ); | 134 | qDebug( QString( "Test selected" ).arg( ( ( AttachItem* )item )->Partnumber() ) ); |
135 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | 135 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { |
136 | setText(); | 136 | setText(); |
137 | } else { | 137 | } else { |
138 | browser->setText( ( m_body.Parts()[( ( AttachItem* )item )->Partnumber() ] ).Identifier() ); | 138 | browser->setText( m_recMail.Wrapper()->fetchPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
139 | } | 139 | } |
140 | break; | 140 | break; |
141 | } | 141 | } |
142 | delete menu; | 142 | delete menu; |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | void ViewMail::setMail( RecMail mail ) { | 146 | void ViewMail::setMail( RecMail mail ) { |
147 | 147 | ||
148 | m_recMail = mail; | ||
149 | |||
148 | m_mail[0] = mail.getFrom(); | 150 | m_mail[0] = mail.getFrom(); |
149 | m_mail[1] = mail.getSubject(); | 151 | m_mail[1] = mail.getSubject(); |
150 | m_mail[3] = mail.getDate(); | 152 | m_mail[3] = mail.getDate(); |
151 | m_mail[4] = mail.Msgid(); | 153 | m_mail[4] = mail.Msgid(); |
152 | 154 | ||
153 | m_mail2[0] = mail.To(); | 155 | m_mail2[0] = mail.To(); |
154 | m_mail2[1] = mail.CC(); | 156 | m_mail2[1] = mail.CC(); |
155 | m_mail2[2] = mail.Bcc(); | 157 | m_mail2[2] = mail.Bcc(); |
156 | 158 | ||
157 | setText(); | 159 | setText(); |
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
161 | 163 | ||
162 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 164 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
163 | : ViewMailBase(parent, name, fl), _inLoop(false) | 165 | : ViewMailBase(parent, name, fl), _inLoop(false) |
164 | { | 166 | { |
165 | m_gotBody = false; | 167 | m_gotBody = false; |
166 | 168 | ||
167 | connect(reply, SIGNAL(activated()), SLOT(slotReply())); | 169 | connect(reply, SIGNAL(activated()), SLOT(slotReply())); |
168 | connect(forward, SIGNAL(activated()), SLOT(slotForward())); | 170 | connect(forward, SIGNAL(activated()), SLOT(slotForward())); |
169 | 171 | ||
170 | attachments->setEnabled(m_gotBody); | 172 | attachments->setEnabled(m_gotBody); |
171 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); | 173 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); |
172 | 174 | ||
173 | } | 175 | } |
174 | 176 | ||
175 | void ViewMail::setText() | 177 | void ViewMail::setText() |
176 | { | 178 | { |
177 | 179 | ||
178 | QString toString; | 180 | QString toString; |
179 | QString ccString; | 181 | QString ccString; |
180 | QString bccString; | 182 | QString bccString; |
181 | 183 | ||
182 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { | 184 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { |
183 | toString += (*it); | 185 | toString += (*it); |
184 | } | 186 | } |
185 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { | 187 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { |
186 | ccString += (*it); | 188 | ccString += (*it); |
187 | } | 189 | } |
188 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { | 190 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { |
189 | bccString += (*it); | 191 | bccString += (*it); |
190 | } | 192 | } |
191 | 193 | ||
192 | setCaption( caption().arg( m_mail[0] ) ); | 194 | setCaption( caption().arg( m_mail[0] ) ); |
193 | 195 | ||
194 | m_mailHtml = "<html><body>" | 196 | m_mailHtml = "<html><body>" |
195 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 197 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
196 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 198 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
197 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 199 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
198 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 200 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
199 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 201 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
200 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 202 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
201 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + | 203 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + |
202 | "</td></tr></table><font face=fixed>"; | 204 | "</td></tr></table><font face=fixed>"; |
203 | 205 | ||
204 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 206 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
205 | // remove later in favor of a real handling | 207 | // remove later in favor of a real handling |
206 | m_gotBody = true; | 208 | m_gotBody = true; |
207 | } | 209 | } |
208 | 210 | ||
209 | 211 | ||
210 | ViewMail::~ViewMail() | 212 | ViewMail::~ViewMail() |
211 | { | 213 | { |
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h index 0e85839..bc12da1 100644 --- a/noncore/net/mail/viewmail.h +++ b/noncore/net/mail/viewmail.h | |||
@@ -1,56 +1,57 @@ | |||
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 | 7 | ||
8 | #include "viewmailbase.h" | 8 | #include "viewmailbase.h" |
9 | #include "mailtypes.h" | 9 | #include "mailtypes.h" |
10 | 10 | ||
11 | class AttachItem : public QListViewItem | 11 | class AttachItem : public QListViewItem |
12 | { | 12 | { |
13 | public: | 13 | public: |
14 | AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num); | 14 | AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num); |
15 | int Partnumber() { return _partNum; } | 15 | int Partnumber() { return _partNum; } |
16 | 16 | ||
17 | private: | 17 | private: |
18 | int _partNum; | 18 | int _partNum; |
19 | }; | 19 | }; |
20 | 20 | ||
21 | class ViewMail : public ViewMailBase | 21 | class ViewMail : public ViewMailBase |
22 | { | 22 | { |
23 | Q_OBJECT | 23 | Q_OBJECT |
24 | 24 | ||
25 | public: | 25 | public: |
26 | ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal); | 26 | ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal); |
27 | ~ViewMail(); | 27 | ~ViewMail(); |
28 | 28 | ||
29 | void hide(); | 29 | void hide(); |
30 | void exec(); | 30 | void exec(); |
31 | void setMail( RecMail mail ); | 31 | void setMail( RecMail mail ); |
32 | void setBody( RecBody body ); | 32 | void setBody( RecBody body ); |
33 | 33 | ||
34 | protected: | 34 | protected: |
35 | QString deHtml(const QString &string); | 35 | QString deHtml(const QString &string); |
36 | 36 | ||
37 | protected slots: | 37 | protected slots: |
38 | void slotReply(); | 38 | void slotReply(); |
39 | void slotForward(); | 39 | void slotForward(); |
40 | void setText(); | 40 | void setText(); |
41 | void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); | 41 | void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); |
42 | 42 | ||
43 | private: | 43 | private: |
44 | bool _inLoop; | 44 | bool _inLoop; |
45 | QString m_mailHtml; | 45 | QString m_mailHtml; |
46 | bool m_gotBody; | 46 | bool m_gotBody; |
47 | RecBody m_body; | 47 | RecBody m_body; |
48 | RecMail m_recMail; | ||
48 | 49 | ||
49 | // 0 from 1 subject 2 bodytext 3 date | 50 | // 0 from 1 subject 2 bodytext 3 date |
50 | QMap <int,QString> m_mail; | 51 | QMap <int,QString> m_mail; |
51 | // 0 to 1 cc 2 bcc | 52 | // 0 to 1 cc 2 bcc |
52 | QMap <int,QStringList> m_mail2; | 53 | QMap <int,QStringList> m_mail2; |
53 | 54 | ||
54 | }; | 55 | }; |
55 | 56 | ||
56 | #endif | 57 | #endif |