Commit 82dc7f43 authored by David Faure's avatar David Faure
Browse files

pop3: introduce base class BaseJob

parent 5b6ead07
......@@ -53,11 +53,13 @@ void POPSession::slotSlaveError(KIO::Slave *slave, int errorCode, const QString
Q_EMIT slaveError(errorCode, errorMessage);
} else {
// Let the job deal with the problem
mCurrentJob->slaveError(errorCode, errorMessage);
auto slaveBaseJob = qobject_cast<SlaveBaseJob *>(mCurrentJob);
Q_ASSERT(slaveBaseJob);
slaveBaseJob->slaveError(errorCode, errorMessage);
}
}
void POPSession::setCurrentJob(SlaveBaseJob *job)
void POPSession::setCurrentJob(BaseJob *job)
{
mCurrentJob = job;
}
......@@ -182,20 +184,28 @@ static QString intListToString(const QList<int> &intList)
return idList;
}
SlaveBaseJob::SlaveBaseJob(POPSession *POPSession)
: mJob(nullptr)
, mPOPSession(POPSession)
BaseJob::BaseJob(POPSession *POPSession)
: mPOPSession(POPSession)
{
mPOPSession->setCurrentJob(this);
}
SlaveBaseJob::~SlaveBaseJob()
BaseJob::~BaseJob()
{
// Don't do that here, the job might be destroyed after another one was started
// and therefore overwrite the current job
// mPOPSession->setCurrentJob( 0 );
}
SlaveBaseJob::SlaveBaseJob(POPSession *POPSession)
: BaseJob(POPSession)
{
}
SlaveBaseJob::~SlaveBaseJob()
{
}
bool SlaveBaseJob::doKill()
{
if (mJob) {
......
......@@ -22,6 +22,7 @@ class Job;
class TransferJob;
}
class BaseJob;
class SlaveBaseJob;
class Settings;
......@@ -41,7 +42,7 @@ public:
// Sets the current SlaveBaseJob that is using the POPSession.
// If there is a job, all slave errors will be forwarded to that job
void setCurrentJob(SlaveBaseJob *job);
void setCurrentJob(BaseJob *job);
private Q_SLOTS:
void slotSlaveError(KIO::Slave *slave, int, const QString &);
......@@ -57,12 +58,23 @@ private:
QString authenticationToString(int type) const;
QPointer<KIO::Slave> mSlave;
SlaveBaseJob *mCurrentJob = nullptr;
BaseJob *mCurrentJob = nullptr;
const QString mPassword;
Settings &mSettings;
};
class SlaveBaseJob : public KJob
class BaseJob : public KJob
{
Q_OBJECT
public:
explicit BaseJob(POPSession *POPSession);
~BaseJob() override;
protected:
POPSession *mPOPSession = nullptr;
};
class SlaveBaseJob : public BaseJob
{
Q_OBJECT
......@@ -83,7 +95,6 @@ protected:
virtual void connectJob();
KIO::TransferJob *mJob = nullptr;
POPSession *mPOPSession = nullptr;
};
class LoginJob : public SlaveBaseJob
......
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