Commit 6d87f356 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to findaccountinfojob

parent 31a332cd
Pipeline #41358 failed with stage
in 12 minutes and 50 seconds
......@@ -10,6 +10,7 @@
#include <KPIMTextEdit/PlainTextEditorWidget>
#include <KPIMTextEdit/PlainTextEditor>
#include "util/util_p.h"
#include "util/findaccountinfojob.h"
#include "libksieve_debug.h"
#include <KLocalizedString>
......@@ -111,13 +112,21 @@ void SieveDebugDialog::slotDiagNextAccount()
connect(mShutDownJob, &QTimer::timeout, this, &SieveDebugDialog::slotShutDownJob);
}
mShutDownJob->start(30 * 1000); // 30 seconds
QString ident = mResourceIdentifier.first();
const QString ident = mResourceIdentifier.first();
mEdit->editor()->appendPlainText(i18n("Collecting data for account '%1'...\n", ident));
mEdit->editor()->appendPlainText(i18n("------------------------------------------------------------\n"));
auto *job = new FindAccountInfoJob(this);
connect(job, &FindAccountInfoJob::findAccountInfoFinished, this, &SieveDebugDialog::slotFindAccountInfoFinished);
job->setIdentifier(ident);
job->setProvider(mPasswordProvider);
job->start();
}
void SieveDebugDialog::slotFindAccountInfoFinished(const KSieveUi::Util::AccountInfo &info)
{
// Detect URL for this IMAP account
const KSieveUi::Util::AccountInfo info = KSieveUi::Util::fullAccountInfo(ident, mPasswordProvider);
const QUrl url = info.sieveUrl;
if (!url.isValid()) {
mEdit->editor()->appendPlainText(i18n("(Account does not support Sieve)\n\n"));
......@@ -149,15 +158,25 @@ void SieveDebugDialog::slotDiagNextScript()
return;
}
QString scriptFile = mScriptList.constFirst();
const QString scriptFile = mScriptList.constFirst();
mScriptList.pop_front();
mEdit->editor()->appendPlainText(i18n("Contents of script '%1':\n", scriptFile));
const KSieveUi::Util::AccountInfo info = KSieveUi::Util::fullAccountInfo(mResourceIdentifier.constFirst(), mPasswordProvider);
auto *job = new FindAccountInfoJob(this);
connect(job, &FindAccountInfoJob::findAccountInfoFinished, this, &SieveDebugDialog::slotFindAccountInfoForScriptFinished);
job->setIdentifier(mResourceIdentifier.constFirst());
job->setProvider(mPasswordProvider);
job->setProperty("scriptfile", scriptFile);
job->start();
}
void SieveDebugDialog::slotFindAccountInfoForScriptFinished(const KSieveUi::Util::AccountInfo &info)
{
mUrl = info.sieveUrl;
mUrl = mUrl.adjusted(QUrl::RemoveFilename);
const QString scriptFile = sender()->property("scriptfile").toString();
mUrl.setPath(mUrl.path() + QLatin1Char('/') + scriptFile);
mSieveJob = KManageSieve::SieveJob::get(mUrl);
......
......@@ -10,6 +10,7 @@
#define KSIEVE_KSIEVEUI_SIEVEDEBUGDIALOG_H
#include "ksieveui_export.h"
#include "util_p.h"
#include <QDialog>
#include <QUrl>
......@@ -35,7 +36,7 @@ class KSIEVEUI_EXPORT SieveDebugDialog : public QDialog
Q_OBJECT
public:
explicit SieveDebugDialog(SieveImapPasswordProvider *passwordProvider, QWidget *parent = nullptr);
~SieveDebugDialog();
~SieveDebugDialog() override;
Q_SIGNALS:
void result(bool success);
......@@ -49,6 +50,8 @@ private Q_SLOTS:
void slotShutDownJob();
private:
void slotFindAccountInfoFinished(const KSieveUi::Util::AccountInfo &info);
void slotFindAccountInfoForScriptFinished(const KSieveUi::Util::AccountInfo &info);
void writeConfig();
void readConfig();
KManageSieve::SieveJob *mSieveJob = nullptr;
......
......@@ -14,31 +14,31 @@
#include <QUrlQuery>
using namespace KSieveUi;
findAccountInfoJob::findAccountInfoJob(QObject *parent)
FindAccountInfoJob::FindAccountInfoJob(QObject *parent)
: QObject(parent)
{
}
findAccountInfoJob::~findAccountInfoJob()
FindAccountInfoJob::~FindAccountInfoJob()
{
}
bool findAccountInfoJob::canStart() const
bool FindAccountInfoJob::canStart() const
{
return !mIdentifier.isEmpty() && mProvider;
}
void findAccountInfoJob::sendAccountInfo()
void FindAccountInfoJob::sendAccountInfo()
{
deleteLater();
Q_EMIT findAccountInfoFinished(mAccountInfo);
}
void findAccountInfoJob::start()
void FindAccountInfoJob::start()
{
if (canStart()) {
if (!canStart()) {
qCWarning(LIBKSIEVE_LOG) << "Impossible to start findAccountInfoJob";
sendAccountInfo();
return;
......@@ -212,32 +212,32 @@ void findAccountInfoJob::start()
}
}
QString findAccountInfoJob::identifier() const
QString FindAccountInfoJob::identifier() const
{
return mIdentifier;
}
void findAccountInfoJob::setIdentifier(const QString &newIdentifier)
void FindAccountInfoJob::setIdentifier(const QString &newIdentifier)
{
mIdentifier = newIdentifier;
}
bool findAccountInfoJob::withVacationFileName() const
bool FindAccountInfoJob::withVacationFileName() const
{
return mWithVacationFileName;
}
void findAccountInfoJob::setWithVacationFileName(bool newWithVacationFileName)
void FindAccountInfoJob::setWithVacationFileName(bool newWithVacationFileName)
{
mWithVacationFileName = newWithVacationFileName;
}
SieveImapPasswordProvider *findAccountInfoJob::provider() const
SieveImapPasswordProvider *FindAccountInfoJob::provider() const
{
return mProvider;
}
void findAccountInfoJob::setProvider(SieveImapPasswordProvider *newProvider)
void FindAccountInfoJob::setProvider(SieveImapPasswordProvider *newProvider)
{
mProvider = newProvider;
}
......@@ -12,12 +12,12 @@
#include <QObject>
namespace KSieveUi {
class SieveImapPasswordProvider;
class findAccountInfoJob : public QObject
class FindAccountInfoJob : public QObject
{
Q_OBJECT
public:
explicit findAccountInfoJob(QObject *parent = nullptr);
~findAccountInfoJob() override;
explicit FindAccountInfoJob(QObject *parent = nullptr);
~FindAccountInfoJob() override;
void start();
......
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