Skip to content

Commit

Permalink
[Azoth Xoox] Added cancellation for long-running VCard requests.
Browse files Browse the repository at this point in the history
Actually for the corresponding futures, so that the caller doesn't wait
on them forever holding resources.
  • Loading branch information
0xd34df00d committed Nov 26, 2017
1 parent dab2208 commit 135a3c0
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/plugins/azoth/plugins/xoox/entrybase.cpp
Expand Up @@ -33,6 +33,7 @@
#include <QInputDialog>
#include <QtDebug>
#include <QBuffer>
#include <QTimer>
#include <QCryptographicHash>
#include <QXmppVCardIq.h>
#include <QXmppPresence.h>
Expand Down Expand Up @@ -451,14 +452,32 @@ namespace Xoox

QFutureInterface<QImage> iface;
iface.reportStarted ();

const auto cancelTimer = new QTimer;
cancelTimer->setSingleShot (true);
cancelTimer->setTimerType (Qt::VeryCoarseTimer);
cancelTimer->start (120 * 1000);
connect (cancelTimer,
&QTimer::timeout,
[iface, cancelTimer] () mutable
{
if (!iface.isFinished ())
Util::ReportFutureResult (iface, QImage {});
cancelTimer->deleteLater ();
});

Account_->GetClientConnection ()->FetchVCard (GetJID (),
[iface] (const QXmppVCardIq& iq) mutable
[iface, cancelTimer] (const QXmppVCardIq& iq) mutable
{
if (iface.isFinished ())
return;

const auto& photo = iq.photo ();
const auto image = photo.isEmpty () ?
QImage {} :
QImage::fromData (photo);
iface.reportFinished (&image);
delete cancelTimer;
});

return iface.future ();
Expand Down

0 comments on commit 135a3c0

Please sign in to comment.