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

📄 rightsnotification.cpp

📁 Qtopia下的邮件处理程序
💻 CPP
字号:
/******************************************************************************** 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 "rightsnotification.h"#include <qtopia/wap/wappushdatagramservice.h>#include <qtopia/qdrmcontentagent.h>#include <QTimer>#include <QVBoxLayout>#include <QListWidget>#include <qtopia/qtopiaapplication.h>#include <QtDebug>Notification::Notification( QObject *parent )    : QObject( parent ){}Notification::~Notification(){}class RightsNotification : public Notification{    Q_OBJECTpublic:    RightsNotification( const QString &type, const WspPush &push, QObject *parent = 0 );    ~RightsNotification();    bool isValid() const;    QString title() const;    QString message() const;    QStringList responses() const;public slots:    void responseSelected( int index ) const;    void cancelled() const;private:    QString constructMailBody()  const;    QString mimeType;    WspPush rightsPush;    QString name;    QMap< QDrmContent::PermissionType, QDrmRights > rights;};RightsNotification::RightsNotification( const QString &type, const WspPush &push, QObject *parent )    : Notification( parent )    , mimeType( type )    , rightsPush( push ){    QContent content( QDrmContentAgent::getDrm()->parseRightsObject( rightsPush.data(), rights ) );    if( content.isValid() )        name = content.name();}RightsNotification::~RightsNotification(){}bool RightsNotification::isValid() const{    return true;}QString RightsNotification::title() const{    return tr( "License received" );}QString RightsNotification::message() const{    if( !name.isEmpty() )        return tr( "License received for %1" ).arg( name );    else        return tr( "Content license recieved" );}QStringList RightsNotification::responses() const{    return QStringList()            << tr( "Install now" )            << tr( "Install later" )            << tr( "Reject" );}void RightsNotification::responseSelected( int responseIndex ) const{    switch( responseIndex )    {    case 0:        QDrmContentAgent::getDrm()->installRightsObject( rightsPush.data() );        break;    case 1:        cancelled();    }}void RightsNotification::cancelled() const{    foreach( WspField field, rightsPush.headers() )        qDebug() << field.name << ":" << field.value;    MailMessage mail;    mail.setDateTime( QDateTime::currentDateTime() );    if( !name.isEmpty() )        mail.setSubject( tr( "%1 license" ).arg( name ) );    else        mail.setSubject( tr( "Content license" ) );    mail.setPlainTextBody( constructMailBody() );    MailMessagePart rightsPart;    rightsPart.setContentType( mimeType );    rightsPart.setRawEncodedBody( rightsPush.data(), EightBit );    mail.addMessagePart( rightsPart );    mail.setMultipartRelated(true);    mail.encodeMail();    emit saveMail( mail, false );}QString RightsNotification::constructMailBody() const{    QString body;    if( rights.contains( QDrmContent::Play ) )        body += tr( "Play rights:<br>" ) + rights[ QDrmContent::Play ].toString() + "<br>";    if( rights.contains( QDrmContent::Display ) )        body += tr( "Display rights:<br>" ) + rights[ QDrmContent::Display ].toString() + "<br>";    if( rights.contains( QDrmContent::Execute ) )        body += tr( "Execute rights:<br>" ) + rights[ QDrmContent::Execute ].toString() + "<br>";    if( rights.contains( QDrmContent::Print ) )        body += tr( "Print rights:<br>" ) + rights[ QDrmContent::Print ].toString() + "<br>";    if( rights.contains( QDrmContent::Export ) )        body += tr( "Export rights:<br>" ) + rights[ QDrmContent::Export ].toString() + "<br>";    return body;}NotificationService::NotificationService( QObject *parent )    : QObject( parent ){    qDebug() << "Notification service started";    WapPushDatagramService *wapService = new WapPushDatagramService( this );    wapService->addMimeType( "application/vnd.oma.drm.rights+xml"   );    wapService->addMimeType( "application/vnd.oma.drm.rights+wbxml" );    connect( wapService, SIGNAL(datagram(const WspPush&,const QString&,const QString&)),             this, SLOT(pushReceived( const WspPush&,const QString&,const QString&)) );}NotificationService::~NotificationService(){}void NotificationService::pushReceived( const WspPush& push, const QString& matchedType, const QString& sender ){    Q_UNUSED( sender );    RightsNotification notification( matchedType, push );    connect( &notification, SIGNAL(saveMail(const MailMessage&,bool)),             this,          SLOT(convertMail(const MailMessage&,bool)) );    NotificationDialog dialog( notification );    QTimer::singleShot( 30000, &dialog, SLOT(reject()) );    if( QtopiaApplication::execDialog( &dialog ) == QDialog::Accepted )    {        notification.responseSelected( dialog.response() );    }    else    {        notification.cancelled();    }}void NotificationService::convertMail( const MailMessage &mail, bool read ){    Q_UNUSED( read );    emit saveMail( Email( mail ) );}class NotificationDialogPrivate{public:    QLabel messageLabel;    QListWidget responseList;    int response;};NotificationDialog::NotificationDialog( QWidget *parent )    : QDialog( parent ){    d = new NotificationDialogPrivate;    init();}NotificationDialog::NotificationDialog( const Notification &notification, QWidget *parent )    : QDialog( parent ){    d = new NotificationDialogPrivate;    setWindowTitle( notification.title() );    setMessage( notification.message() );    setResponses( notification.responses() );    init();}NotificationDialog::~NotificationDialog(){    delete d;}void NotificationDialog::setMessage( const QString &message ){    d->messageLabel.setText( message );}void NotificationDialog::setResponses( const QStringList &responses ){    d->responseList.clear();    d->responseList.addItems( responses );    d->responseList.setCurrentRow(0);}int NotificationDialog::response() const{    return d->response;}void NotificationDialog::init(){    connect( &(d->responseList), SIGNAL(activated( const QModelIndex&)),               this, SLOT(activated( const QModelIndex&)) );    QVBoxLayout *layout = new QVBoxLayout( this );    setLayout( layout );    d->messageLabel.setTextFormat(Qt::RichText);    d->messageLabel.setWordWrap(true);    layout->addWidget( &(d->messageLabel) );    layout->addStretch( 1 );    layout->addWidget( &(d->responseList) );    setModal( true );}void NotificationDialog::activated ( const QModelIndex & index ){    d->response = index.row();    accept();}#include "rightsnotification.moc"

⌨️ 快捷键说明

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