author | alwin <alwin> | 2004-02-22 23:56:05 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-02-22 23:56:05 (UTC) |
commit | eba25a5ebeca30b7124e7fae80685dbd1c9a985d (patch) (unidiff) | |
tree | d62dd266e9b57f3eae34612f5d0fc4cf0b625c20 /noncore/net/mailit/readmail.cpp | |
parent | 666a49773d06ac94c19996d763854725c2f7a578 (diff) | |
download | opie-eba25a5ebeca30b7124e7fae80685dbd1c9a985d.zip opie-eba25a5ebeca30b7124e7fae80685dbd1c9a985d.tar.gz opie-eba25a5ebeca30b7124e7fae80685dbd1c9a985d.tar.bz2 |
moved mailit into unsupported area 'cause replaced by opiemail3
Diffstat (limited to 'noncore/net/mailit/readmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/readmail.cpp | 399 |
1 files changed, 0 insertions, 399 deletions
diff --git a/noncore/net/mailit/readmail.cpp b/noncore/net/mailit/readmail.cpp deleted file mode 100644 index 1682675..0000000 --- a/noncore/net/mailit/readmail.cpp +++ b/dev/null | |||
@@ -1,399 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qt Palmtop Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "readmail.h" | ||
21 | #include <qimage.h> | ||
22 | #include <qwhatsthis.h> | ||
23 | #include <qmime.h> | ||
24 | #include <qaction.h> | ||
25 | #include <qpopupmenu.h> | ||
26 | #include <qpe/resource.h> | ||
27 | |||
28 | ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) | ||
29 | : QMainWindow(parent, name, fl) | ||
30 | { | ||
31 | plainTxt = FALSE; | ||
32 | |||
33 | init(); | ||
34 | viewAtt = new ViewAtt(0, "View Attatchments"); | ||
35 | } | ||
36 | |||
37 | ReadMail::~ReadMail() | ||
38 | { | ||
39 | delete emailView->mimeSourceFactory(); | ||
40 | delete viewAtt; | ||
41 | } | ||
42 | |||
43 | void ReadMail::init() | ||
44 | { | ||
45 | setToolBarsMovable(FALSE); | ||
46 | |||
47 | QPopupMenu* mailaction=new QPopupMenu(this); | ||
48 | |||
49 | bar = new QToolBar(this); | ||
50 | bar->setHorizontalStretchable( TRUE ); | ||
51 | |||
52 | menu = new QMenuBar( bar ); | ||
53 | |||
54 | viewMenu = new QPopupMenu(menu); | ||
55 | menu->insertItem( tr( "&View" ), viewMenu); | ||
56 | |||
57 | mailMenu = new QPopupMenu(menu); | ||
58 | menu->insertItem( tr( "&Mail" ), mailMenu); | ||
59 | |||
60 | bar = new QToolBar(this); | ||
61 | |||
62 | downloadButton = new QAction( tr( "Download" ), Resource::loadPixmap( "mailit/download" ),QString::null, 0, this, 0 ); | ||
63 | connect(downloadButton, SIGNAL(activated()), this, SLOT(download()) ); | ||
64 | downloadButton->setWhatsThis(tr("Click here to download the selected mail")); | ||
65 | |||
66 | |||
67 | previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); | ||
68 | connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); | ||
69 | previousButton->addTo(bar); | ||
70 | previousButton->addTo(viewMenu); | ||
71 | previousButton->setWhatsThis(tr("Read the previous mail in the list")); | ||
72 | |||
73 | nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); | ||
74 | connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); | ||
75 | nextButton->addTo(bar); | ||
76 | nextButton->addTo(viewMenu); | ||
77 | previousButton->setWhatsThis(tr("Read the next mail in the list")); | ||
78 | |||
79 | attachmentButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); | ||
80 | connect( attachmentButton, SIGNAL( activated() ), this, | ||
81 | SLOT( viewAttachments() ) ); | ||
82 | attachmentButton->addTo(bar); | ||
83 | attachmentButton->addTo(viewMenu); | ||
84 | attachmentButton->setWhatsThis(tr("Click here to add attachments to your mail")); | ||
85 | |||
86 | plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); | ||
87 | connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); | ||
88 | plainTextButton->addTo(bar); | ||
89 | plainTextButton->addTo(viewMenu); | ||
90 | plainTextButton->setWhatsThis(tr("The mail view has 2 modes:\n" | ||
91 | "<LI><B>RichText</B> shows the mail as HTML with reach features (no standard line breaks)</LI>" | ||
92 | "<LI><B>Plain</B> shows the mail as standard plain text</LI>" | ||
93 | "Click here to switch between those view modes" )); | ||
94 | |||
95 | //reply dependant on viewing inbox | ||
96 | replyButton = new QToolButton(Resource::loadPixmap("mailit/reply"),tr("reply"),tr("reply to mail"), this,SLOT(reply()),bar); | ||
97 | QWhatsThis::add(replyButton,tr("Click here to reply to the selected mail\nPress and hold for more options.")); | ||
98 | replyButton->setPopup(mailaction); | ||
99 | |||
100 | replyAllButton = new QAction( tr( "Reply all" ), Resource::loadPixmap( "mailit/reply" ),QString::null, 0, this, 0 ); | ||
101 | connect(replyAllButton, SIGNAL(activated()), this, SLOT(replyAll())); | ||
102 | replyAllButton->setWhatsThis(tr("Click here to reply to the selected mail to CC: addresses also")); | ||
103 | replyAllButton->addTo(mailaction); | ||
104 | |||
105 | forwardButton = new QAction( tr( "Forward" ), Resource::loadPixmap( "mailit/forward" ), | ||
106 | QString::null, 0, this, 0 ); | ||
107 | connect(forwardButton, SIGNAL(activated()), this, SLOT(forward())); | ||
108 | forwardButton->setWhatsThis(tr("Click here to forward the selected mail")); | ||
109 | forwardButton->addTo(mailaction); | ||
110 | |||
111 | |||
112 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); | ||
113 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | ||
114 | deleteButton->addTo(bar); | ||
115 | deleteButton->addTo(mailMenu); | ||
116 | deleteButton->setWhatsThis(tr("Click here to remove the selected mail")); | ||
117 | |||
118 | viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); | ||
119 | |||
120 | emailView = new QTextView( this, "emailView" ); | ||
121 | |||
122 | setCentralWidget(emailView); | ||
123 | |||
124 | mime = new QMimeSourceFactory(); | ||
125 | emailView->setMimeSourceFactory(mime); | ||
126 | } | ||
127 | |||
128 | void ReadMail::updateView() | ||
129 | { | ||
130 | Enclosure *ePtr; | ||
131 | QString mailStringSize; | ||
132 | QString text, temp; | ||
133 | |||
134 | mail->read = TRUE; //mark as read | ||
135 | inbox = mail->received; | ||
136 | |||
137 | replyButton->setEnabled(false); | ||
138 | /*replyButton->removeFrom(bar); | ||
139 | forwardButton->removeFrom(mailMenu); | ||
140 | forwardButton->removeFrom(bar);*/ | ||
141 | downloadButton->removeFrom(bar); | ||
142 | |||
143 | //downloadButton->setEnabled(!mail->downloaded); | ||
144 | |||
145 | |||
146 | if (inbox == TRUE) { | ||
147 | replyButton->setEnabled(true); | ||
148 | /*replyButton->addTo(mailMenu); | ||
149 | forwardButton->addTo(bar); | ||
150 | forwardButton->addTo(mailMenu);*/ | ||
151 | |||
152 | |||
153 | if (!mail->downloaded) { | ||
154 | |||
155 | downloadButton->addTo(bar); | ||
156 | |||
157 | //report currently viewed mail so that it will be | ||
158 | //placed first in the queue of new mails to download | ||
159 | emit viewingMail(mail); | ||
160 | |||
161 | double mailSize = (double) mail->size; | ||
162 | if (mailSize < 1024) { | ||
163 | mailStringSize.setNum(mailSize); | ||
164 | mailStringSize += " Bytes"; | ||
165 | } else if (mailSize < 1024*1024) { | ||
166 | mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); | ||
167 | mailStringSize += " Kb"; | ||
168 | } else { | ||
169 | mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); | ||
170 | mailStringSize += " Mb"; | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | |||
175 | QMimeSourceFactory *mime = emailView->mimeSourceFactory(); | ||
176 | |||
177 | if (! plainTxt) { //use RichText, inline pics etc. | ||
178 | emailView->setTextFormat(QTextView::RichText); | ||
179 | text = "<b><big><center><font color=\"blue\">" + mail->subject | ||
180 | +"</font></center></big></b><br>"; | ||
181 | text += "<b>From: </b>" + mail->from + " <i>" + | ||
182 | mail->fromMail + "</i><br>"; | ||
183 | |||
184 | text +="<b>To: </b>"; | ||
185 | for (QStringList::Iterator it = mail->recipients.begin(); | ||
186 | it != mail->recipients.end(); ++it ) { | ||
187 | text += *it + " "; | ||
188 | } | ||
189 | |||
190 | text +="<br><b>CC: </b>"; | ||
191 | for (QStringList::Iterator it = mail->carbonCopies.begin(); | ||
192 | it != mail->carbonCopies.end(); ++it ) { | ||
193 | text += *it + " "; | ||
194 | } | ||
195 | |||
196 | text += "<br>" + mail->date; | ||
197 | |||
198 | if (mail->files.count() > 0) { | ||
199 | text += "<br><b>Attatchments: </b>"; | ||
200 | |||
201 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | ||
202 | text += ePtr->originalName + " "; | ||
203 | } | ||
204 | text += "<hr><br>" + mail->body; | ||
205 | |||
206 | if (inbox) { | ||
207 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | ||
208 | |||
209 | text += "<br><hr><b>Attatchment: </b>" + | ||
210 | ePtr->originalName + "<hr>"; | ||
211 | |||
212 | if (ePtr->contentType == "TEXT") { | ||
213 | QFile f(ePtr->path + ePtr->name); | ||
214 | |||
215 | if (f.open(IO_ReadOnly) ) { | ||
216 | QTextStream t(&f); | ||
217 | temp = t.read(); | ||
218 | text += temp + "<br>"; | ||
219 | f.close(); | ||
220 | } else { | ||
221 | text += "<b>Could not locate file</b><br>"; | ||
222 | } | ||
223 | |||
224 | } | ||
225 | if (ePtr->contentType == "IMAGE") { | ||
226 | // temp.setNum(emailView->width());//get display width | ||
227 | // text += "<img width=" + temp +" src =""" + | ||
228 | // ePtr->originalName + """> </img>"; | ||
229 | text += "<img src =""" + | ||
230 | ePtr->originalName + """> </img>"; | ||
231 | mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } else { | ||
236 | if (mail->downloaded || !inbox) { | ||
237 | text += "<hr><br>" + mail->body; | ||
238 | } else { | ||
239 | text += "<hr><br><b> Awaiting download </b><br>"; | ||
240 | text += "Size of mail: " + mailStringSize; | ||
241 | } | ||
242 | } | ||
243 | emailView->setText(text); | ||
244 | } else { // show plain txt mail | ||
245 | emailView->setTextFormat(QTextView::PlainText); | ||
246 | text = "Subject: " + mail->subject + "\n"; | ||
247 | text += "From: " + mail->from + " " + mail->fromMail + "\n"; | ||
248 | text += "To: "; | ||
249 | for (QStringList::Iterator it = mail->recipients.begin(); | ||
250 | it != mail->recipients.end(); ++it ) { | ||
251 | text += *it + " "; | ||
252 | } | ||
253 | |||
254 | text += "\nCC: "; | ||
255 | for (QStringList::Iterator it = mail->carbonCopies.begin(); | ||
256 | it != mail->carbonCopies.end(); ++it ) { | ||
257 | text += *it + " "; | ||
258 | } | ||
259 | |||
260 | |||
261 | text += "\nDate: " + mail->date + "\n"; | ||
262 | if (mail->files.count() > 0) { | ||
263 | text += "Attatchments: "; | ||
264 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | ||
265 | text += ePtr->originalName + " "; | ||
266 | } | ||
267 | text += "\n\n"; | ||
268 | } else text += "\n"; | ||
269 | |||
270 | if (!inbox) { | ||
271 | text += mail->body; | ||
272 | } else if (mail->downloaded) { | ||
273 | text += mail->bodyPlain; | ||
274 | } else { | ||
275 | text += "\nAwaiting download\n"; | ||
276 | text += "Size of mail: " + mailStringSize; | ||
277 | } | ||
278 | |||
279 | emailView->setText(text); | ||
280 | } | ||
281 | |||
282 | if (mail->files.count() == 0) | ||
283 | attachmentButton->setEnabled(FALSE); | ||
284 | else attachmentButton->setEnabled(TRUE); | ||
285 | |||
286 | setCaption("Examining mail: " + mail->subject); | ||
287 | } | ||
288 | |||
289 | //update view with current EmailListItem (item) | ||
290 | void ReadMail::update(QListView *thisView, Email *mailIn) | ||
291 | { | ||
292 | view = thisView; | ||
293 | item = (EmailListItem *) view->selectedItem(); | ||
294 | mail = mailIn; | ||
295 | updateView(); | ||
296 | updateButtons(); | ||
297 | } | ||
298 | |||
299 | void ReadMail::mailUpdated(Email *mailIn) | ||
300 | { | ||
301 | if (mailIn == mail) { | ||
302 | updateView(); | ||
303 | } else { | ||
304 | updateButtons(); | ||
305 | } | ||
306 | } | ||
307 | |||
308 | void ReadMail::close() | ||
309 | { | ||
310 | emit cancelView(); | ||
311 | } | ||
312 | |||
313 | //gets next item in listview, exits if there is no next | ||
314 | void ReadMail::next() | ||
315 | { | ||
316 | item = (EmailListItem *) item->nextSibling(); | ||
317 | if (item != NULL) { | ||
318 | mail = item->getMail(); | ||
319 | updateView(); | ||
320 | } | ||
321 | updateButtons(); | ||
322 | } | ||
323 | |||
324 | //gets previous item in listview, exits if there is no previous | ||
325 | void ReadMail::previous() | ||
326 | { | ||
327 | item = (EmailListItem *) item->itemAbove(); | ||
328 | if (item != NULL) { | ||
329 | mail = item->getMail(); | ||
330 | updateView(); | ||
331 | } | ||
332 | updateButtons(); | ||
333 | } | ||
334 | |||
335 | //deletes item, tries bringing up next or previous, exits if unsucessful | ||
336 | void ReadMail::deleteItem() | ||
337 | { | ||
338 | EmailListItem *temp = item; | ||
339 | temp = (EmailListItem *) item->nextSibling();//trybelow | ||
340 | if (temp == NULL) | ||
341 | temp = (EmailListItem *) item->itemAbove(); //try above | ||
342 | |||
343 | emit removeItem(item, inbox); | ||
344 | |||
345 | item = temp; | ||
346 | if (item != NULL) { //more items in list | ||
347 | mail = item->getMail(); | ||
348 | updateView(); | ||
349 | updateButtons(); | ||
350 | } else close(); //no more items to see | ||
351 | } | ||
352 | |||
353 | void ReadMail::updateButtons() | ||
354 | { | ||
355 | EmailListItem *temp; | ||
356 | |||
357 | temp = item; | ||
358 | if ((EmailListItem *) temp->nextSibling() == NULL) | ||
359 | nextButton->setEnabled(FALSE); | ||
360 | else nextButton->setEnabled(TRUE); | ||
361 | |||
362 | temp = item; | ||
363 | if ((EmailListItem *) temp->itemAbove() == NULL) | ||
364 | previousButton->setEnabled(FALSE); | ||
365 | else previousButton->setEnabled(TRUE); | ||
366 | } | ||
367 | |||
368 | void ReadMail::shiftText() | ||
369 | { | ||
370 | plainTxt = ! plainTxt; | ||
371 | updateView(); | ||
372 | } | ||
373 | |||
374 | void ReadMail::viewAttachments() | ||
375 | { | ||
376 | viewAtt->update(mail, inbox); | ||
377 | viewAtt->showMaximized(); | ||
378 | } | ||
379 | |||
380 | void ReadMail::reply() | ||
381 | { | ||
382 | emit replyRequested(*mail, (bool&)FALSE); | ||
383 | } | ||
384 | |||
385 | void ReadMail::replyAll() | ||
386 | { | ||
387 | emit replyRequested(*mail, (bool&)TRUE); | ||
388 | } | ||
389 | |||
390 | void ReadMail::forward() | ||
391 | { | ||
392 | emit forwardRequested(*mail); | ||
393 | } | ||
394 | |||
395 | void ReadMail::download() | ||
396 | { | ||
397 | emit download(mail); | ||
398 | } | ||
399 | |||