📄 emailclient.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.******************************************************************************/#ifdef QTOPIA_DESKTOP#include <qcopenvelope_qd.h>#else#include <qtopia/qtopiaapplication.h>#include <qtopia/qcopenvelope.h>#endif#include <qtopia/qtopianamespace.h>#include <qtopia/qmimetype.h>#include <qtopia/qsoftmenubar.h>#include "emailclient.h"#include "folder.h"#include "searchview.h"#include "accountlist.h"#include "common.h"#ifdef QTOPIA_PHONE#include "composer.h"#include "selectfolder.h"#include "accountsettings.h"#endif#ifdef QTOPIA_PHONE#include "rightsnotification.h"#endif#include <qapplication.h>#include <qmessagebox.h>#include <qfile.h>#include <qcursor.h>#include <qstackedwidget.h>#include <qtooltip.h>#include <qwhatsthis.h>#include <qdesktopwidget.h>#include <qtcpsocket.h>#include <QHeaderView>#include <QListWidget>#include <QDebug>#include <qtmailwindow.h>#include <qtreewidget.h>#ifndef LED_MAIL#define LED_MAIL 0#endif#ifndef QTOPIA_NO_MMS#include "drmattachmentlink.h"#endifbool isRightsObject( Email *mail );using namespace QtMail;static QIcon* pm_folder = 0;static QIcon* pm_trash = 0;//paths for qtmail, is settings, inbox, enclosuresQString getPath(const QString& fn, bool isdir=false){ QString p = Qtopia::applicationFileName("qtmail",fn); if (isdir) { QDir dir(p); if ( !dir.exists() ) dir.mkdir( dir.path() ); p += "/"; } return p;}#ifndef QTOPIA_NO_MMSstatic void deleteDrmAttachments( Email &mail ){ if( mail.type() != MailMessage::MMS ) return; mail.readFromFile(); for( uint i = 0; i < mail.messagePartCount(); i++ ) { const MailMessagePart &part = mail.messagePartAt( i ); if( part.contentType() == "qtopia/drmattachmentlink" ) { DrmAttachmentLink link( part.decodedBody() ); if( !( QFile::exists( part.storedFilename() ) && QFileInfo( part.storedFilename() ).isSymLink() && QFile::remove( part.storedFilename() ) && QFile::rename( link.enclosureLocation(), part.storedFilename() ) ) ) { QContent( link.enclosureLocation() ).removeFiles(); } } }}#endif// A QProgressBar and status label combined. No percentage is show, as// that's represented by the bar alone.//class StatusProgressBar : public QProgressBar {public: StatusProgressBar( QWidget* parent ) : QProgressBar(parent), txtchanged(false) { QPalette p(palette()); p.setBrush(QPalette::Base,p.brush(QPalette::Window)); p.setBrush(QPalette::HighlightedText,p.brush(QPalette::WindowText)); setPalette(p); setAlignment(Qt::AlignHCenter); } QSize sizeHint() const { return QProgressBar::sizeHint()-QSize(0,8); } void setText(const QString& s) { if ( txt != s ) { if ( value() == maximum() ) reset(); txt = s; txtchanged = true; repaint(); } } QString text() const { return txt; }private: QString txt; bool txtchanged;};EmailClient::EmailClient( QWidget* parent, const QString name, Qt::WFlags fl ) : QMainWindow( parent, fl ), accountIdCount(0), mb(0), openedByUser(true), fetchTimer(this), showMessageType(MailAccount::SMS), autoDownloadMail(false){ setObjectName( name );#ifdef QTOPIA_PHONE appTitle = tr("Messages");#else appTitle = tr("Email");#endif emailHandler = new EmailHandler(); connect( &fetchTimer, SIGNAL(timeout()), this, SLOT( automaticFetch() ) ); autoGetMail = false; mailboxList = new MailboxList(this); accountList = new AccountList(this, "accountList"); getPath("enclosures/", true); //create directory enclosures sending = false; receiving = false; previewingMail = false; mailIdCount = 1; allAccounts = false; closeAfterWrite = false; closeAfterView = false; closeAfterTransmissions = false; mMessageView = 0; invalidId = -1; folderId = -2; messageId = -3; init(); connect(emailHandler, SIGNAL(mailSent(int)), this, SLOT(mailSent(int)) ); connect(emailHandler, SIGNAL(smtpError(int,QString&)), this, SLOT(smtpError(int,QString&)) ); connect(emailHandler, SIGNAL(popError(int,QString&)), this, SLOT(popError(int,QString&)) ); connect(emailHandler, SIGNAL(smsError(int,QString&)), this, SLOT(smsError(int,QString&)) );#ifndef QTOPIA_NO_MMS connect(emailHandler, SIGNAL(mmsError(int,QString&)), this, SLOT(mmsError(int,QString&)) );#endif connect(emailHandler, SIGNAL(unresolvedUidlList(QString&,QStringList&)), this, SLOT(unresolvedUidlArrived(QString&,QStringList&)) ); connect(emailHandler, SIGNAL(failedList(QStringList&)), this, SLOT(failedList(QStringList&)) );#ifdef QTOPIA_PHONE connect( new NotificationService( this ), SIGNAL(saveMail(const Email&)), this, SLOT(mailArrived(const Email&)) );#endif connect(folderView, SIGNAL(folderSelected(Folder*)), this, SLOT(folderSelected(Folder*)) ); connect(folderView, SIGNAL( emptyFolder() ), this, SLOT( emptyFolder() ) ); connect(emailHandler, SIGNAL(mailArrived(const Email&)), this, SLOT(mailArrived(const Email&)) ); connect(emailHandler, SIGNAL(mailTransferred(int)), this, SLOT(allMailArrived(int)) ); //imap connect(emailHandler, SIGNAL(serverFolders()), this, SLOT(imapServerFolders()) ); connect(mailboxList, SIGNAL( stringStatus(QString&) ), this, SLOT( setStatusText(QString&) ) ); connect(&showMessageTimer, SIGNAL( timeout() ), this, SLOT( displayRecentMessage() )); connect(accountList, SIGNAL( checkAccount(int) ), this, SLOT(selectAccount(int)) ); connect(&checkAccountTimer, SIGNAL( timeout() ), this, SLOT(selectAccountTimeout()) ); queueStatus = 0; accountList->readAccounts(); updateAccounts(); folderView->setupFolders(accountList ); readSettings(); nosuspend = 0; filesRead = false; showMsgList = false; openedByUser = QTMailWindow::singleton()->openedByUser(); suspendMailCount = false; QTimer::singleShot(0, this, SLOT( openFiles() ) ); // Hook up the "Email" and "SMS" QCop service handlers. new EmailService( this ); new SMSService( this );}EmailClient::~EmailClient(){ AddressPicker::addressList()->save(); delete pm_folder; delete pm_trash; EmailListItem::deletePixmaps();}void EmailClient::openFiles(){ if ( filesRead ) { if ( !cachedDisplayMailbox.isEmpty() ) displayMail(cachedDisplayMailbox, cachedDisplayMailUuid); return; } filesRead = true; readMail(); //connect after mail has been read to speed up reading */ connect(mailboxList, SIGNAL( mailAdded(Email*,const QString&) ), this, SLOT( mailFromDisk(Email*,const QString&) ) ); connect(mailboxList, SIGNAL( mailUpdated(Email*,const QString&) ), this, SLOT( mailUpdated(Email*,const QString&) ) ); connect(mailboxList, SIGNAL( mailRemoved(const QUuid&,const QString&) ), this, SLOT( mailRemoved(const QUuid&,const QString&) ) ); connect(mailboxList, SIGNAL( externalEdit(const QString&) ), this, SLOT(externalEdit(const QString&) ) ); if ( !cachedDisplayMailbox.isEmpty() ) { displayMail(cachedDisplayMailbox, cachedDisplayMailUuid); } else { //No default select for QTreeWidget Folder* currentFolder = folderView->currentFolder(); if(!currentFolder) folderView->changeToSystemFolder(InboxString); else folderSelected( folderView->currentFolder() ); displayPreviousMail(); }} void EmailClient::displayPreviousMail(){ if (!mMessageView) return; QSettings mailconf("Trolltech","qtmail"); mailconf.beginGroup("qtmailglobal"); QUuid id( mailconf.value("currentmail").toString() ); mailconf.endGroup(); if ( !id.isNull() ) { EmailListItem *item = messageView()->getRef( id ); if (item) { messageView()->clearSelection(); messageView()->setItemSelected( item, TRUE ); messageView()->setCurrentItem( item ); messageView()->scrollToItem( item ); } }} void EmailClient::displayMail(const QString &mailbox, const QUuid &id){ EmailFolderList *box = mailboxList->mailbox(mailbox); if ( box ) { folderView->changeToSystemFolder( mailbox ); folderSelected( folderView->currentFolder() ); EmailListItem *item = messageView()->getRef( id ); if ( item ) { messageView()->clearSelection(); messageView()->setItemSelected( item, TRUE ); messageView()->setCurrentItem( item ); queryItemSelected(); } } cachedDisplayMailbox = "";}void EmailClient::displayRecentMessage(){ if ( checkMailConflict( tr("Should this mail be saved in Drafts before viewing the new mail?"), tr("View Mail message will be ignored")) ) return; Folder *folder = 0; QListIterator<MailAccount*> it = accountList->accountIterator(); while ( it.hasNext() ) { if ( it.next()->accountType() == showMessageType ) { folder = it.peekPrevious(); break; } } openFiles(); if (!folder) return; FolderListItem *item = 0; FolderListItem* top = 0; for (int i = 0; i < folderView->topLevelItemCount(); ++i){ top = static_cast<FolderListItem*>(folderView->topLevelItem(i)); if(top->folder() == folder){ item = top; break; } else{ for(int j = 0; j < top->childCount(); ++j){ item = static_cast<FolderListItem*>(top->child(j)); if(item->folder() == folder) break; else item = 0; } if(item) break; } } if (!item || (item->folder() != folder)) return; folderView->setCurrentItem( item ); folderSelected( folderView->currentFolder() ); showMessageList(); if (!showMsgList) { if (!showMsgId.isNull()) { EmailListItem *item = messageView()->getRef(showMsgId); if (item) { messageView()->clearSelection(); messageView()->setItemSelected(item, true); messageView()->setCurrentItem(item); messageView()->scrollToItem(item); } } queryItemSelected(); } if (!openedByUser) // Close qtmail when returning to folder view! closeAfterView = true;}bool EmailClient::cleanExit(bool force){ bool result = true; if (sending || receiving) { if (force) { qDebug() << "forcing cancel to exit"; cancel(); //abort all transfer } result = false; } if (mailboxList) mailboxList->writeDirtyHeaders(); saveSettings(); accountList->saveAccounts(); return result;}void EmailClient::closeAfterTransmissionsFinished(){ closeAfterWrite = false; closeAfterTransmissions = true;}bool EmailClient::isTransmitting(){ return nosuspend;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -