| 1 |
/* |
| 2 |
* Copyright (C) 2019 ~ 2020 Deepin Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: Deng jinhui<[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: Deng jinhui <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#include "imagedemothread.h" |
| 22 |
|
| 23 |
RotateSaveThread::RotateSaveThread() |
| 24 |
{ |
| 25 |
setAutoDelete(true); |
| 26 |
} |
| 27 |
|
| 28 |
void RotateSaveThread::setDatas(QHash<QString, RotateSaveRequest> requests_bar) |
| 29 |
{ |
| 30 |
for (RotateSaveRequest i : requests_bar) { |
| 31 |
m_requests.append(i); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
void RotateSaveThread::run() |
| 36 |
{ |
| 37 |
for (RotateSaveRequest i : m_requests) { |
| 38 |
QString errorMsg; |
| 39 |
if (!UnionImage_NameSpace::rotateImageFIleWithImage(static_cast<int>(i.angel), i.image, i.path, errorMsg)) { |
| 40 |
qDebug() << errorMsg; |
| 41 |
qDebug() << "Save error"; |
| 42 |
} else { |
| 43 |
qDebug() << "Save Success"; |
| 44 |
} |
| 45 |
} |
| 46 |
if (m_requests.empty()) { |
| 47 |
qDebug() << "No Pic and Run Thread"; |
| 48 |
} else { |
| 49 |
qDebug() << "Save End"; |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
ImageDemoThreadControler::ImageDemoThreadControler() |
| 55 |
{ |
| 56 |
wait = new QTimer(this); |
| 57 |
rotateThreadPool.setMaxThreadCount(5); |
| 58 |
connect(wait, &QTimer::timeout, this, &ImageDemoThreadControler::startSave); |
| 59 |
} |
| 60 |
|
| 61 |
ImageDemoThreadControler::~ImageDemoThreadControler() |
| 62 |
{ |
| 63 |
rotateThreadPool.waitForDone(); |
| 64 |
} |
| 65 |
void ImageDemoThreadControler::addRotateAndSave(RotateSaveRequest request, int time_gap) |
| 66 |
{ |
| 67 |
if (NoRepeatRequest.contains(request.path)) { |
| 68 |
NoRepeatRequest[request.path].angel += request.angel; |
| 69 |
emit updateRotate(static_cast<int>(NoRepeatRequest[request.path].angel)); |
| 70 |
} else { |
| 71 |
NoRepeatRequest.insert(request.path, request); |
| 72 |
} |
| 73 |
wait->start(time_gap); |
| 74 |
} |
| 75 |
|
| 76 |
void ImageDemoThreadControler::startSave() |
| 77 |
{ |
| 78 |
emit updateRotate(0); |
| 79 |
RotateSaveThread *thread = new RotateSaveThread; |
| 80 |
thread->setDatas(NoRepeatRequest); |
| 81 |
NoRepeatRequest.clear(); |
| 82 |
rotateThreadPool.start(thread); |
| 83 |
wait->stop(); |
| 84 |
} |