summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mailit/readmail.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/mailit/readmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mailit/readmail.cpp326
1 files changed, 326 insertions, 0 deletions
diff --git a/noncore/unsupported/mailit/readmail.cpp b/noncore/unsupported/mailit/readmail.cpp
new file mode 100644
index 0000000..4954f34
--- a/dev/null
+++ b/noncore/unsupported/mailit/readmail.cpp
@@ -0,0 +1,326 @@
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 <qmime.h>
23#include <qaction.h>
24#include "resource.h"
25
26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl )
27 : QMainWindow(parent, name, fl)
28{
29 plainTxt = FALSE;
30
31 init();
32 viewAtt = new ViewAtt(0, "View Attatchments");
33}
34
35ReadMail::~ReadMail()
36{
37 delete emailView->mimeSourceFactory();
38 delete viewAtt;
39}
40
41void ReadMail::init()
42{
43 setToolBarsMovable(FALSE);
44
45 bar = new QToolBar(this);
46 bar->setHorizontalStretchable( TRUE );
47
48 menu = new QMenuBar( bar );
49
50 viewMenu = new QPopupMenu(menu);
51 menu->insertItem( tr( "&View" ), viewMenu);
52
53 mailMenu = new QPopupMenu(menu);
54 menu->insertItem( tr( "&Mail" ), mailMenu);
55
56 bar = new QToolBar(this);
57
58 //reply dependant on viewing inbox
59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "pass" ),
60 QString::null, 0, this, 0 );
61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) );
62
63 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
64 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) );
65 previousButton->addTo(bar);
66 previousButton->addTo(viewMenu);
67
68 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
69 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) );
70 nextButton->addTo(bar);
71 nextButton->addTo(viewMenu);
72
73 attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
74 connect( attatchmentsButton, SIGNAL( activated() ), this,
75 SLOT( viewAttatchments() ) );
76 attatchmentsButton->addTo(bar);
77 attatchmentsButton->addTo(viewMenu);
78
79 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0, TRUE);
80 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) );
81 plainTextButton->addTo(bar);
82 plainTextButton->addTo(viewMenu);
83
84 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
85 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
86 deleteButton->addTo(bar);
87 deleteButton->addTo(mailMenu);
88
89 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close()));
90
91 emailView = new QTextView( this, "emailView" );
92 setCentralWidget(emailView);
93
94 mime = new QMimeSourceFactory();
95 emailView->setMimeSourceFactory(mime);
96}
97
98void ReadMail::updateView()
99{
100 Enclosure *ePtr;
101 QString mailStringSize;
102 QString text, temp;
103
104 mail->read = TRUE; //mark as read
105 inbox = mail->received;
106
107 replyButton->removeFrom(mailMenu);
108 replyButton->removeFrom(bar);
109
110 if (inbox == TRUE) {
111 replyButton->addTo(bar);
112 replyButton->addTo(mailMenu);
113
114 if (!mail->downloaded) {
115 //report currently viewed mail so that it will be
116 //placed first in the queue of new mails to download
117 emit viewingMail(mail);
118
119 double mailSize = (double) mail->size;
120 if (mailSize < 1024) {
121 mailStringSize.setNum(mailSize);
122 mailStringSize += " Bytes";
123 } else if (mailSize < 1024*1024) {
124 mailStringSize.setNum( (mailSize / 1024), 'g', 2 );
125 mailStringSize += " Kb";
126 } else {
127 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3);
128 mailStringSize += " Mb";
129 }
130 }
131 }
132
133 QMimeSourceFactory *mime = emailView->mimeSourceFactory();
134
135 if (! plainTxt) { //use RichText, inline pics etc.
136 emailView->setTextFormat(QTextView::RichText);
137 text = "<b><big><center><font color=\"blue\">" + mail->subject
138 +"</font></center></big></b><br>";
139 text += "<b>From: </b>" + mail->from + " <i>" +
140 mail->fromMail + "</i><br>";
141
142 text +="<b>To: </b>";
143 for (QStringList::Iterator it = mail->recipients.begin();
144 it != mail->recipients.end(); ++it ) {
145 text += *it + " ";
146 }
147 text += "<br>" + mail->date;
148
149 if (mail->files.count() > 0) {
150 text += "<br><b>Attatchments: </b>";
151
152 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
153 text += ePtr->originalName + " ";
154 }
155 text += "<hr><br>" + mail->body;
156
157 if (inbox) {
158 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
159
160 text += "<br><hr><b>Attatchment: </b>" +
161 ePtr->originalName + "<hr>";
162
163 if (ePtr->contentType == "TEXT") {
164 QFile f(ePtr->path + ePtr->name);
165
166 if (f.open(IO_ReadOnly) ) {
167 QTextStream t(&f);
168 temp = t.read();
169 text += temp + "<br>";
170 f.close();
171 } else {
172 text += "<b>Could not locate file</b><br>";
173 }
174
175 }
176 if (ePtr->contentType == "IMAGE") {
177 // temp.setNum(emailView->width());//get display width
178 // text += "<img width=" + temp +" src =""" +
179 // ePtr->originalName + """> </img>";
180 text += "<img src =""" +
181 ePtr->originalName + """> </img>";
182 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) ));
183 }
184 }
185 }
186 } else {
187 if (mail->downloaded || !inbox) {
188 text += "<hr><br>" + mail->body;
189 } else {
190 text += "<hr><br><b> Awaiting download </b><br>";
191 text += "Size of mail: " + mailStringSize;
192 }
193 }
194 emailView->setText(text);
195 } else { // show plain txt mail
196 emailView->setTextFormat(QTextView::PlainText);
197 text = "Subject: " + mail->subject + "\n";
198 text += "From: " + mail->from + " " + mail->fromMail + "\n";
199 text += "To: ";
200 for (QStringList::Iterator it = mail->recipients.begin();
201 it != mail->recipients.end(); ++it ) {
202 text += *it + " ";
203 }
204 text += "\nDate: " + mail->date + "\n";
205 if (mail->files.count() > 0) {
206 text += "Attatchments: ";
207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
208 text += ePtr->originalName + " ";
209 }
210 text += "\n\n";
211 } else text += "\n";
212
213 if (!inbox) {
214 text += mail->body;
215 } else if (mail->downloaded) {
216 text += mail->bodyPlain;
217 } else {
218 text += "\nAwaiting download\n";
219 text += "Size of mail: " + mailStringSize;
220 }
221
222 emailView->setText(text);
223 }
224
225 if (mail->files.count() == 0)
226 attatchmentsButton->setEnabled(FALSE);
227 else attatchmentsButton->setEnabled(TRUE);
228
229 setCaption("Examining mail: " + mail->subject);
230}
231
232//update view with current EmailListItem (item)
233void ReadMail::update(QListView *thisView, Email *mailIn)
234{
235 view = thisView;
236 item = (EmailListItem *) view->selectedItem();
237 mail = mailIn;
238 updateView();
239 updateButtons();
240}
241
242void ReadMail::mailUpdated(Email *mailIn)
243{
244 if (mailIn == mail) {
245 updateView();
246 } else {
247 updateButtons();
248 }
249}
250
251void ReadMail::close()
252{
253 emit cancelView();
254}
255
256//gets next item in listview, exits if there is no next
257void ReadMail::next()
258{
259 item = (EmailListItem *) item->nextSibling();
260 if (item != NULL) {
261 mail = item->getMail();
262 updateView();
263 }
264 updateButtons();
265}
266
267//gets previous item in listview, exits if there is no previous
268void ReadMail::previous()
269{
270 item = (EmailListItem *) item->itemAbove();
271 if (item != NULL) {
272 mail = item->getMail();
273 updateView();
274 }
275 updateButtons();
276}
277
278//deletes item, tries bringing up next or previous, exits if unsucessful
279void ReadMail::deleteItem()
280{
281 EmailListItem *temp = item;
282 temp = (EmailListItem *) item->nextSibling();//trybelow
283 if (temp == NULL)
284 temp = (EmailListItem *) item->itemAbove(); //try above
285
286 emit removeItem(item, inbox);
287
288 item = temp;
289 if (item != NULL) { //more items in list
290 mail = item->getMail();
291 updateView();
292 updateButtons();
293 } else close(); //no more items to see
294}
295
296void ReadMail::updateButtons()
297{
298 EmailListItem *temp;
299
300 temp = item;
301 if ((EmailListItem *) temp->nextSibling() == NULL)
302 nextButton->setEnabled(FALSE);
303 else nextButton->setEnabled(TRUE);
304
305 temp = item;
306 if ((EmailListItem *) temp->itemAbove() == NULL)
307 previousButton->setEnabled(FALSE);
308 else previousButton->setEnabled(TRUE);
309}
310
311void ReadMail::shiftText()
312{
313 plainTxt = ! plainTxt;
314 updateView();
315}
316
317void ReadMail::viewAttatchments()
318{
319 viewAtt->update(mail, inbox);
320 viewAtt->showMaximized();
321}
322
323void ReadMail::reply()
324{
325 emit replyRequested(*mail);
326}