author | alwin <alwin> | 2004-01-03 13:04:52 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-03 13:04:52 (UTC) |
commit | 22564b62e15c1ea3feada5b2f9b6ec4d98b40c6b (patch) (unidiff) | |
tree | 85847776be6743270b18f5e1df9fa6451288f7a6 | |
parent | 452aac36b77ed1f7e6db3a7952028bf6027e54b6 (diff) | |
download | opie-22564b62e15c1ea3feada5b2f9b6ec4d98b40c6b.zip opie-22564b62e15c1ea3feada5b2f9b6ec4d98b40c6b.tar.gz opie-22564b62e15c1ea3feada5b2f9b6ec4d98b40c6b.tar.bz2 |
some more display beauty
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 14 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.h | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index d4c5150..ed77eb5 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,415 +1,429 @@ | |||
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 <qfile.h> | 6 | #include <qfile.h> |
7 | #include <qapplication.h> | 7 | #include <qapplication.h> |
8 | #include <qvaluelist.h> | 8 | #include <qvaluelist.h> |
9 | 9 | ||
10 | #include <qpe/config.h> | 10 | #include <qpe/config.h> |
11 | 11 | ||
12 | #include <opie/ofiledialog.h> | 12 | #include <opie/ofiledialog.h> |
13 | 13 | ||
14 | #include "settings.h" | 14 | #include "settings.h" |
15 | #include "composemail.h" | 15 | #include "composemail.h" |
16 | #include "viewmail.h" | 16 | #include "viewmail.h" |
17 | #include "abstractmail.h" | 17 | #include "abstractmail.h" |
18 | #include "accountview.h" | 18 | #include "accountview.h" |
19 | #include "mailtypes.h" | 19 | #include "mailtypes.h" |
20 | 20 | ||
21 | 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, |
22 | const QString&fsize,int num,const QValueList<int>&path) | 22 | const QString&fsize,int num,const QValueList<int>&path) |
23 | : QListViewItem(parent,after),_partNum(num) | 23 | : QListViewItem(parent,after),_partNum(num) |
24 | { | 24 | { |
25 | _path=path; | 25 | _path=path; |
26 | setText(0, mime); | 26 | setText(0, mime); |
27 | setText(1, desc); | 27 | setText(1, desc); |
28 | setText(2, file); | 28 | setText(2, file); |
29 | setText(3, fsize); | 29 | setText(3, fsize); |
30 | } | 30 | } |
31 | 31 | ||
32 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 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) | 33 | const QString&fsize,int num,const QValueList<int>&path) |
34 | : QListViewItem(parent,after),_partNum(num) | 34 | : QListViewItem(parent,after),_partNum(num) |
35 | { | 35 | { |
36 | _path=path; | 36 | _path=path; |
37 | setText(0, mime); | 37 | setText(0, mime); |
38 | setText(1, desc); | 38 | setText(1, desc); |
39 | setText(2, file); | 39 | setText(2, file); |
40 | setText(3, fsize); | 40 | setText(3, fsize); |
41 | } | 41 | } |
42 | 42 | ||
43 | bool AttachItem::isParentof(const QValueList<int>&path) | 43 | bool AttachItem::isParentof(const QValueList<int>&path) |
44 | { | 44 | { |
45 | /* if not set, then no parent */ | 45 | /* if not set, then no parent */ |
46 | if (path.count()==0||_path.count()==0) return false; | 46 | if (path.count()==0||_path.count()==0) return false; |
47 | /* the parent must have one digit less then a child */ | 47 | /* the parent must have one digit less then a child */ |
48 | if (path.count()!=_path.count()+1) return false; | 48 | if (path.count()!=_path.count()+1) return false; |
49 | for (unsigned int i=0; i < _path.count();++i) { | 49 | for (unsigned int i=0; i < _path.count();++i) { |
50 | if (_path[i]!=path[i]) return false; | 50 | if (_path[i]!=path[i]) return false; |
51 | } | 51 | } |
52 | return true; | 52 | return true; |
53 | } | 53 | } |
54 | 54 | ||
55 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) | 55 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) |
56 | { | 56 | { |
57 | QListViewItemIterator it( attachments ); | 57 | QListViewItemIterator it( attachments ); |
58 | for ( ; it.current(); ++it ) { | 58 | for ( ; it.current(); ++it ) { |
59 | AttachItem*ati = (AttachItem*)it.current(); | 59 | AttachItem*ati = (AttachItem*)it.current(); |
60 | if (ati->isParentof(path)) return ati; | 60 | if (ati->isParentof(path)) return ati; |
61 | } | 61 | } |
62 | return 0; | 62 | return 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | AttachItem* ViewMail::lastChild(AttachItem*parent) | ||
66 | { | ||
67 | if (!parent) return 0; | ||
68 | AttachItem* item = (AttachItem*)parent->firstChild(); | ||
69 | if (!item) return item; | ||
70 | AttachItem*temp=0; | ||
71 | while( (temp=(AttachItem*)item->nextSibling())) { | ||
72 | item = temp; | ||
73 | } | ||
74 | return item; | ||
75 | } | ||
76 | |||
65 | void ViewMail::setBody( RecBody body ) { | 77 | void ViewMail::setBody( RecBody body ) { |
66 | 78 | ||
67 | m_body = body; | 79 | m_body = body; |
68 | m_mail[2] = body.Bodytext(); | 80 | m_mail[2] = body.Bodytext(); |
69 | attachbutton->setEnabled(body.Parts().count()>0); | 81 | attachbutton->setEnabled(body.Parts().count()>0); |
70 | attachments->setEnabled(body.Parts().count()>0); | 82 | attachments->setEnabled(body.Parts().count()>0); |
71 | if (body.Parts().count()==0) { | 83 | if (body.Parts().count()==0) { |
72 | return; | 84 | return; |
73 | } | 85 | } |
74 | AttachItem * curItem=0; | 86 | AttachItem * curItem=0; |
75 | AttachItem * parentItem = 0; | 87 | AttachItem * parentItem = 0; |
76 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); | 88 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); |
77 | QString desc,fsize; | 89 | QString desc,fsize; |
78 | double s = body.Description().Size(); | 90 | double s = body.Description().Size(); |
79 | int w; | 91 | int w; |
80 | w=0; | 92 | w=0; |
81 | 93 | ||
82 | while (s>1024) { | 94 | while (s>1024) { |
83 | s/=1024; | 95 | s/=1024; |
84 | ++w; | 96 | ++w; |
85 | if (w>=2) break; | 97 | if (w>=2) break; |
86 | } | 98 | } |
87 | 99 | ||
88 | QString q=""; | 100 | QString q=""; |
89 | switch(w) { | 101 | switch(w) { |
90 | case 1: | 102 | case 1: |
91 | q="k"; | 103 | q="k"; |
92 | break; | 104 | break; |
93 | case 2: | 105 | case 2: |
94 | q="M"; | 106 | q="M"; |
95 | break; | 107 | break; |
96 | default: | 108 | default: |
97 | break; | 109 | break; |
98 | } | 110 | } |
99 | 111 | ||
100 | { | 112 | { |
101 | /* I did not found a method to make a CONTENT reset on a QTextStream | 113 | /* I did not found a method to make a CONTENT reset on a QTextStream |
102 | so I use this construct that the stream will re-constructed in each | 114 | so I use this construct that the stream will re-constructed in each |
103 | loop. To let it work, the textstream is packed into a own area of | 115 | loop. To let it work, the textstream is packed into a own area of |
104 | code is it will be destructed after finishing its small job. | 116 | code is it will be destructed after finishing its small job. |
105 | */ | 117 | */ |
106 | QTextOStream o(&fsize); | 118 | QTextOStream o(&fsize); |
107 | if (w>0) o.precision(2); else o.precision(0); | 119 | if (w>0) o.precision(2); else o.precision(0); |
108 | o.setf(QTextStream::fixed); | 120 | o.setf(QTextStream::fixed); |
109 | o << s << " " << q << "Byte"; | 121 | o << s << " " << q << "Byte"; |
110 | } | 122 | } |
111 | 123 | ||
112 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist()); | 124 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist()); |
113 | QString filename = ""; | 125 | QString filename = ""; |
114 | 126 | ||
115 | for (unsigned int i = 0; i < body.Parts().count();++i) { | 127 | for (unsigned int i = 0; i < body.Parts().count();++i) { |
116 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | 128 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); |
117 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | 129 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); |
118 | for (;it!=body.Parts()[i].Parameters().end();++it) { | 130 | for (;it!=body.Parts()[i].Parameters().end();++it) { |
119 | qDebug(it.key()); | 131 | qDebug(it.key()); |
120 | if (it.key().lower()=="name") { | 132 | if (it.key().lower()=="name") { |
121 | filename=it.data(); | 133 | filename=it.data(); |
122 | } | 134 | } |
123 | } | 135 | } |
124 | s = body.Parts()[i].Size(); | 136 | s = body.Parts()[i].Size(); |
125 | w = 0; | 137 | w = 0; |
126 | while (s>1024) { | 138 | while (s>1024) { |
127 | s/=1024; | 139 | s/=1024; |
128 | ++w; | 140 | ++w; |
129 | if (w>=2) break; | 141 | if (w>=2) break; |
130 | } | 142 | } |
131 | switch(w) { | 143 | switch(w) { |
132 | case 1: | 144 | case 1: |
133 | q="k"; | 145 | q="k"; |
134 | break; | 146 | break; |
135 | case 2: | 147 | case 2: |
136 | q="M"; | 148 | q="M"; |
137 | break; | 149 | break; |
138 | default: | 150 | default: |
139 | q=""; | 151 | q=""; |
140 | break; | 152 | break; |
141 | } | 153 | } |
142 | QTextOStream o(&fsize); | 154 | QTextOStream o(&fsize); |
143 | if (w>0) o.precision(2); else o.precision(0); | 155 | if (w>0) o.precision(2); else o.precision(0); |
144 | o.setf(QTextStream::fixed); | 156 | o.setf(QTextStream::fixed); |
145 | o << s << " " << q << "Byte"; | 157 | o << s << " " << q << "Byte"; |
146 | desc = body.Parts()[i].Description(); | 158 | desc = body.Parts()[i].Description(); |
147 | parentItem = searchParent(body.Parts()[i].Positionlist()); | 159 | parentItem = searchParent(body.Parts()[i].Positionlist()); |
148 | if (parentItem) { | 160 | if (parentItem) { |
161 | AttachItem*temp = lastChild(parentItem); | ||
162 | if (temp) curItem = temp; | ||
149 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); | 163 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); |
150 | attachments->setRootIsDecorated(true); | 164 | attachments->setRootIsDecorated(true); |
151 | curItem = parentItem; | 165 | curItem = parentItem; |
152 | } else { | 166 | } else { |
153 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); | 167 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); |
154 | } | 168 | } |
155 | } | 169 | } |
156 | } | 170 | } |
157 | 171 | ||
158 | 172 | ||
159 | void ViewMail::slotShowHtml( bool state ) { | 173 | void ViewMail::slotShowHtml( bool state ) { |
160 | m_showHtml = state; | 174 | m_showHtml = state; |
161 | setText(); | 175 | setText(); |
162 | } | 176 | } |
163 | 177 | ||
164 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) { | 178 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) { |
165 | if (!item ) | 179 | if (!item ) |
166 | return; | 180 | return; |
167 | 181 | ||
168 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | 182 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { |
169 | setText(); | 183 | setText(); |
170 | return; | 184 | return; |
171 | } | 185 | } |
172 | QPopupMenu *menu = new QPopupMenu(); | 186 | QPopupMenu *menu = new QPopupMenu(); |
173 | int ret=0; | 187 | int ret=0; |
174 | 188 | ||
175 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) { | 189 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) { |
176 | menu->insertItem( tr( "Show Text" ), 1 ); | 190 | menu->insertItem( tr( "Show Text" ), 1 ); |
177 | } | 191 | } |
178 | menu->insertItem( tr( "Save Attachment" ), 0 ); | 192 | menu->insertItem( tr( "Save Attachment" ), 0 ); |
179 | menu->insertSeparator(1); | 193 | menu->insertSeparator(1); |
180 | 194 | ||
181 | ret = menu->exec( point, 0 ); | 195 | ret = menu->exec( point, 0 ); |
182 | 196 | ||
183 | switch(ret) { | 197 | switch(ret) { |
184 | case 0: | 198 | case 0: |
185 | { MimeTypes types; | 199 | { MimeTypes types; |
186 | types.insert( "all", "*" ); | 200 | types.insert( "all", "*" ); |
187 | QString str = OFileDialog::getSaveFileName( 1, | 201 | QString str = OFileDialog::getSaveFileName( 1, |
188 | "/", item->text( 2 ) , types, 0 ); | 202 | "/", item->text( 2 ) , types, 0 ); |
189 | 203 | ||
190 | if( !str.isEmpty() ) { | 204 | if( !str.isEmpty() ) { |
191 | encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 205 | encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
192 | if (content) { | 206 | if (content) { |
193 | QFile output(str); | 207 | QFile output(str); |
194 | output.open(IO_WriteOnly); | 208 | output.open(IO_WriteOnly); |
195 | output.writeBlock(content->Content(),content->Length()); | 209 | output.writeBlock(content->Content(),content->Length()); |
196 | output.close(); | 210 | output.close(); |
197 | delete content; | 211 | delete content; |
198 | } | 212 | } |
199 | } | 213 | } |
200 | } | 214 | } |
201 | break ; | 215 | break ; |
202 | 216 | ||
203 | case 1: | 217 | case 1: |
204 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | 218 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { |
205 | setText(); | 219 | setText(); |
206 | } else { | 220 | } else { |
207 | if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions | 221 | if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions |
208 | browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); | 222 | browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
209 | } | 223 | } |
210 | } | 224 | } |
211 | break; | 225 | break; |
212 | } | 226 | } |
213 | delete menu; | 227 | delete menu; |
214 | } | 228 | } |
215 | 229 | ||
216 | 230 | ||
217 | void ViewMail::setMail( RecMail mail ) { | 231 | void ViewMail::setMail( RecMail mail ) { |
218 | 232 | ||
219 | m_recMail = mail; | 233 | m_recMail = mail; |
220 | 234 | ||
221 | m_mail[0] = mail.getFrom(); | 235 | m_mail[0] = mail.getFrom(); |
222 | m_mail[1] = mail.getSubject(); | 236 | m_mail[1] = mail.getSubject(); |
223 | m_mail[3] = mail.getDate(); | 237 | m_mail[3] = mail.getDate(); |
224 | m_mail[4] = mail.Msgid(); | 238 | m_mail[4] = mail.Msgid(); |
225 | 239 | ||
226 | m_mail2[0] = mail.To(); | 240 | m_mail2[0] = mail.To(); |
227 | m_mail2[1] = mail.CC(); | 241 | m_mail2[1] = mail.CC(); |
228 | m_mail2[2] = mail.Bcc(); | 242 | m_mail2[2] = mail.Bcc(); |
229 | 243 | ||
230 | setText(); | 244 | setText(); |
231 | } | 245 | } |
232 | 246 | ||
233 | 247 | ||
234 | 248 | ||
235 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 249 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
236 | : ViewMailBase(parent, name, fl), _inLoop(false) | 250 | : ViewMailBase(parent, name, fl), _inLoop(false) |
237 | { | 251 | { |
238 | m_gotBody = false; | 252 | m_gotBody = false; |
239 | deleted = false; | 253 | deleted = false; |
240 | 254 | ||
241 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); | 255 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); |
242 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); | 256 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); |
243 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) ); | 257 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) ); |
244 | connect( showHtml, SIGNAL( toggled( bool ) ), SLOT( slotShowHtml( bool ) ) ); | 258 | connect( showHtml, SIGNAL( toggled( bool ) ), SLOT( slotShowHtml( bool ) ) ); |
245 | 259 | ||
246 | attachments->setEnabled(m_gotBody); | 260 | attachments->setEnabled(m_gotBody); |
247 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); | 261 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); |
248 | 262 | ||
249 | readConfig(); | 263 | readConfig(); |
250 | attachments->setSorting(-1); | 264 | attachments->setSorting(-1); |
251 | } | 265 | } |
252 | 266 | ||
253 | void ViewMail::readConfig() { | 267 | void ViewMail::readConfig() { |
254 | Config cfg( "mail" ); | 268 | Config cfg( "mail" ); |
255 | cfg.setGroup( "Settings" ); | 269 | cfg.setGroup( "Settings" ); |
256 | m_showHtml = cfg.readBoolEntry( "showHtml", false ); | 270 | m_showHtml = cfg.readBoolEntry( "showHtml", false ); |
257 | showHtml->setOn( m_showHtml ); | 271 | showHtml->setOn( m_showHtml ); |
258 | } | 272 | } |
259 | 273 | ||
260 | void ViewMail::setText() | 274 | void ViewMail::setText() |
261 | { | 275 | { |
262 | 276 | ||
263 | QString toString; | 277 | QString toString; |
264 | QString ccString; | 278 | QString ccString; |
265 | QString bccString; | 279 | QString bccString; |
266 | 280 | ||
267 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { | 281 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { |
268 | toString += (*it); | 282 | toString += (*it); |
269 | } | 283 | } |
270 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { | 284 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { |
271 | ccString += (*it); | 285 | ccString += (*it); |
272 | } | 286 | } |
273 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { | 287 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { |
274 | bccString += (*it); | 288 | bccString += (*it); |
275 | } | 289 | } |
276 | 290 | ||
277 | setCaption( caption().arg( m_mail[0] ) ); | 291 | setCaption( caption().arg( m_mail[0] ) ); |
278 | 292 | ||
279 | m_mailHtml = "<html><body>" | 293 | m_mailHtml = "<html><body>" |
280 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 294 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
281 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 295 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
282 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 296 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
283 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 297 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
284 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 298 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
285 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 299 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
286 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + | 300 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + |
287 | "</td></tr></table><font face=fixed>"; | 301 | "</td></tr></table><font face=fixed>"; |
288 | 302 | ||
289 | if ( !m_showHtml ) { | 303 | if ( !m_showHtml ) { |
290 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 304 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
291 | } else { | 305 | } else { |
292 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); | 306 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); |
293 | } | 307 | } |
294 | // remove later in favor of a real handling | 308 | // remove later in favor of a real handling |
295 | m_gotBody = true; | 309 | m_gotBody = true; |
296 | } | 310 | } |
297 | 311 | ||
298 | 312 | ||
299 | ViewMail::~ViewMail() | 313 | ViewMail::~ViewMail() |
300 | { | 314 | { |
301 | m_recMail.Wrapper()->cleanMimeCache(); | 315 | m_recMail.Wrapper()->cleanMimeCache(); |
302 | hide(); | 316 | hide(); |
303 | } | 317 | } |
304 | 318 | ||
305 | void ViewMail::hide() | 319 | void ViewMail::hide() |
306 | { | 320 | { |
307 | QWidget::hide(); | 321 | QWidget::hide(); |
308 | 322 | ||
309 | if (_inLoop) { | 323 | if (_inLoop) { |
310 | _inLoop = false; | 324 | _inLoop = false; |
311 | qApp->exit_loop(); | 325 | qApp->exit_loop(); |
312 | 326 | ||
313 | } | 327 | } |
314 | 328 | ||
315 | } | 329 | } |
316 | 330 | ||
317 | void ViewMail::exec() | 331 | void ViewMail::exec() |
318 | { | 332 | { |
319 | show(); | 333 | show(); |
320 | 334 | ||
321 | if (!_inLoop) { | 335 | if (!_inLoop) { |
322 | _inLoop = true; | 336 | _inLoop = true; |
323 | qApp->enter_loop(); | 337 | qApp->enter_loop(); |
324 | } | 338 | } |
325 | 339 | ||
326 | } | 340 | } |
327 | 341 | ||
328 | QString ViewMail::deHtml(const QString &string) | 342 | QString ViewMail::deHtml(const QString &string) |
329 | { | 343 | { |
330 | QString string_ = string; | 344 | QString string_ = string; |
331 | string_.replace(QRegExp("&"), "&"); | 345 | string_.replace(QRegExp("&"), "&"); |
332 | string_.replace(QRegExp("<"), "<"); | 346 | string_.replace(QRegExp("<"), "<"); |
333 | string_.replace(QRegExp(">"), ">"); | 347 | string_.replace(QRegExp(">"), ">"); |
334 | string_.replace(QRegExp("\\n"), "<br>"); | 348 | string_.replace(QRegExp("\\n"), "<br>"); |
335 | return string_; | 349 | return string_; |
336 | } | 350 | } |
337 | 351 | ||
338 | void ViewMail::slotReply() | 352 | void ViewMail::slotReply() |
339 | { | 353 | { |
340 | if (!m_gotBody) { | 354 | if (!m_gotBody) { |
341 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); | 355 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); |
342 | return; | 356 | return; |
343 | } | 357 | } |
344 | 358 | ||
345 | QString rtext; | 359 | QString rtext; |
346 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 360 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
347 | .arg( m_mail[0] ) | 361 | .arg( m_mail[0] ) |
348 | .arg( m_mail[3] ); | 362 | .arg( m_mail[3] ); |
349 | 363 | ||
350 | QString text = m_mail[2]; | 364 | QString text = m_mail[2]; |
351 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 365 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
352 | QStringList::Iterator it; | 366 | QStringList::Iterator it; |
353 | for (it = lines.begin(); it != lines.end(); it++) { | 367 | for (it = lines.begin(); it != lines.end(); it++) { |
354 | rtext += "> " + *it + "\n"; | 368 | rtext += "> " + *it + "\n"; |
355 | } | 369 | } |
356 | rtext += "\n"; | 370 | rtext += "\n"; |
357 | 371 | ||
358 | QString prefix; | 372 | QString prefix; |
359 | if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; | 373 | if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; |
360 | else prefix = "Re: "; // no i18n on purpose | 374 | else prefix = "Re: "; // no i18n on purpose |
361 | 375 | ||
362 | Settings *settings = new Settings(); | 376 | Settings *settings = new Settings(); |
363 | ComposeMail composer( settings ,this, 0, true); | 377 | ComposeMail composer( settings ,this, 0, true); |
364 | composer.setTo( m_mail[0] ); | 378 | composer.setTo( m_mail[0] ); |
365 | composer.setSubject( "Re: " + m_mail[1] ); | 379 | composer.setSubject( "Re: " + m_mail[1] ); |
366 | composer.setMessage( rtext ); | 380 | composer.setMessage( rtext ); |
367 | composer.showMaximized(); | 381 | composer.showMaximized(); |
368 | if ( QDialog::Accepted==composer.exec()) { | 382 | if ( QDialog::Accepted==composer.exec()) { |
369 | m_recMail.Wrapper()->answeredMail(m_recMail); | 383 | m_recMail.Wrapper()->answeredMail(m_recMail); |
370 | } | 384 | } |
371 | } | 385 | } |
372 | 386 | ||
373 | void ViewMail::slotForward() | 387 | void ViewMail::slotForward() |
374 | { | 388 | { |
375 | if (!m_gotBody) { | 389 | if (!m_gotBody) { |
376 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); | 390 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); |
377 | return; | 391 | return; |
378 | } | 392 | } |
379 | 393 | ||
380 | QString ftext; | 394 | QString ftext; |
381 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") | 395 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") |
382 | .arg( m_mail[0] ); | 396 | .arg( m_mail[0] ); |
383 | if (!m_mail[3].isNull()) | 397 | if (!m_mail[3].isNull()) |
384 | ftext += QString("Date: %1\n") | 398 | ftext += QString("Date: %1\n") |
385 | .arg( m_mail[3] ); | 399 | .arg( m_mail[3] ); |
386 | if (!m_mail[0].isNull()) | 400 | if (!m_mail[0].isNull()) |
387 | ftext += QString("From: %1\n") | 401 | ftext += QString("From: %1\n") |
388 | .arg( m_mail[0] ); | 402 | .arg( m_mail[0] ); |
389 | if (!m_mail[1].isNull()) | 403 | if (!m_mail[1].isNull()) |
390 | ftext += QString("Subject: %1\n") | 404 | ftext += QString("Subject: %1\n") |
391 | .arg( m_mail[1] ); | 405 | .arg( m_mail[1] ); |
392 | 406 | ||
393 | ftext += QString("\n%1\n") | 407 | ftext += QString("\n%1\n") |
394 | .arg( m_mail[2]); | 408 | .arg( m_mail[2]); |
395 | 409 | ||
396 | ftext += QString("----- End forwarded message -----\n"); | 410 | ftext += QString("----- End forwarded message -----\n"); |
397 | 411 | ||
398 | Settings *settings = new Settings(); | 412 | Settings *settings = new Settings(); |
399 | ComposeMail composer( settings ,this, 0, true); | 413 | ComposeMail composer( settings ,this, 0, true); |
400 | composer.setSubject( "Fwd: " + m_mail[1] ); | 414 | composer.setSubject( "Fwd: " + m_mail[1] ); |
401 | composer.setMessage( ftext ); | 415 | composer.setMessage( ftext ); |
402 | composer.showMaximized(); | 416 | composer.showMaximized(); |
403 | if ( QDialog::Accepted==composer.exec()) { | 417 | if ( QDialog::Accepted==composer.exec()) { |
404 | 418 | ||
405 | } | 419 | } |
406 | } | 420 | } |
407 | 421 | ||
408 | void ViewMail::slotDeleteMail( ) | 422 | void ViewMail::slotDeleteMail( ) |
409 | { | 423 | { |
410 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 424 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { |
411 | m_recMail.Wrapper()->deleteMail( m_recMail ); | 425 | m_recMail.Wrapper()->deleteMail( m_recMail ); |
412 | hide(); | 426 | hide(); |
413 | deleted = true; | 427 | deleted = true; |
414 | } | 428 | } |
415 | } | 429 | } |
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h index b3d3b4e..29681cc 100644 --- a/noncore/net/mail/viewmail.h +++ b/noncore/net/mail/viewmail.h | |||
@@ -1,71 +1,72 @@ | |||
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 | #include <qvaluelist.h> |
8 | 8 | ||
9 | #include "viewmailbase.h" | 9 | #include "viewmailbase.h" |
10 | #include "mailtypes.h" | 10 | #include "mailtypes.h" |
11 | 11 | ||
12 | class AttachItem : public QListViewItem | 12 | class AttachItem : public QListViewItem |
13 | { | 13 | { |
14 | public: | 14 | public: |
15 | 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, |
16 | const QString&fsize,int num,const QValueList<int>&path); | 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, | 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); | 18 | const QString&fsize,int num,const QValueList<int>&path); |
19 | int Partnumber() { return _partNum; } | 19 | int Partnumber() { return _partNum; } |
20 | bool isParentof(const QValueList<int>&path); | 20 | bool isParentof(const QValueList<int>&path); |
21 | 21 | ||
22 | private: | 22 | private: |
23 | int _partNum; | 23 | int _partNum; |
24 | /* needed for a better display of attachments */ | 24 | /* needed for a better display of attachments */ |
25 | QValueList<int> _path; | 25 | QValueList<int> _path; |
26 | }; | 26 | }; |
27 | 27 | ||
28 | class ViewMail : public ViewMailBase | 28 | class ViewMail : public ViewMailBase |
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | 31 | ||
32 | public: | 32 | public: |
33 | ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal); | 33 | ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal); |
34 | ~ViewMail(); | 34 | ~ViewMail(); |
35 | 35 | ||
36 | void hide(); | 36 | void hide(); |
37 | void exec(); | 37 | void exec(); |
38 | void setMail( RecMail mail ); | 38 | void setMail( RecMail mail ); |
39 | void setBody( RecBody body ); | 39 | void setBody( RecBody body ); |
40 | bool deleted; | 40 | bool deleted; |
41 | 41 | ||
42 | protected: | 42 | protected: |
43 | QString deHtml(const QString &string); | 43 | QString deHtml(const QString &string); |
44 | AttachItem* searchParent(const QValueList<int>&path); | 44 | AttachItem* searchParent(const QValueList<int>&path); |
45 | AttachItem* lastChild(AttachItem*parent); | ||
45 | 46 | ||
46 | protected slots: | 47 | protected slots: |
47 | void slotReply(); | 48 | void slotReply(); |
48 | void slotForward(); | 49 | void slotForward(); |
49 | void setText(); | 50 | void setText(); |
50 | void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); | 51 | void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); |
51 | void slotDeleteMail( ); | 52 | void slotDeleteMail( ); |
52 | void slotShowHtml( bool ); | 53 | void slotShowHtml( bool ); |
53 | 54 | ||
54 | private: | 55 | private: |
55 | void readConfig(); | 56 | void readConfig(); |
56 | 57 | ||
57 | bool _inLoop; | 58 | bool _inLoop; |
58 | QString m_mailHtml; | 59 | QString m_mailHtml; |
59 | bool m_gotBody; | 60 | bool m_gotBody; |
60 | RecBody m_body; | 61 | RecBody m_body; |
61 | RecMail m_recMail; | 62 | RecMail m_recMail; |
62 | bool m_showHtml; | 63 | bool m_showHtml; |
63 | 64 | ||
64 | // 0 from 1 subject 2 bodytext 3 date | 65 | // 0 from 1 subject 2 bodytext 3 date |
65 | QMap <int,QString> m_mail; | 66 | QMap <int,QString> m_mail; |
66 | // 0 to 1 cc 2 bcc | 67 | // 0 to 1 cc 2 bcc |
67 | QMap <int,QStringList> m_mail2; | 68 | QMap <int,QStringList> m_mail2; |
68 | 69 | ||
69 | }; | 70 | }; |
70 | 71 | ||
71 | #endif | 72 | #endif |