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