Commit 2faf5a52 authored by Ahmad Samir's avatar Ahmad Samir Committed by Ingo Klöcker
Browse files

EncryptEMailController: minor refactor

- Make ensuareWizardCreated() non-const, this will make protocol() and
  protocolAsString() non-cost too
- Remove slotWizardRecipientsResolved and connect directly to
  recipientsResolved
- Replace one QTimer::singleShot() with queued method invocation
parent 17587942
Pipeline #180515 passed with stage
in 5 minutes and 48 seconds
......@@ -48,11 +48,10 @@ public:
explicit Private(Mode mode, EncryptEMailController *qq);
private:
void slotWizardRecipientsResolved();
void slotWizardCanceled();
private:
void ensureWizardCreated() const;
void ensureWizardCreated();
void ensureWizardVisible();
void cancelAllTasks();
......@@ -63,7 +62,7 @@ private:
const Mode mode;
std::vector< std::shared_ptr<EncryptEMailTask> > runnable, completed;
std::shared_ptr<EncryptEMailTask> cms, openpgp;
mutable QPointer<EncryptEMailWizard> wizard;
QPointer<EncryptEMailWizard> wizard;
};
EncryptEMailController::Private::Private(Mode m, EncryptEMailController *qq)
......@@ -112,13 +111,13 @@ void EncryptEMailController::setProtocol(Protocol proto)
d->wizard->setPresetProtocol(proto);
}
Protocol EncryptEMailController::protocol() const
Protocol EncryptEMailController::protocol()
{
d->ensureWizardCreated();
return d->wizard->selectedProtocol();
}
const char *EncryptEMailController::protocolAsString() const
const char *EncryptEMailController::protocolAsString()
{
switch (protocol()) {
case OpenPGP: return "OpenPGP";
......@@ -141,11 +140,6 @@ void EncryptEMailController::startResolveRecipients(const std::vector<Mailbox> &
d->ensureWizardVisible();
}
void EncryptEMailController::Private::slotWizardRecipientsResolved()
{
Q_EMIT q->recipientsResolved();
}
void EncryptEMailController::Private::slotWizardCanceled()
{
q->setLastError(gpg_error(GPG_ERR_CANCELED), i18n("User cancel"));
......@@ -256,7 +250,7 @@ void EncryptEMailController::doTaskDone(const Task *task, const std::shared_ptr<
d->openpgp.reset();
}
QTimer::singleShot(0, this, SLOT(schedule()));
QMetaObject::invokeMethod(this, [this]() { d->schedule(); }, Qt::QueuedConnection);
}
void EncryptEMailController::cancel()
......@@ -287,7 +281,7 @@ void EncryptEMailController::Private::cancelAllTasks()
}
}
void EncryptEMailController::Private::ensureWizardCreated() const
void EncryptEMailController::Private::ensureWizardCreated()
{
if (wizard) {
return;
......@@ -297,8 +291,8 @@ void EncryptEMailController::Private::ensureWizardCreated() const
w->setAttribute(Qt::WA_DeleteOnClose);
Kleo::EMailOperationsPreferences prefs;
w->setQuickMode(prefs.quickEncryptEMail());
connect(w.get(), SIGNAL(recipientsResolved()), q, SLOT(slotWizardRecipientsResolved()), Qt::QueuedConnection);
connect(w.get(), SIGNAL(canceled()), q, SLOT(slotWizardCanceled()), Qt::QueuedConnection);
connect(w.get(), &EncryptEMailWizard::recipientsResolved, q, &EncryptEMailController::recipientsResolved, Qt::QueuedConnection);
connect(w.get(), &EncryptEMailWizard::canceled, q, [this]() { slotWizardCanceled(); }, Qt::QueuedConnection);
wizard = w.release();
}
......
......@@ -58,8 +58,8 @@ public:
}
void setProtocol(GpgME::Protocol proto);
const char *protocolAsString() const;
GpgME::Protocol protocol() const;
const char *protocolAsString();
GpgME::Protocol protocol();
void startResolveRecipients();
void startResolveRecipients(const std::vector<KMime::Types::Mailbox> &recipients, const std::vector<KMime::Types::Mailbox> &senders);
......@@ -83,9 +83,6 @@ private:
class Private;
kdtools::pimpl_ptr<Private> d;
Q_PRIVATE_SLOT(d, void slotWizardRecipientsResolved())
Q_PRIVATE_SLOT(d, void slotWizardCanceled())
Q_PRIVATE_SLOT(d, void schedule())
};
} // Crypto
......
Supports Markdown
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