writemail.cpp

来自「Qtopia下的邮件处理程序」· C++ 代码 · 共 1,183 行 · 第 1/3 页

CPP
1,183 行
字号
#ifdef QTOPIA_PHONEvoid WriteMail::setSmsRecipient(const QString &recipient){  m_detailsPage->setTo( recipient );}#endifvoid WriteMail::setRecipients(const QString &emails, const QString &#ifdef QTOPIA_PHONE        numbers#endif                             ){  QString to;  to += emails;#ifdef QTOPIA_PHONE    to = to.trimmed();    if( to.right( 1 ) != "," && !numbers.isEmpty()        && !numbers.trimmed().startsWith( "," ) )      to += ", ";    to +=  numbers;#endif#ifdef QTOPIA_PHONE    m_detailsPage#else    m_composerInterface#endif    ->setTo( to );}void WriteMail::reset(){  mail = MailMessage();  mail.removeAllMessageParts();  mail.setAllStatusFields(0);  mail.setServerUid("");  mail.setMessageId("");  mail.setInReplyTo("");  mail.setMultipartRelated( false );  QUuid id;  mail.setUuid( id );  mail.setAllStatusFields(0);  mail.setTo( QStringList() );  mail.setCc( QStringList() );  mail.setBcc( QStringList() );#ifdef QTOPIA_PHONE  if ( m_detailsPage )    m_detailsPage->clear();#else    m_composerInterface->clear();#endif#ifdef QTOPIA_PHONE    if( m_composerInterface ) {	m_composerInterface->deleteLater();	m_composerInterface = 0;	m_composerWidget = 0;    }#endif    hasMessageChanged = false;}void WriteMail::newMail( const QString&#ifdef QTOPIA_PHONE    cmpsr#endif, bool detailsOnly                       ){  reset();  _detailsOnly = detailsOnly;#ifdef QTOPIA_PHONE    QString comp = cmpsr;    if( comp.isNull() ) {      if (!selectComposer()) {        setComposer(ComposerFactory::defaultInterface());        QTimer::singleShot(0,this,SLOT(discard()));        return;      }    } else {      setComposer( comp );    }    if( m_composerInterface )      m_detailsPage->setType( m_composerInterface->type() );    if(_detailsOnly)        detailsStage();    else        composeStage();//     TODO  : attachments//     addAtt->clear();    QSoftMenuBar::setLabel(this, Qt::Key_Back, QSoftMenuBar::Next);#endif   }//updates actions, labels, captions based on the current stagevoid WriteMail::updateUI(){#ifdef QTOPIA_PHONE    QWidget *curPage = widgetStack->currentWidget();    m_previousAction->setVisible( curPage != m_composerWidget && !_detailsOnly);    if( curPage == m_detailsPage )      m_mainWindow->setWindowTitle( m_composerInterface->nickName() + " " + tr("Details") );    else if( curPage == m_composerWidget )      m_mainWindow->setWindowTitle( tr("Create") + " " + m_composerInterface->nickName() );    else      m_mainWindow->setWindowTitle( tr("Write Message") );    if( curPage == m_detailsPage )      if( hasRecipients() )        QSoftMenuBar::setLabel( this, Qt::Key_Back, "qtmail/enqueue", tr("Enqueue") );    else      QSoftMenuBar::setLabel( this, Qt::Key_Back, "qtmail/draft", tr("Draft") );        else if( curPage == m_composerWidget && m_composerInterface             && !m_composerInterface->hasContent() )      QSoftMenuBar::setLabel(this, Qt::Key_Back, QSoftMenuBar::Cancel);    else      QSoftMenuBar::setLabel(this, Qt::Key_Back, QSoftMenuBar::Next);#else#endif}void WriteMail::readConfig(){/*  TODO : allow toggling of cc, bcc and from fields  save configuration for phone edition*/#ifndef QTOPIA_PHONE    QSettings config("qtmail");    config.beginGroup("writemail");    bool showCC = config.value("showcc", true).toBool(),    showBCC = config.value("showbcc", false).toBool(),    showFrom = config.value("showfrom", false).toBool(),    wrap = config.value("wrap", true).toBool();    m_ccAction->setChecked( showCC );    m_bccAction->setChecked( showBCC );    m_fromAction->setChecked( showFrom );    m_wrapAction->setChecked( wrap );    m_composerInterface->toggleCc( showCC );    m_composerInterface->toggleBcc( showBCC );    m_composerInterface->toggleFrom( showFrom );    m_composerInterface->setWordWrap( wrap );#endif  }void WriteMail::saveConfig(){  /* TODO phone edition */#ifndef QTOPIA_PHONE    QSettings config("qtmail");    config.beginGroup("writemail");    config.remove("");    //TODO PDA fix accessibility of child widgets    Q_ASSERT(false);    //     config.writeEntry("showcc", !m_composerInterface->ccInput->isHidden() );//     config.writeEntry("showbcc", !m_composerInterface->bccInput->isHidden() );//     config.writeEntry("showfrom", !m_composerInterface->fromBox->isHidden() );//     config.writeEntry("wrap",//                       m_composerInterface->emailInput->wordWrap() != QTextEdit::NoWrap );#endif}void WriteMail::discard(){#ifdef QTOPIA_PHONE  // The follow if clause fixes a crash for the case when an email is being   // composed and while the textwidget has focus cancel is selected from   // the context menu  if( m_composerInterface )      m_composerInterface->widget()->hide();#endif  emit discardMail();  // Must delete the composer widget after emitting the discardMail signal  reset();}void WriteMail::enqueue(){  if ( !isComplete() ) {    if( !changed() )      discard();    else      draft();    return;  }  QValueSpaceItem item("/UI/Profile/PlaneMode");  if(item.value().toBool()) {      // Cannot send right now, in plane mode!      QMessageBox::information(this, tr("Airplane Safe Mode"), tr("<qt>Cannot send message while in Airplane Safe Mode.</qt>"));      return;  }  if( buildMail() )    /*#ifdef QTOPIA_PHONE    */    emit enqueueMail(mail);    /*#else  emit autosaveMail( mail );#endif    */  // Prevent double deletion of composer textedit that leads to crash on exit  reset(); }void WriteMail::draft(){  if( !changed() )  {    discard();    return;  }  if ( buildMail() )    emit saveAsDraft( mail );}void WriteMail::keyPressEvent(QKeyEvent *e){#ifdef QTOPIA_PHONE    if( e->key() == Qt::Key_Back || e->key() == Qt::Key_Yes ) {	keyEventAccepted = false;	/*	  don't call nextStage directly here, because it	  might delete the composer that this key press	  originated from.	*/	QTimer::singleShot( 0, this, SLOT(nextStage()) );	e->accept();	if (!Qtopia::mousePreferred()) {	    keyEventAccepted = true;	}    } else#endif	QMainWindow::keyPressEvent( e );}bool WriteMail::selectComposer(){#ifdef QTOPIA_PHONE    QDialog *dlg = new QDialog( this);    dlg->setObjectName("selectComposer");    dlg->setWindowTitle( tr("Select Type") );    QtopiaApplication::setMenuLike( dlg, true );    QVBoxLayout *l = new QVBoxLayout( dlg );    SelectListWidget *lb = new SelectListWidget( dlg );    lb->setFrameStyle(QFrame::NoFrame);    l->addWidget( lb );    QList<QString> interfaces = ComposerFactory::interfaces();    QList<QString>::ConstIterator it;    for( it = interfaces.begin() ; it != interfaces.end() ; ++it )    {    // list is order dependent      QIcon icon = ComposerFactory::displayIcon( *it );      QListWidgetItem* lwItem = new QListWidgetItem(ComposerFactory::fullName( *it ),lb);      lwItem->setIcon(icon);      if( *it == composer() )        lb->setCurrentRow( lb->count() -1 );    }    if (lb->currentRow() == -1)      lb->setCurrentRow(0);    connect( lb, SIGNAL(itemActivated(QListWidgetItem*)), dlg, SLOT(accept()) );    connect( lb, SIGNAL(itemClicked(QListWidgetItem*)), dlg, SLOT(accept()) );    dlg->showMaximized();    int result = QtopiaApplication::execDialog( dlg ) ;    bool ok = result == QDialog::Accepted && lb->currentRow() != -1;    // The dialog always seems to be accepted even when Key_Back is pressed    // hence explicitly check to see if keyBack was pressed and if so    // treat the dialog as rejected.    ok &= !lb->keyBackPressed();    if (ok) {      QString inf = interfaces[lb->currentRow()];      qDebug(("Setting composer: " + inf).toAscii());      setComposer( inf );     }    delete dlg;    return ok;#else    return false;#endif}#ifdef QTOPIA_PHONEvoid WriteMail::setComposer( const QString &id ){  if( m_composerInterface && m_composerInterface->id() == id )    return;  if( m_composerInterface )  {    delete m_composerInterface;    m_composerInterface = 0;  }  if(m_composerWidget)    widgetStack->removeWidget(m_composerWidget);  m_composerWidget = 0;  m_composerInterface = ComposerFactory::create( id, this );  if( !m_composerInterface )    return;  m_composerWidget = m_composerInterface->widget();  widgetStack->addWidget(m_composerWidget);  connect( m_composerInterface, SIGNAL(contentChanged()), this, SLOT(updateUI()) );  connect( m_composerInterface, SIGNAL(contentChanged()), this, SLOT(messageChanged()) );    // add standard actions to context menu for this composer  QMenu* menu = QSoftMenuBar::menuFor(m_composerInterface->widget());      //menu->insertSeparator( 0 );    //menu->insertAction( m_selectComposerAction, 0 );  menu->addSeparator();  menu->addAction(m_previousAction);  menu->addAction(m_cancelAction);    //menu->addTo( this );    m_composerInterface->widget()->show();  m_composerInterface->widget()->setFocus();  m_detailsPage = new DetailsPage( this );  widgetStack->addWidget(m_detailsPage);  connect( m_detailsPage, SIGNAL(recipientsChanged()), this, SLOT(updateUI()) );  m_detailsPage->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );  if ( accountList )      m_detailsPage->setFromFields( accountList->emailAccounts() );  QMenu *detailsMenu = QSoftMenuBar::menuFor( m_detailsPage );  detailsMenu->addSeparator();  detailsMenu->addAction(m_previousAction);  detailsMenu->addAction(m_cancelAction);    QTimer::singleShot( 0, this, SLOT(updateUI()) );    /*  QMainWindow *mw = new QMainWindow( this, "mainWindow" );  QWidgetStack *stack = new QWidgetStack( mw );  QMultiLineEdit *me = new QMultiLineEdit( stack );  stack->addWidget( me, 0 );  me->setMaxLength( 10 );  mw->setCentralWidget( stack );  mw->showMaximized();  mw->setCaption("Test");  stack->raiseWidget( me );    */}void WriteMail::setComposerFocus(){  if( !m_composerInterface )    return;  m_composerWidget->setFocus();}QString WriteMail::composer() const{  QString id;  if( m_composerInterface )    id = m_composerInterface->id();  return id;}bool WriteMail::keyPressAccepted() {  if (keyEventAccepted) {    keyEventAccepted = false;    return true;  }  return false;}#endifvoid WriteMail::messageChanged(){  hasMessageChanged = true;}

⌨️ 快捷键说明

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