Commit 2a19d195 authored by Volker Krause's avatar Volker Krause
Browse files

add async wallet loading during sending

svn path=/trunk/KDE/kdepim/mailtransport/; revision=620316
parent 4b8dbe97
......@@ -18,7 +18,6 @@ TransportManager
- deletetion of Transport objects during reload is a problem
(create a copy for edit?)
- load passwords if another instance opens the wallet
- add job scheduler (see knode) for async wallet loading during sending
TransportComboBox
-----------------
......
......@@ -72,7 +72,6 @@ void SendmailJob::wroteStdin()
void SendmailJob::receivedStdErr(KProcess * proc, char * data, int len)
{
Q_ASSERT( proc == mProcess );
kDebug() << k_funcinfo << endl;
mLastError += QString::fromLocal8Bit( data, len );
}
......
......@@ -168,7 +168,7 @@ void SmtpJob::doStart()
bool SmtpJob::doKill()
{
if ( !hasSubjobs() )
return false;
return true;
KIO::SimpleJob *job = static_cast<KIO::SimpleJob*>( subjobs().first() );
clearSubjobs();
KIO::Scheduler::cancelJob( job );
......@@ -177,7 +177,6 @@ bool SmtpJob::doKill()
void SmtpJob::slotResult(KJob * job)
{
kDebug() << k_funcinfo << job->error() << error() << endl;
TransportJob::slotResult( job );
removeSlaveFromPool( mSlave, error() != KIO::ERR_SLAVE_DIED );
if ( !error() )
......@@ -196,7 +195,6 @@ void SmtpJob::dataRequest(KIO::Job * job, QByteArray & data)
void SmtpJob::slaveError(KIO::Slave * slave, int errorCode, const QString & errorMsg)
{
kDebug() << k_funcinfo << errorCode << errorMsg << endl;
removeSlaveFromPool( slave, errorCode != KIO::ERR_SLAVE_DIED );
if ( mSlave == slave ) {
setError( errorCode );
......
......@@ -76,7 +76,7 @@ void TransportMgr::sendBtnClicked()
connect( job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)) );
connect( job, SIGNAL(percent(KJob*,unsigned long)), SLOT(jobPercent(KJob*,unsigned long)) );
mCurrentJob = job;
job->start();
TransportManager::self()->schedule( job );
}
void TransportMgr::cancelBtnClicked()
......
......@@ -48,7 +48,7 @@ bool Transport::isValid() const
QString Transport::password()
{
if ( !mPasswordLoaded && requiresAuthentication() && mPassword.isEmpty() )
if ( !mPasswordLoaded && requiresAuthentication() && storePassword() && mPassword.isEmpty() )
TransportManager::self()->loadPasswords();
return mPassword;
}
......@@ -64,7 +64,7 @@ void Transport::setPassword(const QString & passwd)
bool Transport::isComplete() const
{
return !requiresAuthentication() || mPasswordLoaded;
return !requiresAuthentication() || !storePassword() || mPasswordLoaded;
}
QString Transport::authenticationTypeString() const
......
......@@ -36,6 +36,8 @@ class Transport;
*/
class MAILTRANSPORT_EXPORT TransportJob : public KCompositeJob
{
friend class TransportManager;
public:
/**
Creates a new mail transport job.
......@@ -74,6 +76,12 @@ class MAILTRANSPORT_EXPORT TransportJob : public KCompositeJob
*/
void setData( const QByteArray &data );
/**
Starts this job. It is recommended to not call this method directly but use
TransportManager::schedule() to execute the job instead.
@see TransportManager::schedule()
*/
virtual void start();
protected:
......
......@@ -122,6 +122,21 @@ void TransportManager::addTransport(Transport * transport)
emitChangesCommitted();
}
void TransportManager::schedule(TransportJob * job)
{
connect( job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)) );
// check if the job is waiting for the wallet
if ( !job->transport()->isComplete() ) {
kDebug() << k_funcinfo << "job waits for wallet: " << job << endl;
mWalletQueue << job;
loadPasswordsAsync();
return;
}
job->start();
}
TransportJob* TransportManager::createTransportJob(int transportId)
{
Transport *t = transportById( transportId, false );
......@@ -325,11 +340,20 @@ void TransportManager::loadPasswords()
{
foreach ( Transport *t, mTransports )
t->readPassword();
// flush the wallet queue
foreach ( TransportJob *job, mWalletQueue ) {
job->start();
}
mWalletQueue.clear();
emit passwordsChanged();
}
void TransportManager::loadPasswordsAsync()
{
kDebug() << k_funcinfo << endl;
// check if there is anything to do at all
bool found = false;
foreach ( Transport *t, mTransports ) {
......@@ -365,6 +389,7 @@ void TransportManager::loadPasswordsAsync()
void TransportManager::slotWalletOpened( bool success )
{
kDebug() << k_funcinfo << endl;
mWalletAsyncOpen = false;
if ( !success ) {
mWalletOpenFailed = true;
......@@ -430,4 +455,9 @@ void TransportManager::dbusServiceOwnerChanged(const QString & service, const QS
QDBusConnection::sessionBus().registerService( DBUS_SERVICE_NAME );
}
void TransportManager::jobResult(KJob * job)
{
mWalletQueue.removeAll( static_cast<TransportJob*>( job ) );
}
#include "transportmanager.moc"
......@@ -26,6 +26,7 @@
#include <QObject>
class KConfig;
class KJob;
namespace KWallet {
class Wallet;
......@@ -70,6 +71,9 @@ class MAILTRANSPORT_EXPORT TransportManager : public QObject
@param id The identifier of the Transport.
@param def if set to true, the default transport will be returned if the
specified Transport object could not be found, 0 otherwise.
@returns A Transport object for immediate use. It might become invalid as
soon as the event loop is entered again due to remote changes. If you need
to store a Transport object, store the transport identifier instead.
*/
Transport* transportById( int id, bool def = true ) const;
......@@ -78,6 +82,8 @@ class MAILTRANSPORT_EXPORT TransportManager : public QObject
@param name The transport name.
@param def if set to true, the default transport will be returned if the
specified Transport object could not be found, 0 otherwise.
@returns A Transport object for immediate use, see transportById() for
limitations.
*/
Transport* transportByName( const QString &name, bool def = true ) const;
......@@ -109,6 +115,14 @@ class MAILTRANSPORT_EXPORT TransportManager : public QObject
*/
TransportJob* createTransportJob( int transportId );
/**
Executes the given transport job. This is the preferred way to start
transport jobs. It takes care of asynchronously loading passwords from
KWallet if necessary.
@param job The completely configured transport job to execute.
*/
void schedule( TransportJob* job );
public slots:
/**
Returns true if there are no mail transports at all.
......@@ -193,6 +207,7 @@ class MAILTRANSPORT_EXPORT TransportManager : public QObject
void slotTransportsChanged();
void slotWalletOpened( bool success );
void dbusServiceOwnerChanged( const QString &service, const QString &oldOwner, const QString &newOwner );
void jobResult( KJob* job );
private:
static TransportManager* mInstance;
......@@ -204,6 +219,7 @@ class MAILTRANSPORT_EXPORT TransportManager : public QObject
bool mWalletAsyncOpen;
int mDefaultTransportId;
bool mIsMainInstance;
QList<TransportJob*> mWalletQueue;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment