-rw-r--r-- | kmicromail/viewmail.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/kmicromail/viewmail.cpp b/kmicromail/viewmail.cpp index 60c764c..6d88cad 100644 --- a/kmicromail/viewmail.cpp +++ b/kmicromail/viewmail.cpp | |||
@@ -1,533 +1,534 @@ | |||
1 | // CHANGED 2004-08-06 Lutz Rogowski | 1 | // CHANGED 2004-08-06 Lutz Rogowski |
2 | 2 | ||
3 | 3 | ||
4 | 4 | ||
5 | #include <kfiledialog.h> | 5 | #include <kfiledialog.h> |
6 | #include "koprefs.h" | 6 | #include "koprefs.h" |
7 | #include <klocale.h> | 7 | #include <klocale.h> |
8 | #include <kglobal.h> | 8 | #include <kglobal.h> |
9 | #include <kapplication.h> | 9 | #include <kapplication.h> |
10 | 10 | ||
11 | #ifdef MINIKDE_KDIALOG_H | 11 | #ifdef MINIKDE_KDIALOG_H |
12 | #undef MINIKDE_KDIALOG_H | 12 | #undef MINIKDE_KDIALOG_H |
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | #include "composemail.h" | 15 | #include "composemail.h" |
16 | #include "viewmail.h" | 16 | #include "viewmail.h" |
17 | 17 | ||
18 | #include <libmailwrapper/settings.h> | 18 | #include <libmailwrapper/settings.h> |
19 | #include <libmailwrapper/abstractmail.h> | 19 | #include <libmailwrapper/abstractmail.h> |
20 | #include <libmailwrapper/mailtypes.h> | 20 | #include <libmailwrapper/mailtypes.h> |
21 | 21 | ||
22 | #include <qdialog.h> | 22 | #include <qdialog.h> |
23 | 23 | ||
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | 25 | ||
26 | /* QT */ | 26 | /* QT */ |
27 | #include <qtextbrowser.h> | 27 | #include <qtextbrowser.h> |
28 | #include <qmessagebox.h> | 28 | #include <qmessagebox.h> |
29 | #include <qtextstream.h> | 29 | #include <qtextstream.h> |
30 | #include <qaction.h> | 30 | #include <qaction.h> |
31 | #include <qpopupmenu.h> | 31 | #include <qpopupmenu.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qlayout.h> | 33 | #include <qlayout.h> |
34 | 34 | ||
35 | //using namespace Opie::Ui; | 35 | //using namespace Opie::Ui; |
36 | //using namespace Opie::Core; | 36 | //using namespace Opie::Core; |
37 | 37 | ||
38 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 38 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
39 | const QString&fsize,int num,const QValueList<int>&path) | 39 | const QString&fsize,int num,const QValueList<int>&path) |
40 | : QListViewItem(parent,after),_partNum(num) | 40 | : QListViewItem(parent,after),_partNum(num) |
41 | { | 41 | { |
42 | _path=path; | 42 | _path=path; |
43 | setText(0, mime); | 43 | setText(0, mime); |
44 | setText(1, desc); | 44 | setText(1, desc); |
45 | setText(2, file); | 45 | setText(2, file); |
46 | setText(3, fsize); | 46 | setText(3, fsize); |
47 | } | 47 | } |
48 | 48 | ||
49 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 49 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
50 | const QString&fsize,int num,const QValueList<int>&path) | 50 | const QString&fsize,int num,const QValueList<int>&path) |
51 | : QListViewItem(parent,after),_partNum(num) | 51 | : QListViewItem(parent,after),_partNum(num) |
52 | { | 52 | { |
53 | _path=path; | 53 | _path=path; |
54 | setText(0, mime); | 54 | setText(0, mime); |
55 | setText(1, desc); | 55 | setText(1, desc); |
56 | setText(2, file); | 56 | setText(2, file); |
57 | setText(3, fsize); | 57 | setText(3, fsize); |
58 | } | 58 | } |
59 | 59 | ||
60 | bool AttachItem::isParentof(const QValueList<int>&path) | 60 | bool AttachItem::isParentof(const QValueList<int>&path) |
61 | { | 61 | { |
62 | /* if not set, then no parent */ | 62 | /* if not set, then no parent */ |
63 | if (path.count()==0||_path.count()==0) return false; | 63 | if (path.count()==0||_path.count()==0) return false; |
64 | /* the parent must have one digit less then a child */ | 64 | /* the parent must have one digit less then a child */ |
65 | if (path.count()!=_path.count()+1) return false; | 65 | if (path.count()!=_path.count()+1) return false; |
66 | for (unsigned int i=0; i < _path.count();++i) | 66 | for (unsigned int i=0; i < _path.count();++i) |
67 | { | 67 | { |
68 | if (_path[i]!=path[i]) return false; | 68 | if (_path[i]!=path[i]) return false; |
69 | } | 69 | } |
70 | return true; | 70 | return true; |
71 | } | 71 | } |
72 | 72 | ||
73 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) | 73 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) |
74 | { | 74 | { |
75 | QListViewItemIterator it( attachments ); | 75 | QListViewItemIterator it( attachments ); |
76 | for ( ; it.current(); ++it ) | 76 | for ( ; it.current(); ++it ) |
77 | { | 77 | { |
78 | AttachItem*ati = (AttachItem*)it.current(); | 78 | AttachItem*ati = (AttachItem*)it.current(); |
79 | if (ati->isParentof(path)) return ati; | 79 | if (ati->isParentof(path)) return ati; |
80 | } | 80 | } |
81 | return 0; | 81 | return 0; |
82 | } | 82 | } |
83 | 83 | ||
84 | AttachItem* ViewMail::lastChild(AttachItem*parent) | 84 | AttachItem* ViewMail::lastChild(AttachItem*parent) |
85 | { | 85 | { |
86 | if (!parent) return 0; | 86 | if (!parent) return 0; |
87 | AttachItem* item = (AttachItem*)parent->firstChild(); | 87 | AttachItem* item = (AttachItem*)parent->firstChild(); |
88 | if (!item) return item; | 88 | if (!item) return item; |
89 | AttachItem*temp=0; | 89 | AttachItem*temp=0; |
90 | while( (temp=(AttachItem*)item->nextSibling())) | 90 | while( (temp=(AttachItem*)item->nextSibling())) |
91 | { | 91 | { |
92 | item = temp; | 92 | item = temp; |
93 | } | 93 | } |
94 | return item; | 94 | return item; |
95 | } | 95 | } |
96 | 96 | ||
97 | void ViewMail::setBody(const RecBodyP&body ) | 97 | void ViewMail::setBody(const RecBodyP&body ) |
98 | { | 98 | { |
99 | 99 | ||
100 | m_body = body; | 100 | m_body = body; |
101 | m_mail[2] = body->Bodytext(); | 101 | m_mail[2] = body->Bodytext(); |
102 | // qDebug("********text %s ",m_mail[2].latin1() ); | 102 | // qDebug("********text %s ",m_mail[2].latin1() ); |
103 | attachbutton->setEnabled(body->Parts().count()>0); | 103 | attachbutton->setEnabled(body->Parts().count()>0); |
104 | attachments->setEnabled(body->Parts().count()>0); | 104 | attachments->setEnabled(body->Parts().count()>0); |
105 | if (body->Parts().count()==0) | 105 | if (body->Parts().count()==0) |
106 | { | 106 | { |
107 | return; | 107 | return; |
108 | } | 108 | } |
109 | AttachItem * curItem=0; | 109 | AttachItem * curItem=0; |
110 | AttachItem * parentItem = 0; | 110 | AttachItem * parentItem = 0; |
111 | QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); | 111 | QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); |
112 | QString desc,fsize; | 112 | QString desc,fsize; |
113 | double s = body->Description()->Size(); | 113 | double s = body->Description()->Size(); |
114 | int w; | 114 | int w; |
115 | w=0; | 115 | w=0; |
116 | 116 | ||
117 | while (s>1024) | 117 | while (s>1024) |
118 | { | 118 | { |
119 | s/=1024; | 119 | s/=1024; |
120 | ++w; | 120 | ++w; |
121 | if (w>=2) break; | 121 | if (w>=2) break; |
122 | } | 122 | } |
123 | 123 | ||
124 | QString q=""; | 124 | QString q=""; |
125 | switch(w) | 125 | switch(w) |
126 | { | 126 | { |
127 | case 1: | 127 | case 1: |
128 | q="k"; | 128 | q="k"; |
129 | break; | 129 | break; |
130 | case 2: | 130 | case 2: |
131 | q="M"; | 131 | q="M"; |
132 | break; | 132 | break; |
133 | default: | 133 | default: |
134 | break; | 134 | break; |
135 | } | 135 | } |
136 | 136 | ||
137 | { | 137 | { |
138 | /* I did not found a method to make a CONTENT reset on a QTextStream | 138 | /* I did not found a method to make a CONTENT reset on a QTextStream |
139 | so I use this construct that the stream will re-constructed in each | 139 | so I use this construct that the stream will re-constructed in each |
140 | loop. To let it work, the textstream is packed into a own area of | 140 | loop. To let it work, the textstream is packed into a own area of |
141 | code is it will be destructed after finishing its small job. | 141 | code is it will be destructed after finishing its small job. |
142 | */ | 142 | */ |
143 | QTextOStream o(&fsize); | 143 | QTextOStream o(&fsize); |
144 | if (w>0) o.precision(2); else o.precision(0); | 144 | if (w>0) o.precision(2); else o.precision(0); |
145 | o.setf(QTextStream::fixed); | 145 | o.setf(QTextStream::fixed); |
146 | o << s << " " << q << "Byte"; | 146 | o << s << " " << q << "Byte"; |
147 | } | 147 | } |
148 | 148 | ||
149 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); | 149 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); |
150 | QString filename = ""; | 150 | QString filename = ""; |
151 | 151 | ||
152 | for (unsigned int i = 0; i < body->Parts().count();++i) | 152 | for (unsigned int i = 0; i < body->Parts().count();++i) |
153 | { | 153 | { |
154 | filename = ""; | 154 | filename = ""; |
155 | type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); | 155 | type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); |
156 | part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); | 156 | part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); |
157 | for (;it!=body->Parts()[i]->Parameters().end();++it) | 157 | for (;it!=body->Parts()[i]->Parameters().end();++it) |
158 | { | 158 | { |
159 | if (it.key().lower()=="name") | 159 | if (it.key().lower()=="name") |
160 | { | 160 | { |
161 | filename=it.data(); | 161 | filename=it.data(); |
162 | } | 162 | } |
163 | } | 163 | } |
164 | s = body->Parts()[i]->Size(); | 164 | s = body->Parts()[i]->Size(); |
165 | w = 0; | 165 | w = 0; |
166 | while (s>1024) | 166 | while (s>1024) |
167 | { | 167 | { |
168 | s/=1024; | 168 | s/=1024; |
169 | ++w; | 169 | ++w; |
170 | if (w>=2) break; | 170 | if (w>=2) break; |
171 | } | 171 | } |
172 | switch(w) | 172 | switch(w) |
173 | { | 173 | { |
174 | case 1: | 174 | case 1: |
175 | q="k"; | 175 | q="k"; |
176 | break; | 176 | break; |
177 | case 2: | 177 | case 2: |
178 | q="M"; | 178 | q="M"; |
179 | break; | 179 | break; |
180 | default: | 180 | default: |
181 | q=""; | 181 | q=""; |
182 | break; | 182 | break; |
183 | } | 183 | } |
184 | QTextOStream o(&fsize); | 184 | QTextOStream o(&fsize); |
185 | if (w>0) o.precision(2); else o.precision(0); | 185 | if (w>0) o.precision(2); else o.precision(0); |
186 | o.setf(QTextStream::fixed); | 186 | o.setf(QTextStream::fixed); |
187 | o << s << " " << q << "Byte"; | 187 | o << s << " " << q << "Byte"; |
188 | desc = body->Parts()[i]->Description(); | 188 | desc = body->Parts()[i]->Description(); |
189 | parentItem = searchParent(body->Parts()[i]->Positionlist()); | 189 | parentItem = searchParent(body->Parts()[i]->Positionlist()); |
190 | if (parentItem) | 190 | if (parentItem) |
191 | { | 191 | { |
192 | AttachItem*temp = lastChild(parentItem); | 192 | AttachItem*temp = lastChild(parentItem); |
193 | if (temp) curItem = temp; | 193 | if (temp) curItem = temp; |
194 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); | 194 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); |
195 | attachments->setRootIsDecorated(true); | 195 | attachments->setRootIsDecorated(true); |
196 | curItem = parentItem; | 196 | curItem = parentItem; |
197 | } | 197 | } |
198 | else | 198 | else |
199 | { | 199 | { |
200 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); | 200 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); |
201 | } | 201 | } |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
206 | void ViewMail::slotShowHtml( bool state ) | 206 | void ViewMail::slotShowHtml( bool state ) |
207 | { | 207 | { |
208 | m_showHtml = state; | 208 | m_showHtml = state; |
209 | setText(); | 209 | setText(); |
210 | } | 210 | } |
211 | 211 | ||
212 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) | 212 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) |
213 | { | 213 | { |
214 | if (!item ) | 214 | if (!item ) |
215 | return; | 215 | return; |
216 | 216 | ||
217 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 217 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
218 | { | 218 | { |
219 | setText(); | 219 | setText(); |
220 | return; | 220 | return; |
221 | } | 221 | } |
222 | QPopupMenu *menu = new QPopupMenu(); | 222 | QPopupMenu *menu = new QPopupMenu(); |
223 | int ret=0; | 223 | int ret=0; |
224 | 224 | ||
225 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) | 225 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) |
226 | { | 226 | { |
227 | menu->insertItem( i18n( "Show Text" ), 1 ); | 227 | menu->insertItem( i18n( "Show Text" ), 1 ); |
228 | } | 228 | } |
229 | if (item->text(0).left(6)=="image/") { | 229 | if (item->text(0).left(6)=="image/") { |
230 | menu->insertItem(i18n("Display image preview"),2); | 230 | menu->insertItem(i18n("Display image preview"),2); |
231 | } | 231 | } |
232 | menu->insertItem( i18n( "Save Attachment" ), 0 ); | 232 | menu->insertItem( i18n( "Save Attachment" ), 0 ); |
233 | menu->insertSeparator(1); | 233 | menu->insertSeparator(1); |
234 | 234 | ||
235 | ret = menu->exec( point, 0 ); | 235 | ret = menu->exec( point, 0 ); |
236 | 236 | ||
237 | switch(ret) | 237 | switch(ret) |
238 | { | 238 | { |
239 | case 0: | 239 | case 0: |
240 | { | 240 | { |
241 | //MimeTypes types; | 241 | //MimeTypes types; |
242 | //types.insert( "all", "*" ); | 242 | //types.insert( "all", "*" ); |
243 | QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this ); | 243 | QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this ); |
244 | 244 | ||
245 | if( !str.isEmpty() ) | 245 | if( !str.isEmpty() ) |
246 | { | 246 | { |
247 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 247 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
248 | if (content) | 248 | if (content) |
249 | { | 249 | { |
250 | QFile output(str); | 250 | QFile output(str); |
251 | output.open(IO_WriteOnly); | 251 | output.open(IO_WriteOnly); |
252 | output.writeBlock(content->Content(),content->Length()); | 252 | output.writeBlock(content->Content(),content->Length()); |
253 | output.close(); | 253 | output.close(); |
254 | delete content; | 254 | delete content; |
255 | } | 255 | } |
256 | } | 256 | } |
257 | } | 257 | } |
258 | break ; | 258 | break ; |
259 | 259 | ||
260 | case 2: | 260 | case 2: |
261 | { | 261 | { |
262 | #ifdef DESKTOP_VERSION | 262 | #ifdef DESKTOP_VERSION |
263 | QString tmpfile = locateLocal( "tmp", "opiemail-image"); | 263 | QString tmpfile = locateLocal( "tmp", "opiemail-image"); |
264 | #else | 264 | #else |
265 | QString tmpfile = "/tmp/opiemail-image"; | 265 | QString tmpfile = "/tmp/opiemail-image"; |
266 | #endif | 266 | #endif |
267 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 267 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
268 | if (content) { | 268 | if (content) { |
269 | QFile output(tmpfile); | 269 | QFile output(tmpfile); |
270 | output.open(IO_WriteOnly); | 270 | output.open(IO_WriteOnly); |
271 | output.writeBlock(content->Content(),content->Length()); | 271 | output.writeBlock(content->Content(),content->Length()); |
272 | output.close(); | 272 | output.close(); |
273 | delete content; | 273 | delete content; |
274 | MailImageDlg iview(""); | 274 | MailImageDlg iview(""); |
275 | iview.setName(tmpfile); | 275 | iview.setName(tmpfile); |
276 | KApplication::execDialog(&iview); | 276 | KApplication::execDialog(&iview); |
277 | output.remove(); | 277 | output.remove(); |
278 | } | 278 | } |
279 | } | 279 | } |
280 | break; | 280 | break; |
281 | case 1: | 281 | case 1: |
282 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 282 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
283 | { | 283 | { |
284 | setText(); | 284 | setText(); |
285 | } | 285 | } |
286 | else | 286 | else |
287 | { | 287 | { |
288 | if ( m_recMail->Wrapper() != 0l ) | 288 | if ( m_recMail->Wrapper() != 0l ) |
289 | { // make sure that there is a wrapper , even after delete or simular actions | 289 | { // make sure that there is a wrapper , even after delete or simular actions |
290 | browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); | 290 | browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
291 | } | 291 | } |
292 | } | 292 | } |
293 | break; | 293 | break; |
294 | } | 294 | } |
295 | delete menu; | 295 | delete menu; |
296 | } | 296 | } |
297 | 297 | ||
298 | 298 | ||
299 | void ViewMail::setMail(const RecMailP&mail ) | 299 | void ViewMail::setMail(const RecMailP&mail ) |
300 | { | 300 | { |
301 | 301 | ||
302 | m_recMail = mail; | 302 | m_recMail = mail; |
303 | 303 | ||
304 | m_mail[0] = mail->getFrom(); | 304 | m_mail[0] = mail->getFrom(); |
305 | m_mail[1] = mail->getSubject(); | 305 | m_mail[1] = mail->getSubject(); |
306 | m_mail[3] = mail->getDate(); | 306 | m_mail[3] = mail->getDate(); |
307 | m_mail[4] = mail->Msgid(); | 307 | m_mail[4] = mail->Msgid(); |
308 | 308 | ||
309 | m_mail2[0] = mail->To(); | 309 | m_mail2[0] = mail->To(); |
310 | m_mail2[1] = mail->CC(); | 310 | m_mail2[1] = mail->CC(); |
311 | m_mail2[2] = mail->Bcc(); | 311 | m_mail2[2] = mail->Bcc(); |
312 | 312 | ||
313 | setText(); | 313 | setText(); |
314 | } | 314 | } |
315 | 315 | ||
316 | 316 | ||
317 | 317 | ||
318 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 318 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
319 | : ViewMailBase(parent, name, fl), _inLoop(false) | 319 | : ViewMailBase(parent, name, fl), _inLoop(false) |
320 | { | 320 | { |
321 | m_gotBody = false; | 321 | m_gotBody = false; |
322 | deleted = false; | 322 | deleted = false; |
323 | 323 | ||
324 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); | 324 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); |
325 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); | 325 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); |
326 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); | 326 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); |
327 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); | 327 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); |
328 | connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); | 328 | connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); |
329 | connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) ); | 329 | connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) ); |
330 | 330 | ||
331 | attachments->setEnabled(m_gotBody); | 331 | attachments->setEnabled(m_gotBody); |
332 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); | 332 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); |
333 | 333 | ||
334 | readConfig(); | 334 | readConfig(); |
335 | attachments->setSorting(-1); | 335 | attachments->setSorting(-1); |
336 | } | 336 | } |
337 | 337 | ||
338 | void ViewMail::readConfig() | 338 | void ViewMail::readConfig() |
339 | { | 339 | { |
340 | 340 | ||
341 | setFont ( KOPrefs::instance()->mReadFont ); | 341 | setFont ( KOPrefs::instance()->mReadFont ); |
342 | m_showHtml = KOPrefs::instance()->mViewAsHtml; | 342 | m_showHtml = KOPrefs::instance()->mViewAsHtml; |
343 | showHtml->setOn( m_showHtml ); | 343 | showHtml->setOn( m_showHtml ); |
344 | } | 344 | } |
345 | 345 | ||
346 | void ViewMail::setText() | 346 | void ViewMail::setText() |
347 | { | 347 | { |
348 | 348 | ||
349 | QString toString; | 349 | QString toString; |
350 | QString ccString; | 350 | QString ccString; |
351 | QString bccString; | 351 | QString bccString; |
352 | 352 | ||
353 | 353 | ||
354 | toString = m_mail2[0].join(","); | 354 | toString = m_mail2[0].join(","); |
355 | ccString = m_mail2[1].join(","); | 355 | ccString = m_mail2[1].join(","); |
356 | bccString = m_mail2[2].join(","); | 356 | bccString = m_mail2[2].join(","); |
357 | 357 | ||
358 | 358 | ||
359 | setCaption( i18n("E-Mail by %1").arg( m_mail[0] ) ); | 359 | setCaption( i18n("E-Mail by %1").arg( m_mail[0] ) ); |
360 | 360 | ||
361 | m_mailHtml = "<html><body>" | 361 | m_mailHtml = "<html><body>" |
362 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 362 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
363 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 363 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
364 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 364 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
365 | "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 365 | "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
366 | "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 366 | "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
367 | i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 367 | i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
368 | "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + | 368 | "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + |
369 | "</td></tr></table><font>"; | 369 | "</td></tr></table><font>"; |
370 | 370 | ||
371 | if ( !m_showHtml ) | 371 | if ( !m_showHtml ) |
372 | { | 372 | { |
373 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 373 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
374 | } | 374 | } |
375 | else | 375 | else |
376 | { | 376 | { |
377 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); | 377 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); |
378 | } | 378 | } |
379 | // remove later in favor of a real handling | 379 | // remove later in favor of a real handling |
380 | m_gotBody = true; | 380 | m_gotBody = true; |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | ViewMail::~ViewMail() | 384 | ViewMail::~ViewMail() |
385 | { | 385 | { |
386 | m_recMail->Wrapper()->cleanMimeCache(); | 386 | m_recMail->Wrapper()->cleanMimeCache(); |
387 | hide(); | 387 | hide(); |
388 | } | 388 | } |
389 | 389 | ||
390 | void ViewMail::hide() | 390 | void ViewMail::hide() |
391 | { | 391 | { |
392 | QWidget::hide(); | 392 | QWidget::hide(); |
393 | 393 | ||
394 | if (_inLoop) | 394 | if (_inLoop) |
395 | { | 395 | { |
396 | _inLoop = false; | 396 | _inLoop = false; |
397 | qApp->exit_loop(); | 397 | qApp->exit_loop(); |
398 | 398 | ||
399 | } | 399 | } |
400 | 400 | ||
401 | } | 401 | } |
402 | 402 | ||
403 | void ViewMail::exec() | 403 | void ViewMail::exec() |
404 | { | 404 | { |
405 | show(); | 405 | show(); |
406 | 406 | ||
407 | if (!_inLoop) | 407 | if (!_inLoop) |
408 | { | 408 | { |
409 | _inLoop = true; | 409 | _inLoop = true; |
410 | qApp->enter_loop(); | 410 | qApp->enter_loop(); |
411 | } | 411 | } |
412 | 412 | ||
413 | } | 413 | } |
414 | 414 | ||
415 | QString ViewMail::deHtml(const QString &string) | 415 | QString ViewMail::deHtml(const QString &string) |
416 | { | 416 | { |
417 | QString string_ = string; | 417 | QString string_ = string; |
418 | string_.replace(QRegExp("&"), "&"); | 418 | string_.replace(QRegExp("&"), "&"); |
419 | string_.replace(QRegExp("<"), "<"); | 419 | string_.replace(QRegExp("<"), "<"); |
420 | string_.replace(QRegExp(">"), ">"); | 420 | string_.replace(QRegExp(">"), ">"); |
421 | string_.replace(QRegExp("\\n"), "<br>"); | 421 | string_.replace(QRegExp("\\n"), "<br>"); |
422 | return string_; | 422 | return string_; |
423 | } | 423 | } |
424 | 424 | ||
425 | void ViewMail::slotReply() | 425 | void ViewMail::slotReply() |
426 | { | 426 | { |
427 | if (!m_gotBody) | 427 | if (!m_gotBody) |
428 | { | 428 | { |
429 | QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot reply yet."), i18n("Ok")); | 429 | QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot reply yet."), i18n("Ok")); |
430 | return; | 430 | return; |
431 | } | 431 | } |
432 | 432 | ||
433 | QString rtext; | 433 | QString rtext; |
434 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 434 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
435 | .arg( m_mail[0] ) | 435 | .arg( m_mail[0] ) |
436 | .arg( m_mail[3] ); | 436 | .arg( m_mail[3] ); |
437 | 437 | ||
438 | QString text = m_mail[2]; | 438 | QString text = m_mail[2]; |
439 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 439 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
440 | QStringList::Iterator it; | 440 | QStringList::Iterator it; |
441 | for (it = lines.begin(); it != lines.end(); it++) | 441 | for (it = lines.begin(); it != lines.end(); it++) |
442 | { | 442 | { |
443 | rtext += "> " + *it + "\n"; | 443 | rtext += "> " + *it + "\n"; |
444 | } | 444 | } |
445 | rtext += "\n"; | 445 | rtext += "\n"; |
446 | 446 | ||
447 | QString prefix; | 447 | QString prefix; |
448 | if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; | 448 | if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; |
449 | else prefix = "Re: "; // no i18n on purpose | 449 | else prefix = "Re: "; // no i18n on purpose |
450 | 450 | ||
451 | Settings *settings = new Settings(); | 451 | Settings *settings = new Settings(); |
452 | ComposeMail composer( settings ,this, 0, true); | 452 | ComposeMail composer( settings ,this, 0, true); |
453 | if (m_recMail->Replyto().isEmpty()) { | 453 | if (m_recMail->Replyto().isEmpty()) { |
454 | composer.setTo(m_recMail->getFrom()); | 454 | composer.setTo(m_recMail->getFrom()); |
455 | } else { | 455 | } else { |
456 | composer.setTo(m_recMail->Replyto()); | 456 | composer.setTo(m_recMail->Replyto()); |
457 | } | 457 | } |
458 | composer.setSubject( prefix + m_mail[1] ); | 458 | composer.setSubject( prefix + m_mail[1] ); |
459 | composer.setMessage( rtext ); | 459 | composer.setMessage( rtext ); |
460 | composer.setInReplyTo(m_recMail->Msgid()); | 460 | composer.setInReplyTo(m_recMail->Msgid()); |
461 | composer.setCharset( m_body->getCharset() ); | 461 | composer.setCharset( m_body->getCharset() ); |
462 | 462 | ||
463 | if ( QDialog::Accepted == KApplication::execDialog( &composer ) ) | 463 | if ( QDialog::Accepted == KApplication::execDialog( &composer ) ) |
464 | { | 464 | { |
465 | m_recMail->Wrapper()->answeredMail(m_recMail); | 465 | m_recMail->Wrapper()->answeredMail(m_recMail); |
466 | } | 466 | } |
467 | delete settings; | 467 | delete settings; |
468 | } | 468 | } |
469 | 469 | ||
470 | void ViewMail::slotForward() | 470 | void ViewMail::slotForward() |
471 | { | 471 | { |
472 | if (!m_gotBody) | 472 | if (!m_gotBody) |
473 | { | 473 | { |
474 | QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot forward yet."), i18n("Ok")); | 474 | QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot forward yet."), i18n("Ok")); |
475 | return; | 475 | return; |
476 | } | 476 | } |
477 | 477 | ||
478 | QString ftext; | 478 | QString ftext; |
479 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") | 479 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") |
480 | .arg( m_mail[0] ); | 480 | .arg( m_mail[0] ); |
481 | if (!m_mail[3].isNull()) | 481 | if (!m_mail[3].isNull()) |
482 | ftext += QString("Date: %1\n") | 482 | ftext += QString("Date: %1\n") |
483 | .arg( m_mail[3] ); | 483 | .arg( m_mail[3] ); |
484 | if (!m_mail[0].isNull()) | 484 | if (!m_mail[0].isNull()) |
485 | ftext += QString("From: %1\n") | 485 | ftext += QString("From: %1\n") |
486 | .arg( m_mail[0] ); | 486 | .arg( m_mail[0] ); |
487 | if (!m_mail[1].isNull()) | 487 | if (!m_mail[1].isNull()) |
488 | ftext += QString("Subject: %1\n") | 488 | ftext += QString("Subject: %1\n") |
489 | .arg( m_mail[1] ); | 489 | .arg( m_mail[1] ); |
490 | 490 | ||
491 | ftext += QString("\n%1\n") | 491 | ftext += QString("\n%1\n") |
492 | .arg( m_mail[2]); | 492 | .arg( m_mail[2]); |
493 | 493 | ||
494 | ftext += QString("----- End forwarded message -----\n"); | 494 | ftext += QString("----- End forwarded message -----\n"); |
495 | 495 | ||
496 | Settings *settings = new Settings(); | 496 | Settings *settings = new Settings(); |
497 | ComposeMail composer( settings ,this, 0, true); | 497 | ComposeMail composer( settings ,this, 0, true); |
498 | composer.setSubject( "Fwd: " + m_mail[1] ); | 498 | composer.setSubject( "Fwd: " + m_mail[1] ); |
499 | composer.setMessage( ftext ); | 499 | composer.setMessage( ftext ); |
500 | if ( QDialog::Accepted == KApplication::execDialog( &composer )) | 500 | if ( QDialog::Accepted == KApplication::execDialog( &composer )) |
501 | { | 501 | { |
502 | } | 502 | } |
503 | } | 503 | } |
504 | 504 | ||
505 | void ViewMail::slotDeleteMail( ) | 505 | void ViewMail::slotDeleteMail( ) |
506 | { | 506 | { |
507 | if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) | 507 | if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) |
508 | { | 508 | { |
509 | m_recMail->Wrapper()->deleteMail( m_recMail ); | 509 | emit deleteAndDisplayNextMail( this); |
510 | hide(); | 510 | //m_recMail->Wrapper()->deleteMail( m_recMail ); |
511 | //hide(); | ||
511 | deleted = true; | 512 | deleted = true; |
512 | } | 513 | } |
513 | } | 514 | } |
514 | 515 | ||
515 | MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, WFlags f) | 516 | MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, WFlags f) |
516 | : QDialog(parent,name,modal) | 517 | : QDialog(parent,name,modal) |
517 | { | 518 | { |
518 | QVBoxLayout*dlglayout = new QVBoxLayout(this); | 519 | QVBoxLayout*dlglayout = new QVBoxLayout(this); |
519 | dlglayout->setSpacing(2); | 520 | dlglayout->setSpacing(2); |
520 | dlglayout->setMargin(1); | 521 | dlglayout->setMargin(1); |
521 | //m_imageview = new Opie::MM::OImageScrollView(this); | 522 | //m_imageview = new Opie::MM::OImageScrollView(this); |
522 | //dlglayout->addWidget(m_imageview); | 523 | //dlglayout->addWidget(m_imageview); |
523 | } | 524 | } |
524 | 525 | ||
525 | MailImageDlg::~MailImageDlg() | 526 | MailImageDlg::~MailImageDlg() |
526 | { | 527 | { |
527 | } | 528 | } |
528 | 529 | ||
529 | void MailImageDlg::setName(const QString&fname) | 530 | void MailImageDlg::setName(const QString&fname) |
530 | { | 531 | { |
531 | qDebug("viewmail.cpp: MailImageDlg::setName Pending"); | 532 | qDebug("viewmail.cpp: MailImageDlg::setName Pending"); |
532 | // m_imageview->setImage(fname); | 533 | // m_imageview->setImage(fname); |
533 | } | 534 | } |