2 * Copyright (C) 2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "croppedimagesizerasyncworker.h"
19#include "croppedimagesizer.h"
21#include <QNetworkReply>
22#include <QtConcurrentRun>
24CroppedImageSizerAsyncWorker::CroppedImageSizerAsyncWorker(CroppedImageSizer *sizer, QNetworkReply *reply)
29 connect(m_reply, &QNetworkReply::finished, this, &CroppedImageSizerAsyncWorker::requestFinished);
32void CroppedImageSizerAsyncWorker::abort()
34 // This runs on main thread
35 QMutexLocker locker(&m_mutex);
37 // If we already started the future run we can't abort the reply
38 // since we don't know at which stage the future is, just let it finish
40 QMetaObject::invokeMethod(m_reply, "abort", Qt::QueuedConnection);
44void CroppedImageSizerAsyncWorker::requestFinished()
46 // This runs on main thread
47 QMutexLocker locker(&m_mutex);
50 QtConcurrent::run(processRequestFinished, this);
52 // We were aborted delete ourselves
53 m_reply->deleteLater();
58void CroppedImageSizerAsyncWorker::processRequestFinished(CroppedImageSizerAsyncWorker *worker)
60 // This runs on non main thread
61 // m_reply has finished at this point and is protected against change by m_ignoreAbort
62 QImageReader reader(worker->m_reply);
63 const QSize imageSize = reader.size();
65 worker->m_mutex.lock();
66 if (worker->m_sizer) {
67 QMetaObject::invokeMethod(worker->m_sizer, "setImageSize", Qt::QueuedConnection, Q_ARG(QSize, imageSize));
69 worker->m_mutex.unlock();
71 // All work is done, delete ourselves
72 worker->m_reply->deleteLater();
73 worker->deleteLater();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list