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

📄 readmail.cpp

📁 Qtopia下的邮件处理程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        if ( inbox == (mail->status(EFlag_Incoming) > 0) ) {	    updateView();        } else {	    update( mailView );        }        updateButtons();    }}//deletes item, tries bringing up next or previous, exits if unsucessfulvoid ReadMail::deleteItem(){    EmailListItem *item = (EmailListItem *) mailView->currentItem();    emit removeItem(item);}void ReadMail::updateButtons(){    EmailListItem *current = (EmailListItem *) mailView->currentItem();    if ( !current || !mailView->isItemSelected( current ) ) {	close();	return;    }    /*  Safety precaution.  The mail might have been moved internally/externally	away from the mailbox.  Verify that we actually still have access to the	same mail   */    mail = current->mail();    if ( mail->uuid() != lastMailUuid ) {	update( mailView );	return;    }    QString mailbox = mailView->currentMailbox();    if ( hasGet(mailbox) ) {	bool off = mail->status(EFlag_Downloaded) || receiving;        qDebug() << "getThisMailButton off" << off;	getThisMailButton->setVisible( !off );    } else {        qDebug() << "!hasGet";    }    if ( hasSend(mailbox) ) {	if ( mail->status(EFlag_Sent) || sending ) {	    sendThisMailButton->setVisible(false);	} else if ( mail->unfinished() ) {	    sendThisMailButton->setVisible(false);	} else {	    sendThisMailButton->setVisible(true);	}    }    if ( hasEdit(mailbox) )	modifyButton->setVisible( !( mail->status(EFlag_Sent) || sending ) );    attachmentsButton->setVisible( mail->messagePartCount() );    nextButton->setVisible(mailView->row(current) + 1 < mailView->rowCount());    previousButton->setVisible(mailView->row(current) > 0);    if ( current )	current->updateState();    if (sending || receiving)	progressLabel->show();    else	progressLabel->hide();}void ReadMail::shiftText(){    plainTxt = !plainTxt;    if ( plainTxt ) {	QFont font("Fixed", 16, QFont::Normal); // No tr	font.setFixedPitch( true );	emailView->setFont( font );    } else {	QFont font;	emailView->setFont( font );    }    updateView();}void ReadMail::viewAttachments(){    ViewAtt dlg(mail, mail->status(EFlag_Incoming));#ifdef QTOPIA_DESKTOP    dlg.exec();#else    QtopiaApplication::execDialog(&dlg);#endif}void ReadMail::viewMms(){#ifdef QTOPIA_PHONE#ifndef QTOPIA_NO_MMS    QString start = "<presentation-part>";    QString content = mail->header("Content-Type");    QStringList params = content.split(';');    QStringList::Iterator it;    for (it = params.begin(); it != params.end(); ++it) {	int pos = (*it).indexOf("start=");	if (pos > 0) {	    start = (*it).mid(pos+6);	    if (start[0] == '\"')		start = start.mid(1);	    if (start[start.length()-1] == '\"')		start.truncate(start.length()-1);	    break;	}    }    if (!smilView) {	smilView = new SmilView(views);        smilView->setGeometry(views->rect()); // will be using rect() to tweak smil layout	connect(smilView, SIGNAL(transferRequested(SmilDataSource*, const QString&)),		this, SLOT(requestTransfer(SmilDataSource*, const QString&)));	connect(smilView, SIGNAL(transferCancelled(SmilDataSource*, const QString&)),		this, SLOT(cancelTransfer(SmilDataSource*, const QString&)));	connect(smilView, SIGNAL(finished()), this, SLOT(mmsFinished()));	views->addWidget(smilView);	smilView->setFocusPolicy(Qt::StrongFocus);	smilView->installEventFilter(this);	QSoftMenuBar::setLabel(smilView, QSoftMenuBar::menuKey(), QSoftMenuBar::NoLabel);	QSoftMenuBar::setLabel(smilView, Qt::Key_Select, QSoftMenuBar::Next);    }    bool ok = false;    for ( uint i = 0; i < mail->messagePartCount(); i++ ) {	MailMessagePart &part = mail->messagePartAt( i );	if (part.contentID() == start) {	    QString smil = part.decodedBody();            qWarning() << smil;	    smilView->setSource(smil);	    ok = true;	    break;	}    }    if (ok && smilView && smilView->rootElement()) {	tweakSmil(smilView->rootElement());	smilView->play();	views->setCurrentWidget(smilView);    } else {	QMessageBox::warning(this, tr("Cannot view MMS"),	    tr("<qt>Cannot play improperly formatted MMS</qt>"), QMessageBox::Ok, QMessageBox::NoButton);    }#endif#endif}#ifdef QTOPIA_PHONE#ifndef QTOPIA_NO_MMSvoid ReadMail::tweakSmil(SmilElement *smil){    // Try to make sure the layout works on our display    SmilElement *layout = smil->findChild(QString(), "layout", true);    if (!layout)	return;    QRect rl = rect();    SmilElement *rootLayout = layout->findChild(QString(), "root-layout");    if (rootLayout) {	if (rootLayout->rect().width() > smilView->width()	    || rootLayout->rect().height() > smilView->height()) {	    rootLayout->setRect(QRect(0, 0, smilView->width(), smilView->height()));	}	rl = rootLayout->rect();    }    SmilElement *imageLayout = layout->findChild("Image", "region");    if (!imageLayout)	imageLayout = layout->findChild("image", "region");    SmilElement *textLayout = layout->findChild("Text", "region");    if (!textLayout)	textLayout = layout->findChild("text", "region");    if (imageLayout && textLayout) {	QRect il = imageLayout->rect();	QRect tl = textLayout->rect();	if (il.bottom() > tl.top() || il.right() > rl.right()		|| tl.right() > rl.right() || il.bottom() > rl.bottom()		|| tl.bottom() > rl.bottom()) {	    // Not going to fit - use our preferred sizes.	    il = tl = rl;	    il.setBottom(il.top() + rl.height()*2/3);	    tl.setTop(il.bottom()+1);	    tl.setHeight(rl.height() - il.height());	    imageLayout->setRect(il);	    textLayout->setRect(tl);	    qDebug() << "Adjusting smil layout" << il<< tl;	}    }}void ReadMail::advanceMmsSlide(){    // Try to advance to the next slide    qDebug("Try to advance");    SmilElement *smil = smilView->rootElement();    if (!smil)	return;    SmilElement *body = smil->findChild(QString(), "body", true);    if (!body)	return;    SmilElementList::ConstIterator it;    for (it = body->children().begin(); it != body->children().end(); ++it) {	SmilElement *e = *it;	if (e->name() == "par") {	    if (e->state() == SmilElement::Active) {		// This should be the current active slide		qDebug() << " Advancing element" << e->name();		SmilTimingAttribute *at = (SmilTimingAttribute*)e->module("Timing");		Duration d(at->startTime.elapsed());	// i.e. end now.		e->setCurrentEnd(d);		break;	    }	}    }}#endif#endifvoid ReadMail::mmsFinished(){#ifdef QTOPIA_PHONE#ifndef QTOPIA_NO_MMS    qDebug("mmsFinished");    views->setCurrentWidget(emailView);#endif#endif}void ReadMail::requestTransfer(SmilDataSource*#ifdef QTOPIA_PHONE dataSource, const QString &src#else , const QString&#endif    ){#ifdef QTOPIA_PHONE#ifndef QTOPIA_NO_MMS    bool isId = false;    QString source = src;    if (source.startsWith("cid:")) {	source = source.mid(4);	isId = true;    }    for ( uint i = 0; i < mail->messagePartCount(); i++ ) {	MailMessagePart &part = mail->messagePartAt( i );	if ((isId && part.contentID() == source)	    || part.contentLocation() == source) {	    qDebug() << "Loading" << src;	    dataSource->setMimeType(part.contentType());	    QBuffer *data = new QBuffer();            data->setData(part.decodedBody().toLatin1());	    data->open(QIODevice::ReadOnly);            dataSource->setDevice(data);	    if (!transfers)		transfers = new QMap<SmilDataSource*,QIODevice*>;	    (*transfers)[dataSource] = data;	    break;	}    }#endif#endif}void ReadMail::cancelTransfer(SmilDataSource *dataSource, const QString &src){    QString unused = src;#if defined(QTOPIA_PHONE) && !defined(QTOPIA_NO_MMS)    if (!transfers)	return;    if (transfers->contains(dataSource))        transfers->take(dataSource)->deleteLater();#else    Q_UNUSED(dataSource)#endif}void ReadMail::reply(){    emit resendRequested(*mail, 1);}void ReadMail::replyAll(){    emit resendRequested(*mail, 2);}/*  Need to install the files first in order for them to be available    as a mimecoded attachment.  This does however make all the attached files    appear in thew Documents tab, which may or may not be logical */void ReadMail::forward(){//    MailMessagePart part;//    for ( uint i = 0; i < mail->messagePartCount(); i++ ) {//        part = mail->messagePartAt( i );//        mail->setAttachmentInstalled(part.name(), true );//    }    emit resendRequested(*mail, 3);}void ReadMail::setStatus(int id){    uint prevStatus = mail->allStatusFields();    switch( id ) {	case 1:	{	    mail->setStatus(EFlag_Replied | EFlag_RepliedAll | EFlag_Forwarded, false);	    mail->setStatus(EFlag_Read, false);	    break;	}	case 2:	{	    mail->setStatus(EFlag_Replied | EFlag_RepliedAll | EFlag_Forwarded, false);	    mail->setStatus(EFlag_Replied, true );	    break;	}	case 3:		{	    mail->setStatus(EFlag_Replied | EFlag_RepliedAll, false);	    mail->setStatus(EFlag_Forwarded, true);	    break;	}	case 4:	mail->setStatus(EFlag_Sent, true ); break;	case 5: mail->setStatus(EFlag_Sent, false ); break;    }    if ( mail->allStatusFields() != prevStatus)	mail->setDirty( true );    updateButtons();}void ReadMail::modify(){    emit modifyRequested(mail);}void ReadMail::getThisMail(){    emit getMailRequested(mail);}void ReadMail::sendThisMail(){    emit sendMailRequested(mail);}void ReadMail::isSending(bool on){    sending = on;    if ( isVisible() )	updateButtons();}void ReadMail::isReceiving(bool on){    receiving = on;    if ( isVisible() )	updateButtons();}void ReadMail::setProgressText(const QString &txt){//    qDebug("Setting progress text: %s", txt.toLatin1());    progressLabel->setText(txt);    if (txt.isNull())	progressLabel->hide();}void ReadMail::initImages(){    if (initialized)	return;        initialized = true;    // Add the predefined smiley images for EMS messages.    emailView->setResource( QUrl( "x-sms-predefined:ironic" ),			    QVariant( QImage( ":image/smiley/ironic" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:glad" ),			    QVariant( QImage( ":image/smiley/glad" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:skeptical" ),			    QVariant( QImage( ":image/smiley/skeptical" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:sad" ),			    QVariant( QImage( ":image/smiley/sad" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:wow" ),			    QVariant( QImage( ":image/smiley/wow" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:crying" ),			    QVariant( QImage( ":image/smiley/crying" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:winking" ),			    QVariant( QImage( ":image/smiley/winking" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:laughing" ),			    QVariant( QImage( ":image/smiley/laughing" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:indifferent" ),			    QVariant( QImage( ":image/smiley/indifferent" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:kissing" ),			    QVariant( QImage( ":image/smiley/kissing" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:confused" ),			    QVariant( QImage( ":image/smiley/confused" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:tongue" ),			    QVariant( QImage( ":image/smiley/tongue" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:angry" ),			    QVariant( QImage( ":image/smiley/angry" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:glasses" ),			    QVariant( QImage( ":image/smiley/glasses" ) ) );    emailView->setResource( QUrl( "x-sms-predefined:devil" ),			    QVariant( QImage( ":image/smiley/devil" ) ) );}bool ReadMail::hasGet(const QString &mailbox){    return mailbox.startsWith("inbox");}bool ReadMail::hasSend(const QString &mailbox){    return mailbox.startsWith("outbox");}bool ReadMail::hasEdit(const QString &mailbox){    return mailbox.startsWith("outbox") || mailbox.startsWith("drafts"); // No tr}bool ReadMail::hasReply(const QString &mailbox){    return !mailbox.startsWith("outbox");}

⌨️ 快捷键说明

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