⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readmail.cpp

📁 Qtopia下的邮件处理程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 2000-2006 TROLLTECH ASA. All rights reserved.**** This file is part of the Phone Edition of the Qtopia Toolkit.**** Licensees holding a valid license agreement from Trolltech or any of its** authorized distributors may use this file in accordance with** the License Agreement provided with the Licensed Software.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Trolltech's Commercial License Agreements.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.********** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "readmail.h"#include "maillistview.h"#include "addresslist.h"#include "emailfolderlist.h"#include "smsclient.h"#ifdef QTOPIA_DESKTOP#include <qdapplication.h>#include <qcopenvelope_qd.h>#else#include <qtopia/qtopiaapplication.h>#include <qtopia/qcopenvelope.h>#endif#include <qtopia/qtopianamespace.h>#include <qtopia/qcopservices.h>#include <qtopia/qsoftmenubar.h>#include <qtopia/pim/qcontact.h>#ifdef QTOPIA_PHONE#ifndef QTOPIA_NO_MMS# include <qtopia/smil/smil.h># include <qtopia/smil/element.h># include <qtopia/smil/timing.h># include <qtopia/smil/transfer.h>#endif#endif#include <qlabel.h>#include <qimage.h>#include <qaction.h>#include <qfile.h>#include <qtextstream.h>#include <qcursor.h>#include <qtooltip.h>#include <qwhatsthis.h>#include <qregexp.h>#include <qstackedwidget.h>#include <qmessagebox.h>#include <qboxlayout.h>#include <qevent.h>#include <qimagereader.h>#include <QDebug>#include <qtopia/qdrmcontentagent.h>Browser::Browser( QWidget *parent  )	: QTextBrowser( parent ){#ifdef QTOPIA_PHONE    setFrameStyle( NoFrame );#endif}Browser::~Browser(){}void Browser::scrollBy(int dx, int dy){    scrollContentsBy( dx, dy );}QVariant Browser::loadResource( int type, const QUrl& name ){    if ( resourceMap[name].isNull() )	return QTextBrowser::loadResource( type, name );    return resourceMap[name];}void Browser::setResource( const QUrl& name, QVariant var ){    resourceMap[name] = var;}void Browser::setSource(const QUrl &name){    Q_UNUSED(name)// We deal with this ourselves.//    QTextBrowser::setSource( name );}//===========================================================================class InfoLabel : public QLabel{public:    InfoLabel( const QString &txt, QWidget *parent = 0, const char *name = 0 )	: QLabel( txt, parent, Qt::FramelessWindowHint | Qt::Tool )    {	setObjectName( name );	setFrameStyle( QFrame::WinPanel + QFrame::Raised );	setMargin( 10 );	resize( sizeHint() );	startTimer( 2000 );    }protected:    void timerEvent(QTimerEvent *)    {	delete this;    }    void mousePressEvent(QMouseEvent *)    {	delete this;    }};#ifdef QTOPIA_PHONE#ifndef QTOPIA_NO_MMSstatic QMap<SmilDataSource*,QIODevice*> *transfers = 0;#endif#endifbool isRightsObject( Email *mail ){    return mail->messagePartCount() && mail->messagePartAt( 0 ).contentType().startsWith( "application/vnd.oma.drm.rights+" );}//===========================================================================ReadMail::ReadMail( QWidget* parent,  const QString name, Qt::WFlags fl )    : QMainWindow(parent, fl){    setObjectName( name );    plainTxt = false;    sending = false;    receiving = false;    initialized = false;    _pHeight = 0;    _pWidth = 0;    firstRead = false;    init();}ReadMail::~ReadMail(){}void ReadMail::init(){#if defined(QTOPIA_PHONE) && !defined(QTOPIA_NO_MMS)    smilView = 0;#endif#ifndef QTOPIA_PHONE#ifdef QTOPIA4_TODO    bar = new QToolBar(this);    bar->setMoveable( false );    bar->setHorizontalStretchable( true );    menu = new QMenuBar( bar );    mailMenu = new QPopupMenu(menu);    menu->insertItem( tr( "&Mail" ), mailMenu);    viewMenu = new QPopupMenu(menu);    menu->insertItem( tr( "&View" ), viewMenu);    statusMenu = new QPopupMenu(menu);    bar = new QToolBar(this);#endif#endif    getThisMailButton = new QAction( QIcon(":icon/getmail"), tr("Get this mail"), this );    connect(getThisMailButton, SIGNAL(triggered()), this, SLOT(getThisMail()) );    getThisMailButton->setWhatsThis( tr("Retrieve this mail from the server.  You can use this option to retrieve individual mails that would normally not be automatically downloaded.") );    sendThisMailButton = new QAction( QIcon(":icon/sendmail"), tr("Send this mail"), this );    connect(sendThisMailButton, SIGNAL(triggered()), this, SLOT(sendThisMail()));    sendThisMailButton->setWhatsThis(  tr("Send this mail.  This option will not send any other mails in your outbox.") );    replyButton = new QAction( QIcon(":icon/reply"), tr("Reply"), this );    connect(replyButton, SIGNAL(triggered()), this, SLOT(reply()));    replyButton->setWhatsThis( tr("Reply to sender only.  Select Reply all from the menu if you want to reply to all recipients.") );    replyAllAction = new QAction( QIcon(":icon/replytoall"), tr("Reply All"), this );    connect(replyAllAction, SIGNAL(triggered()), this, SLOT(replyAll()));    forwardAction = new QAction(tr("Forward"), this );    connect(forwardAction, SIGNAL(triggered()), this, SLOT(forward()));    modifyButton = new QAction( QIcon(":icon/edit"), tr("Modify"), this );    connect(modifyButton, SIGNAL(triggered()), this, SLOT(modify()));    modifyButton->setWhatsThis( tr("Opens this mail in the composer so that you can make modifications to it.") );    previousButton = new QAction( QIcon( ":icon/up" ), tr( "Previous" ), this );    connect( previousButton, SIGNAL(triggered()), this, SLOT( previous() ) );    previousButton->setWhatsThis( tr("Read the previous mail in the folder.") );    nextButton = new QAction( QIcon( ":icon/down" ), tr( "Next" ), this );    connect( nextButton, SIGNAL(triggered()), this, SLOT( next() ) );    nextButton->setWhatsThis( tr("Read the next mail in the folder.") );    attachmentsButton = new QAction( QIcon( ":icon/attach" ), tr( "Attachments" ), this );    connect( attachmentsButton, SIGNAL(triggered()), this,	    SLOT( viewAttachments() ) );    attachmentsButton->setWhatsThis( tr("View the attachments in the mail.") );    plainTextButton = new QAction( QIcon( ":icon/plaintext" ), tr( "Text Format" ), this );    plainTextButton->setCheckable( true );    connect( plainTextButton, SIGNAL(triggered()), this, SLOT( shiftText() ) );    plainTextButton->setWhatsThis( tr("Toggle the display of mail between plain text and rich text.") );    deleteButton = new QAction( QIcon( ":icon/trash" ), tr( "Delete" ), this );    connect( deleteButton, SIGNAL(triggered()), this, SLOT( deleteItem() ) );    deleteButton->setWhatsThis( tr("Move this mail to the trash folder.  If the mail is already in the trash folder it will be deleted. ") );    QFrame *vbox = new QFrame(this);    QVBoxLayout *vboxLayout = new QVBoxLayout(vbox);    views = new QStackedWidget(vbox);    vboxLayout->addWidget( views );    emailView = new Browser( views );    emailView->setObjectName( "emailView" );    connect(emailView, SIGNAL( anchorClicked(const QUrl&) ),	    this, SLOT( linkClicked(const QUrl&) ) );    emailView->setWhatsThis( tr("This view displays the contents of the mail.") );    views->addWidget(emailView);    views->setCurrentWidget(emailView);    progressLabel = new QLabel(vbox);    vboxLayout->addWidget( progressLabel );    progressLabel->hide();    setCentralWidget(vbox);#ifdef QTOPIA_PHONE    emailView->installEventFilter( this );    context = QSoftMenuBar::menuFor( this );#else#ifdef QTOPIA4_TODO    previousButton->addTo(viewMenu);    nextButton->addTo(viewMenu);    viewMenu->insertSeparator();    attachmentsButton->addTo(viewMenu);    viewMenu->insertSeparator();    plainTextButton->addTo(viewMenu);#endif#endif    }/*  We need to be careful here. Don't allow clicking on any links    to automatically install anything.  If we want that, we need to    make sure that the mail doesn't contain mailicious link encoding*/void ReadMail::linkClicked(const QUrl &lnk){#ifdef QTOPIA4_TODO    // Why does lnk have "&amp;" etc. in it?    QString str = Qtopia::plainString(lnk.toString());#else    QString str = lnk.toString();#endif    int pos = str.indexOf(";");    if ( pos != -1 ) {	QString command = str.left(pos);	QString param = str.mid(pos + 1);		if ( command == "attachment" ) { // No tr	    if (param == "view") { // No tr		viewAttachments();	    } else if ( param.startsWith("scrollto;") ) {		emailView->scrollToAnchor( param.mid(9) );#ifndef QTOPIA_NO_MMS	    } else if (param == "play") {		if (isMms)		    viewMms();#endif	    }	}    } else {	if ( str.startsWith("mailto:") )  {#ifdef QTOPIA_PHONE	    emit mailto( str );#else#ifdef QTOPIA4_TODO	    QPopupMenu *pop = new QPopupMenu(this);	    pop->insertItem( tr("Add to Contacts"), 0 );	    pop->insertItem( tr("Write mail to"), 1);	    int id;	    if ( (id = pop->exec( QCursor::pos() ) ) > -1 ) {		if ( id == 0 ) {		    if ( !AddressPicker::addressList()->addToContacts( str.mid(7) ) ) {			InfoLabel *label = new InfoLabel( tr("The address already exists in Contacts") );			QPoint p = QCursor::pos();			if ( p.x() + label->width() > qApp->desktop()->width() )			    p.setX( qApp->desktop()->width() - label->width() );			label->move( p );			label->show();		    }		} else if ( id == 1 ) {		    emit mailto( str );		}	    }#endif#endif		} else if ( str.startsWith("http://") ) {#ifndef	QT_NO_COP	    {		QCopServiceRequest e( "WebAccess", "openURL(QString)" );		e << str;		e.send();	    }#else#ifdef QTOPIA_DESKTOP	    // open a url#else#warning "should open link some other way if no qcop"#endif#endif	}        else if( str == "installrights" && isRightsObject( mail ) )        {            QDrmContentAgent::getDrm()->installRightsObject( mail->messagePartAt( 0 ).rawEncodedBody() );            mail->removeAllMessageParts();            mail->setDirty( true );            EmailFolderList *folder = mail->parent();            folder->removeMail( mail->uuid(), true );            close();        }    }}void ReadMail::updateView(){    QString mailStringSize;    if ( lastMailUuid.isNull() )	return;    isMms = false;    isSmil = false;    views->setCurrentWidget(emailView);    mail->readFromFile();    if ( !mail->status(EFlag_Read) ) {	mail->setStatus(EFlag_Read, true );	mail->setDirty( true );    firstRead = true;    }    else        firstRead = false;    qDebug("####### parts : %d", mail->messagePartCount());    if ( mail->status(EFlag_Incoming) ) {        if ( !mail->status(EFlag_Downloaded) ) {	    //report currently viewed mail so that it will be	    //placed first in the queue of new mails to download.	    emit viewingMail(mail);	    uint mailSize = mail->size();	    if (mailSize < 1024) {		mailStringSize.setNum(mailSize);		mailStringSize += " Bytes";	    } else if (mailSize < 1024*1024) {		mailStringSize.setNum( (mailSize / 1024) );		mailStringSize += " Kb";	    } else {		float f = (float) mailSize / (1024*1024);		mailStringSize.setNum(f , 'g', 3 );		mailStringSize += " Mb";	    }	}    }#ifndef QTOPIA_NO_MMS    QString mmsType = mail->header("X-Mms-Message-Type");    if (mmsType.contains("m-retrieve-conf")	|| mmsType.contains("m-send-req")) {	isMms = true;	if (mail->header("Content-Type").contains("multipart/related")) {	    isSmil = true;	    qDebug("SMIL");	}    }#endif    plainTextButton->setVisible(!isMms && !isRightsObject( mail ) );    replyButton->setVisible( !isRightsObject( mail ) );    forwardAction->setVisible(mail->type() == MailMessage::Email && !isRightsObject( mail ) );    replyAllAction->setVisible(mail->type() == MailMessage::Email && !isRightsObject( mail ) );    if ( !plainTxt || isMms ) {						//use RichText, inline pics etc.	emailView->setHtml( fancyText(mailStringSize) );    } else {						// show plain txt mail	emailView->setPlainText( normalText(mailStringSize) );    }}void ReadMail::resizeEvent(QResizeEvent *e){    _pWidth = e->size().width();    _pHeight = e->size().height();    updateView();}void ReadMail::keyPressEvent(QKeyEvent *e){    switch( e->key() ) {	case Qt::Key_A:	    if ( attachmentsButton->isEnabled() )		viewAttachments();	    break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -