editaccount.cpp

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

CPP
681 行
字号
/******************************************************************************** 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 <qtopia/qtopiaapplication.h>#include <qcheckbox.h>#include <qcombobox.h>#include <qcursor.h>#include <qgroupbox.h>#include <qheaderview.h>#include <qlayout.h>#include <qlineedit.h>#include <qmessagebox.h>#include <qmenu.h>#include <qpushbutton.h>#include <qspinbox.h>#include <qtabwidget.h>#include <qtoolbutton.h>#include <qscrollarea.h>#include <qcombobox.h>#include <qlabel.h>#include <qtooltip.h>#include <qwhatsthis.h>#include <qvalidator.h>#include "account.h"#include "editaccount.h"class PortValidator : public QValidator{public:    PortValidator(QWidget *parent = 0, const char *name = 0)	: QValidator(parent) {      setObjectName(name);    }        State validate(QString &str, int &) const    {	// allow empty strings, as it's a bit awkward to edit otherwise	if ( str.isEmpty() )	    return QValidator::Acceptable;		bool ok = false;	int i = str.toInt(&ok);	if ( !ok )	    return QValidator::Invalid;		if ( i <= 0 || i >= 65536 )	    return QValidator::Invalid;		return QValidator::Acceptable;    }};EditAccount::EditAccount( QWidget* parent, const char* name, Qt::WFlags fl )  : QDialog(parent, fl){#if defined(QTOPIA_PHONE)    tabWidget =0;#endif    setupUi(this);        //connect custom slots    connect(ToolButton2,SIGNAL(clicked()),SLOT(sigPressed()));    connect(accountType,SIGNAL(activated(int)),SLOT(typeChanged(int)));    connect(authentication,SIGNAL(activated(int)),SLOT(authChanged(int)));    connect(emailInput,SIGNAL(textChanged(const QString&)),SLOT(emailModified()));    //connect(mailboxButton,SIGNAL(clicked()),SLOT(configureFolders()));        setObjectName(name);        emailTyped = false;#ifdef QTOPIA_PHONE    int imHint = QtopiaApplication::Number;    QtopiaApplication::setInputMethodHint(mailPortInput,                                          (QtopiaApplication::InputMethodHint)imHint );    QtopiaApplication::setInputMethodHint(smtpPortInput,                                          (QtopiaApplication::InputMethodHint)imHint );  #endif    #ifdef QTOPIA_PHONE    // Too easy to mistype numbers in phone mode    mailPasswInput->installEventFilter( this );    accountNameInput->installEventFilter( this );    defaultMailCheckBox->installEventFilter( this );    installEventFilter(this);    mailboxButton->hide();#endif    PortValidator *pv = new PortValidator(this);    mailPortInput->setValidator(pv);    smtpPortInput->setValidator(pv);#ifndef SMTPAUTH	encryption->hide();	authentication->hide();	lblEncryption->hide();	lblAuthentication->hide();	lblSmtpUsername->hide();	lblSmtpPassword->hide();	smtpUsernameInput->hide();	smtpPasswordInput->hide();    encryptionCheckBox->hide();#endif    typeChanged(1);#if defined(QTOPIA_PHONE)    createTabbedView();#endif    mailPasswInput->setEchoMode(QLineEdit::PasswordEchoOnEdit);    smtpPasswordInput->setEchoMode(QLineEdit::PasswordEchoOnEdit);    }void EditAccount::setAccount(MailAccount *in, bool newOne){    account = in;    if (newOne) {	accountNameInput->setText("");	emailInput->setText("");	mailUserInput->setText("");	mailPasswInput->setText("");	mailServerInput->setText("");	smtpServerInput->setText("");	syncCheckBox->setChecked(true);	mailPortInput->setText("110");	smtpPortInput->setText("25");#ifdef SMTPAUTH	smtpUsernameInput->setText("");	smtpPasswordInput->setText("");	encryption->setCurrentIndex(0);	authentication->setCurrentIndex(0);	smtpUsernameInput->setEnabled(false);	smtpPasswordInput->setEnabled(false);    encryptionCheckBox->setChecked(false);#endif	setWindowTitle( tr("Create New Account", "translation not longer than English") );	typeChanged( 0 );    } else {	if ( account->accountType() == MailAccount::POP ) {	} else if ( account->accountType() == MailAccount::IMAP ) {	    accountType->setCurrentIndex(1);	    typeChanged(1);	    imapBaseDir->setText( account->baseFolder() );	} else {	    accountType->setCurrentIndex(2);	    typeChanged(2);	}	accountNameInput->setText( account->accountName() );	nameInput->setText( account->userName() );	emailInput->setText( account->emailAddress() );	mailUserInput->setText( account->mailUserName() );	mailPasswInput->setText( account->mailPassword() );	mailServerInput->setText( account->mailServer() );	smtpServerInput->setText( account->smtpServer() );	syncCheckBox->setChecked( account->synchronize() );	deleteCheckBox->setChecked( account->deleteMail() );	sigCheckBox->setChecked( account->useSig() );	sig = account->sig();	maxSize->setValue(account->maxMailSize());	thresholdCheckBox->setChecked( account->maxMailSize() != -1 );	mailPortInput->setText( QString::number( account->mailPort() ) );	smtpPortInput->setText( QString::number( account->smtpPort() ) );	defaultMailCheckBox->setChecked( account->defaultMailServer() );#ifdef SMTPAUTH		smtpUsernameInput->setText(account->smtpUsername());	smtpPasswordInput->setText(account->smtpPassword());		authentication->setCurrentIndex(static_cast<int>(account->smtpAuthentication()));	encryption->setCurrentIndex(static_cast<int>(account->smtpEncryption()));	smtpUsernameInput->setEnabled(authentication->currentIndex() != 0);	smtpPasswordInput->setEnabled(authentication->currentIndex() != 0);    encryptionCheckBox->setChecked(account->mailEncryption() != MailAccount::Encrypt_NONE);#endif    }    nameInput->setText( account->userName() );}#ifdef QTOPIA_PHONEvoid EditAccount::createTabbedView(){    delete layout();    QHBoxLayout* thelayout = new QHBoxLayout(this);    thelayout->setMargin(0);    thelayout->setSpacing(0);    tabWidget = new QTabWidget(this);    thelayout->addWidget(tabWidget);    QScrollArea* scroll = new QScrollArea(tabWidget);    scroll->setFocusPolicy(Qt::NoFocus);    scroll->setWidget(incomingFrame);    scroll->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );    scroll->setWidgetResizable(true);    scroll->setFrameStyle(QFrame::NoFrame);    incomingFrame->setLineWidth(0);    incomingFrame->setMidLineWidth(0);    incomingFrame->setFrameStyle(QFrame::NoFrame);    tabWidget->addTab(scroll,tr("Incoming"));        scroll = new QScrollArea(tabWidget);    scroll->setFocusPolicy(Qt::NoFocus);    scroll->setWidget(outgoingFrame);    scroll->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );    scroll->setWidgetResizable(true);    scroll->setFrameStyle(QFrame::NoFrame);    outgoingFrame->setLineWidth(0);    outgoingFrame->setMidLineWidth(0);    outgoingFrame->setFrameStyle(QFrame::NoFrame);    tabWidget->addTab(scroll,tr("Outgoing"));        updateGeometry();}// bool EditAccount::event(QEvent* e)// {//     if(e->type() == QEvent::LayoutRequest)//     {        //         if(width() < (incomingFrame->sizeHint().width() + outgoingFrame->sizeHint().width()))//         {//             if(!tabWidget)//             {//                 createTabbedView();//                 return QDialog::event(e);//             }//         }       //     }//     return QDialog::event(e);// }bool EditAccount::eventFilter( QObject* o, QEvent *e ){    if ((o == accountNameInput) && (e->type() == QEvent::FocusIn))    {	if (tabWidget && tabWidget->currentIndex() != 1)	    tabWidget->setCurrentIndex( 1 );	return QWidget::eventFilter( o, e );    }    else if ((o == defaultMailCheckBox) && (e->type() == QEvent::FocusIn)) {	if (tabWidget && tabWidget->currentIndex() != 1)	    tabWidget->setCurrentIndex( 1 );	return QWidget::eventFilter( o, e );    }    return QDialog::eventFilter(o,e);}#endif//TODO fix, unused code, slot inaccessible since button not visible on form// void EditAccount::configureFolders()// {//     MailboxSelector sel(this, "sel", account);//     QtopiaApplication::execDialog(&sel);// }void EditAccount::sigPressed(){    if ( sigCheckBox->isChecked() ) {      SigEntry sigEntry(this, "sigEntry", (Qt::WFlags)1);	if ( sig.isEmpty() ) {	    sigEntry.setEntry( "~~\n" + nameInput->text() );	} else {	    sigEntry.setEntry( sig );	}	if ( sigEntry.exec() == QDialog::Accepted) {	    sig = sigEntry.entry();	}    }}void EditAccount::emailModified(){    emailTyped = true;}void EditAccount::authChanged(int index){    	smtpUsernameInput->setEnabled(index != 0);	smtpPasswordInput->setEnabled(index != 0);	if(index == 0)	{	smtpUsernameInput->clear();	smtpPasswordInput->clear();	}}void EditAccount::typeChanged(int){#ifdef QTOPIA_PHONE    if ( accountType->currentText() == tr("Sync") ) {#else    if ( accountType->currentText() == tr("Synchronized") ) {#endif	imapSettings->hide();	syncCheckBox->hide();	mailboxButton->setEnabled( false );	mailPortInput->setEnabled( false );	smtpPortInput->setEnabled( false );	smtpServerInput->setEnabled( false );	deleteCheckBox->setEnabled( false );	defaultMailCheckBox->setEnabled( false );	thresholdCheckBox->setEnabled( false );	return;    } else {	mailboxButton->setEnabled( true );	mailPortInput->setEnabled( true );

⌨️ 快捷键说明

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