00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "readmail.h"
00021 #include <qimage.h>
00022 #include <qwhatsthis.h>
00023 #include <qmime.h>
00024 #include <qaction.h>
00025 #include <qpopupmenu.h>
00026 #include <qpe/resource.h>
00027
00028 ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl )
00029 : QMainWindow(parent, name, fl)
00030 {
00031 plainTxt = FALSE;
00032
00033 init();
00034 viewAtt = new ViewAtt(0, "View Attatchments");
00035 }
00036
00037 ReadMail::~ReadMail()
00038 {
00039 delete emailView->mimeSourceFactory();
00040 delete viewAtt;
00041 }
00042
00043 void ReadMail::init()
00044 {
00045 setToolBarsMovable(FALSE);
00046
00047 QPopupMenu* mailaction=new QPopupMenu(this);
00048
00049 bar = new QToolBar(this);
00050 bar->setHorizontalStretchable( TRUE );
00051
00052 menu = new QMenuBar( bar );
00053
00054 viewMenu = new QPopupMenu(menu);
00055 menu->insertItem( tr( "&View" ), viewMenu);
00056
00057 mailMenu = new QPopupMenu(menu);
00058 menu->insertItem( tr( "&Mail" ), mailMenu);
00059
00060 bar = new QToolBar(this);
00061
00062 downloadButton = new QAction( tr( "Download" ), Resource::loadPixmap( "mailit/download" ),QString::null, 0, this, 0 );
00063 connect(downloadButton, SIGNAL(activated()), this, SLOT(download()) );
00064 downloadButton->setWhatsThis(tr("Click here to download the selected mail"));
00065
00066
00067 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
00068 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) );
00069 previousButton->addTo(bar);
00070 previousButton->addTo(viewMenu);
00071 previousButton->setWhatsThis(tr("Read the previous mail in the list"));
00072
00073 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
00074 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) );
00075 nextButton->addTo(bar);
00076 nextButton->addTo(viewMenu);
00077 previousButton->setWhatsThis(tr("Read the next mail in the list"));
00078
00079 attachmentButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 );
00080 connect( attachmentButton, SIGNAL( activated() ), this,
00081 SLOT( viewAttachments() ) );
00082 attachmentButton->addTo(bar);
00083 attachmentButton->addTo(viewMenu);
00084 attachmentButton->setWhatsThis(tr("Click here to add attachments to your mail"));
00085
00086 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE);
00087 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) );
00088 plainTextButton->addTo(bar);
00089 plainTextButton->addTo(viewMenu);
00090 plainTextButton->setWhatsThis(tr("The mail view has 2 modes:\n"
00091 "<LI><B>RichText</B> shows the mail as HTML with reach features (no standard line breaks)</LI>"
00092 "<LI><B>Plain</B> shows the mail as standard plain text</LI>"
00093 "Click here to switch between those view modes" ));
00094
00095
00096 replyButton = new QToolButton(Resource::loadPixmap("mailit/reply"),tr("reply"),tr("reply to mail"), this,SLOT(reply()),bar);
00097 QWhatsThis::add(replyButton,tr("Click here to reply to the selected mail\nPress and hold for more options."));
00098 replyButton->setPopup(mailaction);
00099
00100 replyAllButton = new QAction( tr( "Reply all" ), Resource::loadPixmap( "mailit/reply" ),QString::null, 0, this, 0 );
00101 connect(replyAllButton, SIGNAL(activated()), this, SLOT(replyAll()));
00102 replyAllButton->setWhatsThis(tr("Click here to reply to the selected mail to CC: addresses also"));
00103 replyAllButton->addTo(mailaction);
00104
00105 forwardButton = new QAction( tr( "Forward" ), Resource::loadPixmap( "mailit/forward" ),
00106 QString::null, 0, this, 0 );
00107 connect(forwardButton, SIGNAL(activated()), this, SLOT(forward()));
00108 forwardButton->setWhatsThis(tr("Click here to forward the selected mail"));
00109 forwardButton->addTo(mailaction);
00110
00111
00112 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
00113 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
00114 deleteButton->addTo(bar);
00115 deleteButton->addTo(mailMenu);
00116 deleteButton->setWhatsThis(tr("Click here to remove the selected mail"));
00117
00118 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close()));
00119
00120 emailView = new QTextView( this, "emailView" );
00121
00122 setCentralWidget(emailView);
00123
00124 mime = new QMimeSourceFactory();
00125 emailView->setMimeSourceFactory(mime);
00126 }
00127
00128 void ReadMail::updateView()
00129 {
00130 Enclosure *ePtr;
00131 QString mailStringSize;
00132 QString text, temp;
00133
00134 mail->read = TRUE;
00135 inbox = mail->received;
00136
00137 replyButton->setEnabled(false);
00138
00139
00140
00141 downloadButton->removeFrom(bar);
00142
00143
00144
00145
00146 if (inbox == TRUE) {
00147 replyButton->setEnabled(true);
00148
00149
00150
00151
00152
00153 if (!mail->downloaded) {
00154
00155 downloadButton->addTo(bar);
00156
00157
00158
00159 emit viewingMail(mail);
00160
00161 double mailSize = (double) mail->size;
00162 if (mailSize < 1024) {
00163 mailStringSize.setNum(mailSize);
00164 mailStringSize += " Bytes";
00165 } else if (mailSize < 1024*1024) {
00166 mailStringSize.setNum( (mailSize / 1024), 'g', 2 );
00167 mailStringSize += " Kb";
00168 } else {
00169 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3);
00170 mailStringSize += " Mb";
00171 }
00172 }
00173 }
00174
00175 QMimeSourceFactory *mime = emailView->mimeSourceFactory();
00176
00177 if (! plainTxt) {
00178 emailView->setTextFormat(QTextView::RichText);
00179 text = "<b><big><center><font color=\"blue\">" + mail->subject
00180 +"</font></center></big></b><br>";
00181 text += "<b>From: </b>" + mail->from + " <i>" +
00182 mail->fromMail + "</i><br>";
00183
00184 text +="<b>To: </b>";
00185 for (QStringList::Iterator it = mail->recipients.begin();
00186 it != mail->recipients.end(); ++it ) {
00187 text += *it + " ";
00188 }
00189
00190 text +="<br><b>CC: </b>";
00191 for (QStringList::Iterator it = mail->carbonCopies.begin();
00192 it != mail->carbonCopies.end(); ++it ) {
00193 text += *it + " ";
00194 }
00195
00196 text += "<br>" + mail->date;
00197
00198 if (mail->files.count() > 0) {
00199 text += "<br><b>Attatchments: </b>";
00200
00201 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
00202 text += ePtr->originalName + " ";
00203 }
00204 text += "<hr><br>" + mail->body;
00205
00206 if (inbox) {
00207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
00208
00209 text += "<br><hr><b>Attatchment: </b>" +
00210 ePtr->originalName + "<hr>";
00211
00212 if (ePtr->contentType == "TEXT") {
00213 QFile f(ePtr->path + ePtr->name);
00214
00215 if (f.open(IO_ReadOnly) ) {
00216 QTextStream t(&f);
00217 temp = t.read();
00218 text += temp + "<br>";
00219 f.close();
00220 } else {
00221 text += "<b>Could not locate file</b><br>";
00222 }
00223
00224 }
00225 if (ePtr->contentType == "IMAGE") {
00226
00227
00228
00229 text += "<img src =""" +
00230 ePtr->originalName + """> </img>";
00231 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) ));
00232 }
00233 }
00234 }
00235 } else {
00236 if (mail->downloaded || !inbox) {
00237 text += "<hr><br>" + mail->body;
00238 } else {
00239 text += "<hr><br><b> Awaiting download </b><br>";
00240 text += "Size of mail: " + mailStringSize;
00241 }
00242 }
00243 emailView->setText(text);
00244 } else {
00245 emailView->setTextFormat(QTextView::PlainText);
00246 text = "Subject: " + mail->subject + "\n";
00247 text += "From: " + mail->from + " " + mail->fromMail + "\n";
00248 text += "To: ";
00249 for (QStringList::Iterator it = mail->recipients.begin();
00250 it != mail->recipients.end(); ++it ) {
00251 text += *it + " ";
00252 }
00253
00254 text += "\nCC: ";
00255 for (QStringList::Iterator it = mail->carbonCopies.begin();
00256 it != mail->carbonCopies.end(); ++it ) {
00257 text += *it + " ";
00258 }
00259
00260
00261 text += "\nDate: " + mail->date + "\n";
00262 if (mail->files.count() > 0) {
00263 text += "Attatchments: ";
00264 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
00265 text += ePtr->originalName + " ";
00266 }
00267 text += "\n\n";
00268 } else text += "\n";
00269
00270 if (!inbox) {
00271 text += mail->body;
00272 } else if (mail->downloaded) {
00273 text += mail->bodyPlain;
00274 } else {
00275 text += "\nAwaiting download\n";
00276 text += "Size of mail: " + mailStringSize;
00277 }
00278
00279 emailView->setText(text);
00280 }
00281
00282 if (mail->files.count() == 0)
00283 attachmentButton->setEnabled(FALSE);
00284 else attachmentButton->setEnabled(TRUE);
00285
00286 setCaption("Examining mail: " + mail->subject);
00287 }
00288
00289
00290 void ReadMail::update(QListView *thisView, Email *mailIn)
00291 {
00292 view = thisView;
00293 item = (EmailListItem *) view->selectedItem();
00294 mail = mailIn;
00295 updateView();
00296 updateButtons();
00297 }
00298
00299 void ReadMail::mailUpdated(Email *mailIn)
00300 {
00301 if (mailIn == mail) {
00302 updateView();
00303 } else {
00304 updateButtons();
00305 }
00306 }
00307
00308 void ReadMail::close()
00309 {
00310 emit cancelView();
00311 }
00312
00313
00314 void ReadMail::next()
00315 {
00316 item = (EmailListItem *) item->nextSibling();
00317 if (item != NULL) {
00318 mail = item->getMail();
00319 updateView();
00320 }
00321 updateButtons();
00322 }
00323
00324
00325 void ReadMail::previous()
00326 {
00327 item = (EmailListItem *) item->itemAbove();
00328 if (item != NULL) {
00329 mail = item->getMail();
00330 updateView();
00331 }
00332 updateButtons();
00333 }
00334
00335
00336 void ReadMail::deleteItem()
00337 {
00338 EmailListItem *temp = item;
00339 temp = (EmailListItem *) item->nextSibling();
00340 if (temp == NULL)
00341 temp = (EmailListItem *) item->itemAbove();
00342
00343 emit removeItem(item, inbox);
00344
00345 item = temp;
00346 if (item != NULL) {
00347 mail = item->getMail();
00348 updateView();
00349 updateButtons();
00350 } else close();
00351 }
00352
00353 void ReadMail::updateButtons()
00354 {
00355 EmailListItem *temp;
00356
00357 temp = item;
00358 if ((EmailListItem *) temp->nextSibling() == NULL)
00359 nextButton->setEnabled(FALSE);
00360 else nextButton->setEnabled(TRUE);
00361
00362 temp = item;
00363 if ((EmailListItem *) temp->itemAbove() == NULL)
00364 previousButton->setEnabled(FALSE);
00365 else previousButton->setEnabled(TRUE);
00366 }
00367
00368 void ReadMail::shiftText()
00369 {
00370 plainTxt = ! plainTxt;
00371 updateView();
00372 }
00373
00374 void ReadMail::viewAttachments()
00375 {
00376 viewAtt->update(mail, inbox);
00377 viewAtt->showMaximized();
00378 }
00379
00380 void ReadMail::reply()
00381 {
00382 emit replyRequested(*mail, (bool&)FALSE);
00383 }
00384
00385 void ReadMail::replyAll()
00386 {
00387 emit replyRequested(*mail, (bool&)TRUE);
00388 }
00389
00390 void ReadMail::forward()
00391 {
00392 emit forwardRequested(*mail);
00393 }
00394
00395 void ReadMail::download()
00396 {
00397 emit download(mail);
00398 }
00399