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

📄 emailclient.cpp

📁 Qtopia下的邮件处理程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void EmailClient::init(){    mReadMail = 0;    mWriteMail = 0;    pm_folder = new QIcon(":icon/folder");    pm_trash = new QIcon(":icon/trash");    vbox = new QFrame(this);    vboxLayout = new QVBoxLayout(vbox);    vboxLayout->setMargin( 1 );    vboxLayout->setSpacing( 1 );    connect(emailHandler, SIGNAL(updatePopStatus(const QString&)),	    this, SLOT(updatePopStatusLabel(const QString&)) );    connect(emailHandler, SIGNAL(updateSendingStatus(const QString&)),	    this, SLOT(updateSendingStatusLabel(const QString&)) );    connect(emailHandler, SIGNAL(mailboxSize(int)),	    this, SLOT(setTotalPopSize(int)) );    connect(emailHandler, SIGNAL(downloadedSize(int)),	    this, SLOT(setDownloadedSize(int)) );    //smtp    connect(emailHandler, SIGNAL(transferredSize(int)),	    this, SLOT(setTransferredSize(int)) );    connect(emailHandler, SIGNAL(mailSendSize(int)),	    this, SLOT(setTotalSmtpSize(int)) );    setBackgroundRole( QPalette::Button );#ifndef QTOPIA_PHONE    bar = new QToolBar( this );    bar->setMovable( false );#ifdef QTOPIA4_TODO    bar->setHorizontalStretchable( true );#endif    mb = new QMenuBar( bar );    QMenu *mail = mb->addMenu( tr( "&Mail" ) );    configure = mb->addMenu( tr( "&Accounts" ) );    connect(configure, SIGNAL(triggered(QAction*)),	    this, SLOT(editAccount(QAction*)));        bar = new QToolBar( this );    bar->setMovable( false );#endif//     sendMailButton = new QAction( QIcon(":icon/sendmail"), tr("Send all mail"), this );//     connect(sendMailButton, SIGNAL(triggered()), this, SLOT(sendAllQueuedMail()) );//     sendMailButton->setWhatsThis( tr("Send all mail in the Outbox.") );    selectAccountMenu = new QMenu(mb);    connect(selectAccountMenu, SIGNAL(triggered(QAction*)),	    this, SLOT(selectAccount(QAction*)));    getMailButton = new QAction( QIcon(":icon/getmail"), tr("Get all mail"), this );    connect(getMailButton, SIGNAL(triggered()), this, SLOT(getAllNewMail()) );    getMailButton->setWhatsThis( tr("Get new mail from all your accounts.") );    cancelButton = new QAction( QIcon(":icon/reset"), tr("Cancel transfer"), this );    connect(cancelButton, SIGNAL(triggered()), this, SLOT(cancel()) );    cancelButton->setWhatsThis( tr("Abort all transfer of mail.") );    cancelButton->setVisible(false);    movePop = new QMenu(this);    copyPop = new QMenu(this);    connect(movePop, SIGNAL(triggered(QAction*)),	    this, SLOT(moveMailItem(QAction*)));    connect(copyPop, SIGNAL(triggered(QAction*)),	    this, SLOT(copyMailItem(QAction*)));    composeButton = new QAction( QIcon(":icon/new"), tr("New"), this );    connect(composeButton, SIGNAL(triggered()), this, SLOT( compose() ) );    composeButton->setWhatsThis( tr("Write a new mail.") );    searchButton = new QAction( QIcon(":icon/find"), tr("Search"), this );    connect(searchButton, SIGNAL(triggered()), this, SLOT( search() ) );    searchButton->setWhatsThis( tr("Search for mail in your folders.") );    settingsAction = new QAction( QIcon(":icon/settings"), tr("Account Settings..."), this );    connect(settingsAction, SIGNAL(triggered()), this, SLOT(settings()));    emptyTrashAction = new QAction(tr("Empty Trash"), this );    connect(emptyTrashAction, SIGNAL(triggered()), this, SLOT(emptyFolder()));    #ifdef QTOPIA_PHONE    moveAction = new QAction( tr("Move mail..."), this );    connect(moveAction, SIGNAL(triggered()), this, SLOT(moveMessage()));    copyAction = new QAction( tr("Copy mail..."), this );    connect(copyAction, SIGNAL(triggered()), this, SLOT(copyMessage()));    selectAllAction = new QAction( tr("Select all"), this );    connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));#endif        deleteMailAction = new QAction( *pm_trash, tr("Delete mail"), this );    connect(deleteMailAction, SIGNAL(triggered()), this, SLOT(deleteMailItem()));    #ifndef QTOPIA_PHONE//     mail->addAction( sendMailButton );    mail->addSeparator();    mail->addAction( getMailButton );    QAction *selectAccountMenuAction = mail->addMenu( selectAccountMenu );    selectAccountMenuAction->setText( tr("Get Mail in") );    mail->addSeparator();    mail->addAction( cancelButton );    mail->addSeparator();    QAction *movePopMenuAction = mail->addMenu( movePop );    movePopMenuAction->setText( tr("Move to") );    QAction *copyPopMenuAction = mail->addMenu( copyPop );    copyPopMenuAction->setText( tr("Copy to") );    mail->addAction( deleteMailAction );    mail->addSeparator();    mail->addAction( emptyTrashAction );    mail->addSeparator();    mail->addAction( composeButton );    mail->addAction( searchButton );    //     bar->addAction( sendMailButton );    bar->addAction( getMailButton );    if ( qApp->desktop()->width() > 176 )	bar->addAction( composeButton );    if ( qApp->desktop()->width() > 176 )	bar->addAction( searchButton );#endif    /*	Main View - Tabbed on size less than 640, horizontal layout on above sizes  */	    if ( qApp->desktop()->width() >= TabWidthTrigger ) {	widget_3 = new QWidget( vbox );	vboxLayout->addWidget( widget_3 );	gridQuery = new QGridLayout(widget_3);		folderView = new FolderListView(mailboxList, widget_3, "folderView");	gridQuery->addWidget(folderView, 0 , 0);		// Set the messageView to occupy 67% of the available view	gridQuery->setColumnStretch(0, 1);	gridQuery->setColumnStretch(1, 3);		mailboxView = 0;    //important, program relies on this being 0 if not in use    } else {#ifdef QTOPIA_PHONE	mailboxView = new QStackedWidget( vbox );	mailboxView->setObjectName( "mailboxView" );	vboxLayout->addWidget( mailboxView );#else	mailboxView = new QTabWidget( vbox );	mailboxView->setObjectName( "mailboxView" );	vboxLayout->addWidget( mailboxView );	// remove unnecessary border.	QStackedWidget *sw;	sw = mailboxView->findChild<QStackedWidget*>( "QStackedWidget" );	if (sw)	    sw->setFrameStyle( QFrame::NoFrame );#endif	widget_3 = new QWidget( mailboxView );	widget_3->setObjectName( "widget_3" );	gridQuery = new QGridLayout(widget_3);	gridQuery->setMargin( 0 );	gridQuery->setSpacing( 0 );	QWidget *widget_4 = new QWidget( mailboxView );	widget_4->setObjectName( "widget_4" );	QGridLayout *gridFolder = new QGridLayout(widget_4);	gridFolder->setMargin( 0 );	gridFolder->setSpacing( 0 );		folderView = new FolderListView(mailboxList, widget_4, "folderView");	connect(folderView, SIGNAL(viewMessageList()),  this, SLOT(showMessageList()) );	gridFolder->addWidget(folderView, 1, 1 );	#ifdef QTOPIA_PHONE	folderId = mailboxView->addWidget( widget_4 );	messageId = mailboxView->addWidget( widget_3 );		QMenu *folderContext = QSoftMenuBar::menuFor( widget_4 );	folderContext->addAction( composeButton );	folderContext->addAction( getMailButton );// 	folderContext->addAction( sendMailButton );        folderContext->addAction( searchButton );	folderContext->addAction( cancelButton );	folderContext->addAction( emptyTrashAction );        folderContext->addAction( settingsAction );		QMenu *messageContext = QSoftMenuBar::menuFor( widget_3 );        messageContext->addAction( composeButton );	messageContext->addAction( deleteMailAction );	messageContext->addAction( moveAction );	messageContext->addAction( copyAction );	messageContext->addAction( selectAllAction );#else	mailboxView->addTab( widget_4, tr( "Folders" ) );	mailboxView->addTab( widget_3, appTitle );#endif    }    /*  Folder and Message View specific init not related to placement	*/    QStringList columns;    columns << tr( "Folders" );    folderView->setColumnCount( columns.count() );    folderView->setHeaderLabels( columns );    folderView->setRootIsDecorated( false );    QHeaderView *header = folderView->header();    header->setMovable( false );    header->setClickable( false );    QAction *fvWhatsThis = QWhatsThis::createAction( folderView );    fvWhatsThis->setText( tr("A list of your folders.  You can tap Outbox and then tap the Messages tab to see the messages currently in the outbox.") );    #ifdef QTOPIA_PHONE    folderView->header()->resizeSection( 0, qApp->desktop()->width() );    folderView->folderParentMenu(mb);#else    QMenu *options = folderView->folderParentMenu(mb);    options->setTitle( tr( "&Options" ) );    mb->addMenu( options );    /* Corner button	*/    QPushButton *cornerButton = new QPushButton(widget_3);    cornerButton->setIcon( QIcon(":image/qtmail/menu") );    connect(cornerButton, SIGNAL( clicked() ),	    this, SLOT( cornerButtonClicked() ) );        QAction *cbWhatsThis = QWhatsThis::createAction( cornerButton );    cbWhatsThis->setText( tr("Toggle display of the column headers by tapping this icon.") );#ifdef QTOPIA4_TODO    messageView()->setCornerWidget( cornerButton );#endif#endif    progressBar = new StatusProgressBar( vbox );    vboxLayout->addWidget( progressBar );    setCentralWidget( vbox );    setWindowTitle( appTitle );}void EmailClient::update(){    QTableWidgetItem *current = messageView()->currentItem();    if ( current && messageView()->isItemSelected( current ) )	messageView()->scrollToItem( current );    if ( currentMailboxWidgetId() == folderId ) {	folderView->setFocus();    } else if ( currentMailboxWidgetId() == messageId ) {	messageView()->setFocus();    }    mailboxList->writeDirtyHeaders();    mailboxList->compact();    //  In case user changed status of sent/unsent or read/unread messages    Folder *folder = folderView->currentFolder();    if ( folder ) {	updateFolderCount( folder->mailbox() );    }}void EmailClient::cancel(){    if ( !cancelButton->isEnabled() )	return;    emailHandler->cancel();    progressBar->reset();    isSending( false );    isReceiving( false );}/*  Called when the user just exits the writemail window.  We don't know what he wanted    to do, but we should be able to determine it    Close event is handled by qtmailwindow, so no raise signal is neccessary*/void EmailClient::autosaveMail(const Email &mail){    // if uuid is null, it's a new mail    bool isNew = mail.uuid().isNull();    //  Always autosave new messages to drafts folder    if ( isNew ) {	saveAsDraft( mail );    } else {	// update mail in same mailbox as it was previously stored	if ( mailboxList->mailbox(OutboxString)->email( mail.uuid() ) != NULL ) {	    enqueueMail( mail );	} else {	    saveAsDraft( mail );	}    }}/*  Enqueue mail must always store the mail in the outbox   */void EmailClient::enqueueMail(const Email &mailIn){    Email mail(mailIn);    // if uuid is null, it's a new mail    bool isNew = mail.uuid().isNull();    if ( isNew ) {	mailResponded();	mail.setUuid( mailboxList->mailbox(OutboxString)->generateUuid() );	mail.encodeMail();	if ( !mailboxList->mailbox(OutboxString)->addMail(mail) ) {	    accessError(mailboxList->mailbox(OutboxString) );	    return;	}    } else {	mail.encodeMail();		// two possibilities, mail was originally from drafts but is now enqueued, or	// the mail was in the outbox previously as well.	if ( mailboxList->mailbox(DraftsString)->email( mail.uuid() ) != NULL ) {	    mailboxList->mailbox(DraftsString)->removeMail( mail.uuid(), false );	}		if ( !mailboxList->mailbox(OutboxString)->addMail( mail ) ) {	    accessError( mailboxList->mailbox(OutboxString) );	    return;	}    }#ifndef QTOPIA_PHONE    folderView->changeToSystemFolder( OutboxString );    showMessageList();#else    sendAllQueuedMail();    showFolderList();    folderView->setFocus();#endif    emit raiseWidget(this, appTitle );#ifndef QTOPIA_DESKTOP    if (closeAfterWrite) {	closeAfterTransmissionsFinished();	if (isTransmitting()) // prevents flicker	    QTMailWindow::singleton()->hide();	else	    QTMailWindow::singleton()->close();    }#endif}/*  Simple, do nothing	*/void EmailClient::discardMail(){    // Reset these in case user chose reply but discarded message    repliedFromUuid = QUuid();    repliedFlags = 0;    emit raiseWidget( this, appTitle );#ifndef QTOPIA_DESKTOP    if (closeAfterWrite) {	closeAfterTransmissionsFinished();	if (isTransmitting())	    QTMailWindow::singleton()->hide();	else	    QTMailWindow::singleton()->close();    }#endif}void EmailClient::saveAsDraft(const Email &mailIn){    Email mail(mailIn);    // if uuid is null, it's a new mail    bool isNew = mail.uuid().isNull();    if ( isNew ) {	mailResponded();	mail.setUuid( mailboxList->mailbox(DraftsString)->generateUuid() );		mail.encodeMail();	if ( !mailboxList->mailbox(DraftsString)->addMail(mail) ) {	    accessError( mailboxList->mailbox(DraftsString) );	    return;	}    } else {	mail.encodeMail();		// two possibilities, mail was originally from outbox but is now a draft, or	// the mail was in the drafts folder previously as well.	if ( mailboxList->mailbox(OutboxString)->email( mail.uuid() ) != NULL ) {	    mailboxList->mailbox(OutboxString)->removeMail( mail.uuid(), false );	}		if ( !mailboxList->mailbox(DraftsString)->addMail( mail ) ) {	    accessError( mailboxList->mailbox(DraftsString) );	    return;	}    }    folderView->changeToSystemFolder( DraftsString );    showMessageList();    emit raiseWidget(this, appTitle );}/*  Mark a message as replied/repliedall/forwarded  */void EmailClient::mailResponded(){    if ( !repliedFromUuid.isNull() ) {	QString mailbox = InboxString;  //default search path	Folder *folder = folderView->currentFolder();	if ( folder )	    mailbox = folder->mailbox();    //could be trash, etc..		Email *mail;	QListIterator<Email*> it = mailboxList->mailbox( mailbox)->entryIterator();	while ( it.hasNext() ) {	    mail = it.next();	    if ( mail->uuid() == repliedFromUuid ) {		mail->setStatus(repliedFlags, true );		mail->setDirty( true );		break;	    }	}	repliedFromUuid = QUuid();	repliedFlags = 0;    }}/*  Find an appropriate account for the mail and format    the mail accordingly    */

⌨️ 快捷键说明

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