| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[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 "imageenginethread.h" |
| 22 |
#include "imageengineapi.h" |
| 23 |
#include <dgiovolumemanager.h> |
| 24 |
#include <dgiofile.h> |
| 25 |
#include <dgiofileinfo.h> |
| 26 |
#include <dgiovolume.h> |
| 27 |
#include <QImage> |
| 28 |
#include <QImageReader> |
| 29 |
#include <QDebug> |
| 30 |
#include <QDir> |
| 31 |
#include <DApplication> |
| 32 |
#include <DApplicationHelper> |
| 33 |
#include <QStandardPaths> |
| 34 |
#include <QDirIterator> |
| 35 |
#include <QSvgGenerator> |
| 36 |
#include "utils/imageutils.h" |
| 37 |
#include "utils/unionimage.h" |
| 38 |
#include "dbmanager/dbmanager.h" |
| 39 |
#include "application.h" |
| 40 |
#include "controller/signalmanager.h" |
| 41 |
#include "albumgloabl.h" |
| 42 |
#include "imagedataservice.h" |
| 43 |
#include "movieservice.h" |
| 44 |
|
| 45 |
DBImgInfo getDBInfo(const QString &srcpath, bool isVideo) |
| 46 |
{ |
| 47 |
using namespace utils::base; |
| 48 |
using namespace UnionImage_NameSpace; |
| 49 |
QFileInfo srcfi(srcpath); |
| 50 |
DBImgInfo dbi; |
| 51 |
dbi.fileName = srcfi.fileName(); |
| 52 |
dbi.filePath = srcpath; |
| 53 |
dbi.dirHash = utils::base::hashByString(QString()); |
| 54 |
dbi.importTime = QDateTime::currentDateTime(); |
| 55 |
if (isVideo) { |
| 56 |
dbi.itemType = ItemTypeVideo; |
| 57 |
//获取视频信息 |
| 58 |
MovieInfo movieInfo = MovieService::instance()->getMovieInfo(QUrl::fromLocalFile(srcpath)); |
| 59 |
|
| 60 |
dbi.changeTime = srcfi.lastModified(); |
| 61 |
|
| 62 |
if (!movieInfo.creation.isEmpty()) { |
| 63 |
dbi.time = QDateTime::fromString(movieInfo.creation); |
| 64 |
} else if (!srcfi.birthTime().isValid()) { |
| 65 |
dbi.time = srcfi.birthTime(); |
| 66 |
} else if (!srcfi.metadataChangeTime().isValid()) { |
| 67 |
dbi.time = srcfi.metadataChangeTime(); |
| 68 |
} else { |
| 69 |
dbi.time = dbi.changeTime; |
| 70 |
} |
| 71 |
} else { |
| 72 |
auto mds = getAllMetaData(srcpath); |
| 73 |
QString value = mds.value("DateTimeOriginal"); |
| 74 |
dbi.itemType = ItemTypePic; |
| 75 |
dbi.changeTime = QDateTime::fromString(mds.value("DateTimeDigitized"), "yyyy/MM/dd hh:mm"); |
| 76 |
if (!value.isEmpty()) { |
| 77 |
dbi.time = QDateTime::fromString(value, "yyyy/MM/dd hh:mm"); |
| 78 |
} else if (!srcfi.birthTime().isValid()) { |
| 79 |
dbi.time = srcfi.birthTime(); |
| 80 |
} else if (!srcfi.metadataChangeTime().isValid()) { |
| 81 |
dbi.time = srcfi.metadataChangeTime(); |
| 82 |
} else { |
| 83 |
dbi.time = dbi.changeTime; |
| 84 |
} |
| 85 |
} |
| 86 |
return dbi; |
| 87 |
} |
| 88 |
|
| 89 |
ImportImagesThread::ImportImagesThread() |
| 90 |
{ |
| 91 |
m_paths.clear(); |
| 92 |
//setAutoDelete(false); 禁用auto delete,防止崩溃 |
| 93 |
} |
| 94 |
|
| 95 |
ImportImagesThread::~ImportImagesThread() |
| 96 |
{ |
| 97 |
qDebug() << "ImportImagesThread destoryed"; |
| 98 |
} |
| 99 |
|
| 100 |
void ImportImagesThread::setData(QList<QUrl> &paths, QString &albumname, ImageEngineImportObject *obj, bool bdialogselect) |
| 101 |
{ |
| 102 |
m_urls = paths; |
| 103 |
m_albumname = albumname; |
| 104 |
m_obj = obj; |
| 105 |
m_bdialogselect = bdialogselect; |
| 106 |
m_type = DataType_UrlList; |
| 107 |
} |
| 108 |
|
| 109 |
void ImportImagesThread::setData(QStringList &paths, QString &albumname, ImageEngineImportObject *obj, bool bdialogselect) |
| 110 |
{ |
| 111 |
m_paths = paths; |
| 112 |
m_albumname = albumname; |
| 113 |
m_obj = obj; |
| 114 |
m_bdialogselect = bdialogselect; |
| 115 |
m_type = DataType_StringList; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
bool ImportImagesThread::ifCanStopThread(void *imgobject) |
| 120 |
{ |
| 121 |
static_cast<ImageEngineImportObject *>(imgobject)->removeThread(this); |
| 122 |
if (imgobject == m_obj) { |
| 123 |
return true; |
| 124 |
} |
| 125 |
return false; |
| 126 |
} |
| 127 |
|
| 128 |
void ImportImagesThread::runDetail() |
| 129 |
{ |
| 130 |
if (bneedstop) { |
| 131 |
m_obj->imageImported(false); |
| 132 |
m_obj->removeThread(this); |
| 133 |
return; |
| 134 |
} |
| 135 |
QStringList image_list; |
| 136 |
QStringList curAlbumImgPathList; |
| 137 |
if (m_albumname.length() > 0) { |
| 138 |
// 在相册中导入时, |
| 139 |
curAlbumImgPathList = DBManager::instance()->getPathsByAlbum(m_albumname); |
| 140 |
} else { |
| 141 |
// 不是在相册中导入时,allpic timeline .etc |
| 142 |
curAlbumImgPathList = DBManager::instance()->getAllPaths(); |
| 143 |
} |
| 144 |
//重复导入文件 |
| 145 |
QStringList curAlbumImportedPathList; |
| 146 |
// 拖拽导入 url |
| 147 |
if (m_type == DataType_UrlList) { |
| 148 |
QStringList urlLocalPathList; |
| 149 |
for (QUrl url : m_urls) { |
| 150 |
const QString path = url.toLocalFile(); |
| 151 |
urlLocalPathList << path; |
| 152 |
if (QFileInfo(path).isDir()) { |
| 153 |
auto finfos = utils::image::getImagesAndVideoInfo(path, true); |
| 154 |
for (auto finfo : finfos) { |
| 155 |
pathCheck(&image_list, &curAlbumImportedPathList, curAlbumImgPathList, finfo.absoluteFilePath()); |
| 156 |
} |
| 157 |
} else if (QFileInfo(path).exists()) { //文件存在 |
| 158 |
pathCheck(&image_list, &curAlbumImportedPathList, curAlbumImgPathList, path); |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
// 文件管理器选中 |
| 163 |
else if (m_type == DataType_StringList) { |
| 164 |
foreach (QString path, m_paths) { |
| 165 |
if (bneedstop) { |
| 166 |
m_obj->imageImported(false); |
| 167 |
m_obj->removeThread(this); |
| 168 |
return; |
| 169 |
} |
| 170 |
QFileInfo file(path); |
| 171 |
if (file.isDir()) { |
| 172 |
auto finfos = utils::image::getImagesAndVideoInfo(path, true); |
| 173 |
for (auto finfo : finfos) { |
| 174 |
pathCheck(&image_list, &curAlbumImportedPathList, curAlbumImgPathList, finfo.absoluteFilePath()); |
| 175 |
} |
| 176 |
} else if (file.exists()) { //文件存在 |
| 177 |
pathCheck(&image_list, &curAlbumImportedPathList, curAlbumImgPathList, path); |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
if (image_list.size() < 1) { |
| 183 |
if (curAlbumImportedPathList.size() < 1) { |
| 184 |
// 导入列表为空并且导入相同照片的列表也为空,视为导入失败,直接返回 |
| 185 |
emit dApp->signalM->ImportFailed(); |
| 186 |
m_obj->imageImported(false); |
| 187 |
m_obj->removeThread(this); |
| 188 |
return; |
| 189 |
} else if (curAlbumImportedPathList.size() > 0) { |
| 190 |
// 视为导入的图片全部为重复图片 |
| 191 |
// ImportImageLoader() 中,底部状态栏将显示导入状态,之后,核对是否存在重复图片,发送信号准备提示 |
| 192 |
emit dApp->signalM->RepeatImportingTheSamePhotos(image_list, curAlbumImportedPathList, m_albumname); |
| 193 |
// 导入重复照片提示 |
| 194 |
// emit dApp->signalM->sigAddDuplicatePhotos(); |
| 195 |
m_obj->imageImported(true); |
| 196 |
m_obj->removeThread(this); |
| 197 |
return; |
| 198 |
} |
| 199 |
} else if (image_list.size() > 0) { |
| 200 |
if (m_bdialogselect) { |
| 201 |
QFileInfo firstFileInfo(image_list.first()); |
| 202 |
static QString cfgGroupName = QStringLiteral("General"), cfgLastOpenPath = QStringLiteral("LastOpenPath"); |
| 203 |
dApp->setter->setValue(cfgGroupName, cfgLastOpenPath, firstFileInfo.path()); |
| 204 |
} |
| 205 |
// 判断当前导入路径是否为外接设备 |
| 206 |
int isMountFlag = 0; |
| 207 |
DGioVolumeManager *pvfsManager = new DGioVolumeManager; |
| 208 |
QList<QExplicitlySharedDataPointer<DGioMount>> mounts = pvfsManager->getMounts(); |
| 209 |
for (auto mount : mounts) { |
| 210 |
if (bneedstop || ImageEngineApi::instance()->closeFg()) { |
| 211 |
m_obj->imageImported(false); |
| 212 |
m_obj->removeThread(this); |
| 213 |
return; |
| 214 |
} |
| 215 |
QExplicitlySharedDataPointer<DGioFile> LocationFile = mount->getDefaultLocationFile(); |
| 216 |
QString strPath = LocationFile->path(); |
| 217 |
if (0 == image_list.first().compare(strPath)) { |
| 218 |
isMountFlag = 1; |
| 219 |
break; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
// 当前导入路径 |
| 224 |
if (isMountFlag) { |
| 225 |
QString strHomePath = QDir::homePath(); |
| 226 |
//获取系统现在的时间 |
| 227 |
QString strDate = QDateTime::currentDateTime().toString("yyyy-MM-dd"); |
| 228 |
QString basePath = QString("%1%2%3").arg(strHomePath, "/Pictures/照片/", strDate); |
| 229 |
QDir dir; |
| 230 |
if (!dir.exists(basePath)) { |
| 231 |
dir.mkpath(basePath); |
| 232 |
} |
| 233 |
QStringList newImagePaths; |
| 234 |
foreach (QString strPath, image_list) { |
| 235 |
if (bneedstop || ImageEngineApi::instance()->closeFg()) { |
| 236 |
m_obj->imageImported(false); |
| 237 |
m_obj->removeThread(this); |
| 238 |
return; |
| 239 |
} |
| 240 |
//取出文件名称 |
| 241 |
QStringList pathList = strPath.split("/", QString::SkipEmptyParts); |
| 242 |
QStringList nameList = pathList.last().split(".", QString::SkipEmptyParts); |
| 243 |
QString strNewPath = QString("%1%2%3%4%5%6").arg(basePath, "/", nameList.first(), QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch()), ".", nameList.last()); |
| 244 |
|
| 245 |
newImagePaths << strNewPath; |
| 246 |
//判断新路径下是否存在目标文件,若存在,下一次张 |
| 247 |
if (dir.exists(strNewPath)) { |
| 248 |
continue; |
| 249 |
} |
| 250 |
|
| 251 |
// 外接设备图片拷贝到系统 |
| 252 |
if (QFile::copy(strPath, strNewPath)) { |
| 253 |
|
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
image_list.clear(); |
| 258 |
image_list = newImagePaths; |
| 259 |
} |
| 260 |
|
| 261 |
DBImgInfoList dbInfos; |
| 262 |
QStringList pathlist; |
| 263 |
using namespace utils::image; |
| 264 |
int noReadCount = 0; |
| 265 |
bool bIsVideo = false; |
| 266 |
int count = 0; |
| 267 |
QStringList pathlistImport; |
| 268 |
DBImgInfoList dbInfosImport; |
| 269 |
for (auto imagePath : image_list) { |
| 270 |
bIsVideo = utils::base::isVideo(imagePath); |
| 271 |
if (!imageSupportRead(imagePath) && !bIsVideo) { |
| 272 |
noReadCount++; |
| 273 |
continue; |
| 274 |
} |
| 275 |
QFileInfo srcfi(imagePath); |
| 276 |
if (!srcfi.exists()) { //当前文件不存在 |
| 277 |
continue; |
| 278 |
} |
| 279 |
DBImgInfo info = getDBInfo(imagePath, bIsVideo); |
| 280 |
dbInfos << info; |
| 281 |
count++; |
| 282 |
dbInfosImport << info; |
| 283 |
pathlistImport << info.filePath; |
| 284 |
if (count == 200) { |
| 285 |
//导入相册数据库AlbumTable3 |
| 286 |
DBManager::instance()->insertIntoAlbumNoSignal(m_albumname, pathlistImport); |
| 287 |
ImageDataService::instance()->readThumbnailByPaths(pathlistImport, true, true); |
| 288 |
pathlistImport.clear(); |
| 289 |
//导入图片数据库ImageTable3 |
| 290 |
DBManager::instance()->insertImgInfos(dbInfosImport); |
| 291 |
dbInfosImport.clear(); |
| 292 |
} |
| 293 |
emit dApp->signalM->progressOfWaitDialog(image_list.size(), dbInfos.size()); |
| 294 |
} |
| 295 |
//导入相册数据库AlbumTable3 |
| 296 |
DBManager::instance()->insertIntoAlbumNoSignal(m_albumname, pathlistImport); |
| 297 |
ImageDataService::instance()->readThumbnailByPaths(pathlistImport, true, true); |
| 298 |
pathlistImport.clear(); |
| 299 |
//导入图片数据库ImageTable3 |
| 300 |
DBManager::instance()->insertImgInfos(dbInfosImport); |
| 301 |
dbInfosImport.clear(); |
| 302 |
emit dApp->signalM->progressOfWaitDialog(image_list.size(), dbInfos.size()); |
| 303 |
|
| 304 |
if (bneedstop) { |
| 305 |
m_obj->imageImported(false); |
| 306 |
m_obj->removeThread(this); |
| 307 |
return; |
| 308 |
} |
| 309 |
for (auto Info : dbInfos) { |
| 310 |
QFileInfo fi(Info.filePath); |
| 311 |
if (!fi.exists()) |
| 312 |
continue; |
| 313 |
pathlist << Info.filePath; |
| 314 |
} |
| 315 |
emit ImageEngineApi::instance()->sigLoadCompleted(); |
| 316 |
if (image_list.length() == pathlist.length() && !pathlist.isEmpty()) { |
| 317 |
if (pathlist.size() > 0) { |
| 318 |
emit dApp->signalM->updateStatusBarImportLabel(pathlist, 1, m_albumname); |
| 319 |
emit dApp->signalM->ImportSuccess(); |
| 320 |
} else { |
| 321 |
emit dApp->signalM->ImportFailed(); |
| 322 |
} |
| 323 |
// dApp->m_imageloader->ImportImageLoader(tempdbInfos, m_albumname);// 导入照片提示在此处理中 |
| 324 |
m_obj->imageImported(true); |
| 325 |
// ImportImageLoader() 中,底部状态栏将显示导入状态,之后,核对是否存在重复图片,发送信号准备提示 |
| 326 |
if (curAlbumImportedPathList.count() > 0) { |
| 327 |
emit dApp->signalM->RepeatImportingTheSamePhotos(image_list, curAlbumImportedPathList, m_albumname); |
| 328 |
} |
| 329 |
} else { |
| 330 |
//BUG#92844 额外提示未发现照片或文件 |
| 331 |
if (pathlist.isEmpty()) { |
| 332 |
emit dApp->signalM->ImportDonotFindPicOrVideo(); |
| 333 |
} else { |
| 334 |
emit dApp->signalM->ImportSomeFailed(image_list.length(), image_list.length() - pathlist.length()); |
| 335 |
} |
| 336 |
|
| 337 |
emit dApp->signalM->ImportFailed(); |
| 338 |
|
| 339 |
m_obj->imageImported(false); |
| 340 |
} |
| 341 |
m_obj->removeThread(this); |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
void ImportImagesThread::pathCheck(QStringList *image_list, QStringList *curAlbumImportedPathList, QStringList &curAlbumImgPathList, const QString &path) |
| 346 |
{ |
| 347 |
if (utils::image::imageSupportRead(path)) { |
| 348 |
if (curAlbumImgPathList.contains(path)) { |
| 349 |
*curAlbumImportedPathList << path; |
| 350 |
} else { |
| 351 |
*image_list << path; |
| 352 |
} |
| 353 |
} else if (utils::base::isVideo(path)) { |
| 354 |
if (MovieService::instance()->getMovieInfo(QUrl::fromLocalFile(path)).valid) { |
| 355 |
if (curAlbumImgPathList.contains(path)) { |
| 356 |
*curAlbumImportedPathList << path; |
| 357 |
} else { |
| 358 |
*image_list << path; |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
ImageRecoveryImagesFromTrashThread::ImageRecoveryImagesFromTrashThread() |
| 365 |
{ |
| 366 |
setAutoDelete(false); |
| 367 |
} |
| 368 |
|
| 369 |
void ImageRecoveryImagesFromTrashThread::setData(QStringList &paths) |
| 370 |
{ |
| 371 |
m_paths = paths; |
| 372 |
} |
| 373 |
|
| 374 |
void ImageRecoveryImagesFromTrashThread::runDetail() |
| 375 |
{ |
| 376 |
DBImgInfoList infos; |
| 377 |
for (auto path : m_paths) { |
| 378 |
DBImgInfo info = DBManager::instance()->getTrashInfoByPath(path); |
| 379 |
QFileInfo fi(info.filePath); |
| 380 |
if (fi.exists()) { |
| 381 |
info.importTime = QDateTime::currentDateTime(); |
| 382 |
infos << info; |
| 383 |
} |
| 384 |
} |
| 385 |
DBManager::instance()->insertImgInfos(infos); |
| 386 |
|
| 387 |
//恢复到相册是无意义的getTrashInfoByPath无法查询到album |
| 388 |
// for (auto path : paths) { |
| 389 |
// DBImgInfo info = DBManager::instance()->getTrashInfoByPath(path); |
| 390 |
// QStringList namelist = info.albumname.split(","); |
| 391 |
// for (auto eachname : namelist) { |
| 392 |
// if (DBManager::instance()->isAlbumExistInDB(eachname)) { |
| 393 |
// DBManager::instance()->insertIntoAlbum(eachname, QStringList(path)); |
| 394 |
// } |
| 395 |
// } |
| 396 |
// } |
| 397 |
|
| 398 |
DBManager::instance()->removeTrashImgInfos(m_paths); |
| 399 |
emit dApp->signalM->closeWaitDialog(); |
| 400 |
} |
| 401 |
|
| 402 |
ImageMoveImagesToTrashThread::ImageMoveImagesToTrashThread() |
| 403 |
{ |
| 404 |
setAutoDelete(false); |
| 405 |
} |
| 406 |
|
| 407 |
void ImageMoveImagesToTrashThread::setData(const QStringList &paths, bool typetrash) |
| 408 |
{ |
| 409 |
m_paths = paths; |
| 410 |
btypetrash = typetrash; |
| 411 |
} |
| 412 |
|
| 413 |
void ImageMoveImagesToTrashThread::runDetail() |
| 414 |
{ |
| 415 |
QStringList paths = m_paths; |
| 416 |
if (btypetrash) { |
| 417 |
DBManager::instance()->removeTrashImgInfos(paths); |
| 418 |
emit dApp->signalM->sigDeletePhotos(paths.length()); |
| 419 |
} else { |
| 420 |
DBImgInfoList infos; |
| 421 |
int pathsCount = paths.size(); |
| 422 |
int remmoveOffset = 30; //每30条上报前端一次 |
| 423 |
int removedCount = 0; |
| 424 |
QStringList removedPaths; |
| 425 |
emit dApp->signalM->progressOfWaitDialog(paths.size(), 0); |
| 426 |
for (auto path : paths) { |
| 427 |
DBImgInfo info; |
| 428 |
info = DBManager::instance()->getInfoByPath(path); |
| 429 |
info.importTime = QDateTime::currentDateTime(); |
| 430 |
QStringList allalbumnames = DBManager::instance()->getAllAlbumNames(); |
| 431 |
for (auto eachname : allalbumnames) { |
| 432 |
if (DBManager::instance()->isImgExistInAlbum(eachname, path)) { |
| 433 |
info.albumname += (eachname + ","); |
| 434 |
} |
| 435 |
} |
| 436 |
infos << info; |
| 437 |
removedPaths << path; |
| 438 |
removedCount++; |
| 439 |
if (removedCount % remmoveOffset == 0) { |
| 440 |
DBManager::instance()->insertTrashImgInfos(infos); |
| 441 |
DBManager::instance()->removeImgInfos(removedPaths); |
| 442 |
emit dApp->signalM->progressOfWaitDialog(pathsCount, removedCount); |
| 443 |
removedPaths.clear(); |
| 444 |
infos.clear(); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
if (infos.size() > 0) { |
| 449 |
DBManager::instance()->insertTrashImgInfos(infos); |
| 450 |
DBManager::instance()->removeImgInfos(removedPaths); |
| 451 |
emit dApp->signalM->progressOfWaitDialog(pathsCount, removedCount); |
| 452 |
} |
| 453 |
} |
| 454 |
emit dApp->signalM->closeWaitDialog(); |
| 455 |
} |
| 456 |
|
| 457 |
ImageImportFilesFromMountThread::ImageImportFilesFromMountThread() |
| 458 |
{ |
| 459 |
setAutoDelete(false); |
| 460 |
} |
| 461 |
|
| 462 |
ImageImportFilesFromMountThread::~ImageImportFilesFromMountThread() |
| 463 |
{ |
| 464 |
} |
| 465 |
|
| 466 |
void ImageImportFilesFromMountThread::setData(QString &albumname, QStringList &paths, ImageMountImportPathsObject *imgobject) |
| 467 |
{ |
| 468 |
m_paths = paths; |
| 469 |
m_imgobject = imgobject; |
| 470 |
m_albumname = albumname; |
| 471 |
} |
| 472 |
|
| 473 |
bool ImageImportFilesFromMountThread::ifCanStopThread(void *imgobject) |
| 474 |
{ |
| 475 |
static_cast<ImageMountImportPathsObject *>(imgobject)->removeThread(this); |
| 476 |
return (imgobject == m_imgobject); |
| 477 |
} |
| 478 |
|
| 479 |
void ImageImportFilesFromMountThread::runDetail() |
| 480 |
{ |
| 481 |
if (bneedstop) { |
| 482 |
return; |
| 483 |
} |
| 484 |
QStringList newPathList; |
| 485 |
DBImgInfoList dbInfos; |
| 486 |
QString strHomePath = QDir::homePath(); |
| 487 |
//获取系统现在的时间 |
| 488 |
QString strDate = QDateTime::currentDateTime().toString("yyyy-MM-dd"); |
| 489 |
QString basePath = QString("%1%2%3").arg(strHomePath, "/Pictures/照片/", strDate); //todo... 中文“照片”需要替换 |
| 490 |
QDir dir; |
| 491 |
if (!dir.exists(basePath)) { |
| 492 |
dir.mkpath(basePath); |
| 493 |
} |
| 494 |
|
| 495 |
foreach (QString strPath, m_paths) { |
| 496 |
if (bneedstop || ImageEngineApi::instance()->closeFg()) { |
| 497 |
return; |
| 498 |
} |
| 499 |
//取出文件名称 |
| 500 |
QStringList pathList = strPath.split("/", QString::SkipEmptyParts); |
| 501 |
QStringList nameList = pathList.last().split(".", QString::SkipEmptyParts); |
| 502 |
QString strNewPath = QString("%1%2%3%4%5%6").arg(basePath, "/", nameList.first(), |
| 503 |
QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch()), ".", nameList.last()); |
| 504 |
|
| 505 |
//判断新路径下是否存在目标文件,若不存在,继续循环 |
| 506 |
if (!dir.exists(strPath)) { |
| 507 |
continue; |
| 508 |
} |
| 509 |
//判断新路径下是否存在目标文件,若存在,先删除掉 |
| 510 |
if (dir.exists(strNewPath)) { |
| 511 |
dir.remove(strNewPath); |
| 512 |
} |
| 513 |
newPathList << strNewPath; |
| 514 |
QFileInfo fi(strNewPath); |
| 515 |
using namespace utils::image; |
| 516 |
using namespace utils::base; |
| 517 |
if (QFile::copy(strPath, strNewPath)) { |
| 518 |
qDebug() << "onCopyPhotoFromPhone()"; |
| 519 |
} |
| 520 |
dbInfos << getDBInfo(strNewPath, utils::base::isVideo(strNewPath)); |
| 521 |
|
| 522 |
emit dApp->signalM->progressOfWaitDialog(m_paths.size(), dbInfos.size()); |
| 523 |
} |
| 524 |
ImageDataService::instance()->readThumbnailByPaths(newPathList, true); |
| 525 |
if (!dbInfos.isEmpty()) { |
| 526 |
QStringList pathslist; |
| 527 |
int idblen = dbInfos.length(); |
| 528 |
for (int i = 0; i < idblen; i++) { |
| 529 |
if (bneedstop) { |
| 530 |
return; |
| 531 |
} |
| 532 |
pathslist << dbInfos[i].filePath; |
| 533 |
} |
| 534 |
|
| 535 |
if (m_albumname.length() > 0) { |
| 536 |
DBManager::instance()->insertIntoAlbumNoSignal(m_albumname, pathslist); |
| 537 |
} |
| 538 |
DBManager::instance()->insertImgInfos(dbInfos); |
| 539 |
|
| 540 |
if (bneedstop) { |
| 541 |
return; |
| 542 |
} |
| 543 |
if (idblen != m_paths.length()) { |
| 544 |
int successful = dbInfos.length(); |
| 545 |
int failed = m_paths.length() - idblen; |
| 546 |
emit dApp->signalM->ImportSomeFailed(successful, failed); |
| 547 |
} else { |
| 548 |
emit dApp->signalM->ImportSuccess(); |
| 549 |
} |
| 550 |
} else { |
| 551 |
emit dApp->signalM->ImportFailed(); |
| 552 |
} |
| 553 |
emit sigImageFilesImported(m_imgobject, newPathList); |
| 554 |
m_imgobject->removeThread(this); |
| 555 |
} |
| 556 |
|
| 557 |
//ImageGetFilesFromMountThread::ImageGetFilesFromMountThread() |
| 558 |
//{ |
| 559 |
// setAutoDelete(false); |
| 560 |
//} |
| 561 |
|
| 562 |
//ImageGetFilesFromMountThread::~ImageGetFilesFromMountThread() |
| 563 |
//{ |
| 564 |
//} |
| 565 |
|
| 566 |
//void ImageGetFilesFromMountThread::setData(QString &mountname, QString &path, ImageMountGetPathsObject *imgobject) |
| 567 |
//{ |
| 568 |
// m_mountname = mountname; |
| 569 |
// m_path = path; |
| 570 |
// m_imgobject = imgobject; |
| 571 |
//} |
| 572 |
|
| 573 |
//bool ImageGetFilesFromMountThread::ifCanStopThread(void *imgobject) |
| 574 |
//{ |
| 575 |
// static_cast<ImageMountGetPathsObject *>(imgobject)->removeThread(this); |
| 576 |
// if (imgobject == m_imgobject) { |
| 577 |
// return true; |
| 578 |
// } |
| 579 |
// return false; |
| 580 |
//} |
| 581 |
|
| 582 |
////搜索手机中存储相机照片文件的路径,采用两级文件目录深度,找"DCIM"文件目录 |
| 583 |
////经过调研,安卓手机在path/外部存储设备/DCIM下,iPhone在patn/DCIM下 |
| 584 |
//bool ImageGetFilesFromMountThread::findPicturePathByPhone(QString &path) |
| 585 |
//{ |
| 586 |
// QDir dir(path); |
| 587 |
// if (!dir.exists()) return false; |
| 588 |
// QFileInfoList fileInfoList = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); |
| 589 |
// QFileInfo tempFileInfo; |
| 590 |
// foreach (tempFileInfo, fileInfoList) { |
| 591 |
// if (tempFileInfo.fileName().compare(ALBUM_PATHNAME_BY_PHONE) == 0) { |
| 592 |
// path = tempFileInfo.absoluteFilePath(); |
| 593 |
// return true; |
| 594 |
// } else { |
| 595 |
// QDir subDir; |
| 596 |
// subDir.setPath(tempFileInfo.absoluteFilePath()); |
| 597 |
// QFileInfoList subFileInfoList = subDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); |
| 598 |
// QFileInfo subTempFileInfo; |
| 599 |
// foreach (subTempFileInfo, subFileInfoList) { |
| 600 |
// if (subTempFileInfo.fileName().compare(ALBUM_PATHNAME_BY_PHONE) == 0) { |
| 601 |
// path = subTempFileInfo.absoluteFilePath(); |
| 602 |
// return true; |
| 603 |
// } |
| 604 |
// } |
| 605 |
// return false; |
| 606 |
// } |
| 607 |
// } |
| 608 |
// return false; |
| 609 |
//} |
| 610 |
|
| 611 |
//void ImageGetFilesFromMountThread::runDetail() |
| 612 |
//{ |
| 613 |
// if (bneedstop) { |
| 614 |
// return; |
| 615 |
// } |
| 616 |
// //获取所选文件类型过滤器 |
| 617 |
// QStringList filters; |
| 618 |
// for (QString i : UnionImage_NameSpace::unionImageSupportFormat()) { |
| 619 |
// filters << "*." + i; |
| 620 |
// } |
| 621 |
// //定义迭代器并设置过滤器,包括子目录:QDirIterator::Subdirectories |
| 622 |
// QDirIterator dir_iterator(m_path, |
| 623 |
// filters, |
| 624 |
// QDir::Files | QDir::NoSymLinks, |
| 625 |
// QDirIterator::Subdirectories); |
| 626 |
// QStringList allfiles; |
| 627 |
// while (dir_iterator.hasNext()) { |
| 628 |
// if (bneedstop || ImageEngineApi::instance()->closeFg()) { |
| 629 |
// return; |
| 630 |
// } |
| 631 |
// dir_iterator.next(); |
| 632 |
// QFileInfo fileInfo = dir_iterator.fileInfo(); |
| 633 |
// allfiles << fileInfo.filePath(); |
| 634 |
// } |
| 635 |
// if (bneedstop) { |
| 636 |
// return; |
| 637 |
// } |
| 638 |
// emit sigImageFilesGeted(m_imgobject, allfiles, m_path); |
| 639 |
// m_imgobject->removeThread(this); |
| 640 |
// emit dApp->signalM->sigLoadMountImagesEnd(m_mountname); |
| 641 |
//} |
| 642 |
|
| 643 |
ImageLoadFromDBThread::ImageLoadFromDBThread() |
| 644 |
{ |
| 645 |
setAutoDelete(false); |
| 646 |
} |
| 647 |
|
| 648 |
ImageLoadFromDBThread::~ImageLoadFromDBThread() |
| 649 |
{ |
| 650 |
} |
| 651 |
|
| 652 |
bool ImageLoadFromDBThread::ifCanStopThread(void *imgobject) |
| 653 |
{ |
| 654 |
static_cast<ImageEngineObject *>(imgobject)->removeThread(this); |
| 655 |
if (imgobject == m_imgobject) { |
| 656 |
return true; |
| 657 |
} |
| 658 |
return false; |
| 659 |
} |
| 660 |
|
| 661 |
void ImageLoadFromDBThread::runDetail() |
| 662 |
{ |
| 663 |
if (bneedstop) { |
| 664 |
return; |
| 665 |
} |
| 666 |
QStringList image_list; |
| 667 |
QStringList fail_image_list; |
| 668 |
DBImgInfoList infos = DBManager::instance()->getAllInfos(0); |
| 669 |
ImageEngineApi::instance()->m_AllImageDataVector.clear(); |
| 670 |
ImageEngineApi::instance()->clearAllImageData(); |
| 671 |
for (int i = 0; i < infos.size(); i++) { |
| 672 |
DBImgInfo info = infos.at(i); |
| 673 |
//记录源文件不存在的数据 |
| 674 |
if (!QFileInfo(info.filePath).exists()) { |
| 675 |
fail_image_list << info.filePath; |
| 676 |
continue; |
| 677 |
} |
| 678 |
|
| 679 |
ImageEngineApi::instance()->m_AllImageDataVector.append(info); |
| 680 |
ImageEngineApi::instance()->addImageData(info.filePath, info); |
| 681 |
} |
| 682 |
qDebug() << __FUNCTION__ << "---m_AllImageDataVector.size = " << ImageEngineApi::instance()->m_AllImageDataVector.size(); |
| 683 |
if (bneedstop) { |
| 684 |
return; |
| 685 |
} |
| 686 |
|
| 687 |
//删除数据库失效的图片 |
| 688 |
DBManager::instance()->removeImgInfosNoSignal(fail_image_list); |
| 689 |
// 相册照片更新时的.更新路径相册名缓存,用于listview的setdata userrole + 2 |
| 690 |
ImageEngineApi::instance()->setImgPathAndAlbumNames(DBManager::instance()->getAllPathAlbumNames()); |
| 691 |
|
| 692 |
emit ImageEngineApi::instance()->sigReloadAfterFilterEnd(); |
| 693 |
} |
| 694 |
|
| 695 |
RefreshTrashThread::RefreshTrashThread() |
| 696 |
{ |
| 697 |
setAutoDelete(false); |
| 698 |
} |
| 699 |
|
| 700 |
RefreshTrashThread::~RefreshTrashThread() |
| 701 |
{ |
| 702 |
} |
| 703 |
|
| 704 |
void RefreshTrashThread::setData(DBImgInfoList filelist) |
| 705 |
{ |
| 706 |
m_fileinfolist = filelist; |
| 707 |
} |
| 708 |
|
| 709 |
void RefreshTrashThread::runDetail() |
| 710 |
{ |
| 711 |
if (bneedstop) { |
| 712 |
return; |
| 713 |
} |
| 714 |
QStringList image_list; |
| 715 |
|
| 716 |
if (!m_fileinfolist.isEmpty()) { |
| 717 |
QStringList removepaths; |
| 718 |
for (auto info : m_fileinfolist) { |
| 719 |
image_list << info.filePath; |
| 720 |
} |
| 721 |
if (0 < image_list.length()) { |
| 722 |
DBManager::instance()->removeTrashImgInfosNoSignal(image_list); |
| 723 |
} |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
//ImageEngineThread::ImageEngineThread() |
| 728 |
//{ |
| 729 |
// m_imgobject.clear(); |
| 730 |
// setAutoDelete(false); |
| 731 |
//} |
| 732 |
|
| 733 |
//ImageEngineThread::~ImageEngineThread() |
| 734 |
//{ |
| 735 |
//} |
| 736 |
|
| 737 |
//void ImageEngineThread::setData(QString &path, ImageEngineObject *imgobject, ImageDataSt &data, bool needcache) |
| 738 |
//{ |
| 739 |
// m_path = path; |
| 740 |
// m_imgobject << imgobject; |
| 741 |
// m_data = data; |
| 742 |
// bneedcache = needcache; |
| 743 |
//} |
| 744 |
|
| 745 |
//bool ImageEngineThread::ifCanStopThread(void *imgobject) |
| 746 |
//{ |
| 747 |
// if (nullptr != imgobject && ImageEngineApi::instance()->ifObjectExist(imgobject)) |
| 748 |
// static_cast<ImageEngineObject *>(imgobject)->removeThread(this); |
| 749 |
// m_imgobject.removeOne(static_cast<ImageEngineObject *>(imgobject)); |
| 750 |
// if (m_imgobject.size() < 1) { |
| 751 |
// bneedstop = true; |
| 752 |
// return true; |
| 753 |
// } |
| 754 |
// return false; |
| 755 |
//} |
| 756 |
|
| 757 |
//bool ImageEngineThread::getNeedStop() |
| 758 |
//{ |
| 759 |
// return bneedstop; |
| 760 |
//} |
| 761 |
|
| 762 |
//bool ImageEngineThread::addObject(ImageEngineObject *imgobject) |
| 763 |
//{ |
| 764 |
// if (baborted) { |
| 765 |
// baborted = false; |
| 766 |
// QMutexLocker mutex(&m_mutex); |
| 767 |
// m_imgobject << imgobject; |
| 768 |
// return false; |
| 769 |
// } |
| 770 |
// if (bneedstop) { |
| 771 |
// bneedstop = false; |
| 772 |
// } |
| 773 |
// if (!bwaitstop) { |
| 774 |
// QMutexLocker mutex(&m_mutex); |
| 775 |
// m_imgobject << imgobject; |
| 776 |
// } else { |
| 777 |
// imgobject->removeThread(this); |
| 778 |
// emit sigImageLoaded(imgobject, m_path, m_data); |
| 779 |
// } |
| 780 |
// return true; |
| 781 |
//} |
| 782 |
|
| 783 |
//载入QPixmap |
| 784 |
//void ImageEngineThread::runDetail() |
| 785 |
//{ |
| 786 |
// if (getNeedStop()) |
| 787 |
// return; |
| 788 |
// if (!QFileInfo(m_path).exists()) { |
| 789 |
// emit sigAborted(m_path); |
| 790 |
// return; |
| 791 |
// } |
| 792 |
|
| 793 |
// using namespace UnionImage_NameSpace; |
| 794 |
// QImage tImg; |
| 795 |
// QString path = m_path; |
| 796 |
// QFileInfo file(albumGlobal::CACHE_PATH + m_path); |
| 797 |
// QString errMsg; |
| 798 |
// QString dimension; |
| 799 |
// QFileInfo srcfi(m_path); |
| 800 |
// if (m_data.imgpixmap.isNull()) { |
| 801 |
// bool cache_exist = false; |
| 802 |
// if (file.exists()) { |
| 803 |
// QDateTime cachetime = file.metadataChangeTime(); //缓存修改时间 |
| 804 |
// QDateTime srctime = srcfi.metadataChangeTime(); //源数据修改时间 |
| 805 |
// if (srctime.toTime_t() > cachetime.toTime_t()) { //源文件近期修改过,重新生成缓存文件 |
| 806 |
// cache_exist = false; |
| 807 |
// breloadCache = true; |
| 808 |
// path = m_path; |
| 809 |
// if (!loadStaticImageFromFile(path, tImg, errMsg)) { |
| 810 |
// qDebug() << errMsg; |
| 811 |
// } |
| 812 |
// dimension = QString::number(tImg.width()) + "x" + QString::number(tImg.height()); |
| 813 |
// } else { |
| 814 |
// cache_exist = true; |
| 815 |
// path = albumGlobal::CACHE_PATH + m_path; |
| 816 |
// if (!loadStaticImageFromFile(path, tImg, errMsg, "PNG")) { |
| 817 |
// qDebug() << errMsg; |
| 818 |
// } |
| 819 |
// } |
| 820 |
// } else { |
| 821 |
// if (!loadStaticImageFromFile(path, tImg, errMsg)) { |
| 822 |
// qDebug() << errMsg; |
| 823 |
// } |
| 824 |
// dimension = QString::number(tImg.width()) + "x" + QString::number(tImg.height()); |
| 825 |
// } |
| 826 |
// if (getNeedStop()) |
| 827 |
// return; |
| 828 |
|
| 829 |
// if (0 != tImg.height() && 0 != tImg.width() && (tImg.height() / tImg.width()) < 10 && (tImg.width() / tImg.height()) < 10) { |
| 830 |
// if (tImg.height() != 140 && tImg.width() != 140) { |
| 831 |
// if (tImg.height() >= tImg.width()) { |
| 832 |
// cache_exist = true; |
| 833 |
// tImg = tImg.scaledToWidth(140, Qt::FastTransformation); |
| 834 |
// } else if (tImg.height() <= tImg.width()) { |
| 835 |
// cache_exist = true; |
| 836 |
// tImg = tImg.scaledToHeight(140, Qt::FastTransformation); |
| 837 |
// } |
| 838 |
// } |
| 839 |
// if (!cache_exist) { |
| 840 |
// if ((static_cast<float>(tImg.height()) / (static_cast<float>(tImg.width()))) > 3) { |
| 841 |
// tImg = tImg.scaledToWidth(140, Qt::FastTransformation); |
| 842 |
// } else { |
| 843 |
// tImg = tImg.scaledToHeight(140, Qt::FastTransformation); |
| 844 |
// } |
| 845 |
// } |
| 846 |
// } |
| 847 |
// if (breloadCache) { //更新缓存文件 |
| 848 |
// QString spath = albumGlobal::CACHE_PATH + m_path; |
| 849 |
// utils::base::mkMutiDir(spath.mid(0, spath.lastIndexOf('/'))); |
| 850 |
// tImg.save(spath, "PNG"); |
| 851 |
// } |
| 852 |
|
| 853 |
//// QPixmap pixmap = QPixmap::fromImage(tImg); |
| 854 |
//// m_data.imgpixmap = pixmap; |
| 855 |
// ImageDataService::instance()->addImage(m_path, tImg); |
| 856 |
// } |
| 857 |
// DBImgInfo dbi = getDBInfo(m_path); |
| 858 |
// if (!dimension.isEmpty()) { |
| 859 |
// dbi.albumSize = dimension; |
| 860 |
// } |
| 861 |
// m_data.dbi = dbi; |
| 862 |
//// m_data.loaded = ImageLoadStatu_Loaded; |
| 863 |
// if (getNeedStop()) { |
| 864 |
// return; |
| 865 |
// } |
| 866 |
// bwaitstop = true; |
| 867 |
// QMutexLocker mutex(&m_mutex); |
| 868 |
// for (ImageEngineObject *imgobject : m_imgobject) { |
| 869 |
// imgobject->removeThread(this); |
| 870 |
// emit sigImageLoaded(imgobject, m_path, m_data); |
| 871 |
// } |
| 872 |
// //这个代码不可注释,是线程池线程自我释放的检测,调小检测时间可以提高执行速度 |
| 873 |
//// while (!bneedstop && !ImageEngineApi::instance()->closeFg()) { |
| 874 |
//// QThread::msleep(100); |
| 875 |
//// } |
| 876 |
//} |
| 877 |
|
| 878 |
ImageFromNewAppThread::ImageFromNewAppThread() |
| 879 |
{ |
| 880 |
setAutoDelete(false); |
| 881 |
} |
| 882 |
|
| 883 |
ImageFromNewAppThread::~ImageFromNewAppThread() |
| 884 |
{ |
| 885 |
} |
| 886 |
|
| 887 |
void ImageFromNewAppThread::setDate(QStringList &files, ImageEngineImportObject *obj) |
| 888 |
{ |
| 889 |
paths = files; |
| 890 |
m_imgobj = obj; |
| 891 |
} |
| 892 |
|
| 893 |
bool ImageFromNewAppThread::ifCanStopThread(void *imgobject) |
| 894 |
{ |
| 895 |
static_cast<ImageEngineImportObject *>(imgobject)->removeThread(this); |
| 896 |
if (imgobject == m_imgobj) { |
| 897 |
return true; |
| 898 |
} |
| 899 |
return false; |
| 900 |
} |
| 901 |
|
| 902 |
void ImageFromNewAppThread::runDetail() |
| 903 |
{ |
| 904 |
if (bneedstop) { |
| 905 |
m_imgobj->imageImported(false); |
| 906 |
m_imgobj->removeThread(this); |
| 907 |
return; |
| 908 |
} |
| 909 |
DBImgInfoList dbInfos; |
| 910 |
using namespace utils::image; |
| 911 |
for (auto path : paths) { |
| 912 |
if (bneedstop) { |
| 913 |
m_imgobj->imageImported(false); |
| 914 |
m_imgobj->removeThread(this); |
| 915 |
return; |
| 916 |
} |
| 917 |
if (!imageSupportRead(path)) |
| 918 |
continue; |
| 919 |
dbInfos << getDBInfo(path); |
| 920 |
} |
| 921 |
if (! dbInfos.isEmpty()) { |
| 922 |
if (bneedstop) { |
| 923 |
m_imgobj->imageImported(false); |
| 924 |
m_imgobj->removeThread(this); |
| 925 |
return; |
| 926 |
} |
| 927 |
dApp->m_imageloader->ImportImageLoader(dbInfos); |
| 928 |
} |
| 929 |
m_imgobj->removeThread(this); |
| 930 |
} |
| 931 |
//缩略图制作线程 |
| 932 |
//makeThumbnailThread::makeThumbnailThread() |
| 933 |
//{ |
| 934 |
//} |
| 935 |
|
| 936 |
//makeThumbnailThread::~makeThumbnailThread() |
| 937 |
//{ |
| 938 |
// delete m_playlistModel; |
| 939 |
// m_playlistModel = nullptr; |
| 940 |
//} |
| 941 |
|
| 942 |
//void makeThumbnailThread::saveCache(QString m_path) |
| 943 |
//{ |
| 944 |
// if (needStop || m_path.isEmpty()) { |
| 945 |
// qDebug() << "m_path empty"; |
| 946 |
// return; |
| 947 |
// } |
| 948 |
// QImage tImg; |
| 949 |
// QString path = m_path; |
| 950 |
|
| 951 |
// QString spath = utils::base::filePathToThumbnailPath(m_path); |
| 952 |
|
| 953 |
// QFileInfo file(spath); |
| 954 |
// if (needStop) |
| 955 |
// return; |
| 956 |
// if (file.exists()) { |
| 957 |
// return; |
| 958 |
// } |
| 959 |
// if (needStop) |
| 960 |
// return; |
| 961 |
|
| 962 |
// QString errMsg; |
| 963 |
// if (utils::base::isVideo(m_path)) { |
| 964 |
// tImg = m_playlistModel->getMovieCover(QUrl::fromLocalFile(m_path)); |
| 965 |
// bool is = false; |
| 966 |
// //获取视频信息 demo |
| 967 |
// dmr::MovieInfo mi = m_playlistModel->getMovieInfo(QUrl::fromLocalFile(path), &is); |
| 968 |
// ImageDataService::instance()->addMovieDurationStr(m_path, mi.durationStr()); |
| 969 |
// } else { |
| 970 |
// if (!UnionImage_NameSpace::loadStaticImageFromFile(path, tImg, errMsg)) { |
| 971 |
// qDebug() << errMsg; |
| 972 |
// return; |
| 973 |
// } |
| 974 |
// } |
| 975 |
// if (needStop) |
| 976 |
// return; |
| 977 |
|
| 978 |
// if (0 != tImg.height() && 0 != tImg.width() && (tImg.height() / tImg.width()) < 10 && (tImg.width() / tImg.height()) < 10) { |
| 979 |
// bool cache_exist = false; |
| 980 |
// if (tImg.height() != 200 && tImg.width() != 200) { |
| 981 |
// if (tImg.height() >= tImg.width()) { |
| 982 |
// cache_exist = true; |
| 983 |
// tImg = tImg.scaledToWidth(200, Qt::FastTransformation); |
| 984 |
// } else if (tImg.height() <= tImg.width()) { |
| 985 |
// cache_exist = true; |
| 986 |
// tImg = tImg.scaledToHeight(200, Qt::FastTransformation); |
| 987 |
// } |
| 988 |
// } |
| 989 |
// if (!cache_exist) { |
| 990 |
// if (static_cast<float>(tImg.height()) / static_cast<float>(tImg.width()) > 3) { |
| 991 |
// tImg = tImg.scaledToWidth(200, Qt::FastTransformation); |
| 992 |
// } else { |
| 993 |
// tImg = tImg.scaledToHeight(200, Qt::FastTransformation); |
| 994 |
// } |
| 995 |
// } |
| 996 |
// } |
| 997 |
|
| 998 |
// if (needStop) |
| 999 |
// return; |
| 1000 |
// utils::base::mkMutiDir(spath.mid(0, spath.lastIndexOf('/'))); |
| 1001 |
|
| 1002 |
// QPixmap pixmap = QPixmap::fromImage(tImg); |
| 1003 |
// pixmap.save(spath, "PNG"); |
| 1004 |
//} |
| 1005 |
|
| 1006 |
//void makeThumbnailThread::run() |
| 1007 |
//{ |
| 1008 |
// if (m_playlistModel == nullptr) { |
| 1009 |
// qDebug() << __FUNCTION__ << "---new dmr::PlaylistModel"; |
| 1010 |
// m_playlistModel = new dmr::PlaylistModel(nullptr); |
| 1011 |
// } |
| 1012 |
|
| 1013 |
// while (!m_obj->isEmpty() && !needStop && !ImageEngineApi::instance()->closeFg()) { |
| 1014 |
// QString res = m_obj->pop(); |
| 1015 |
// if (!res.isEmpty()) { |
| 1016 |
// saveCache(res); |
| 1017 |
// } |
| 1018 |
// } |
| 1019 |
//} |
| 1020 |
|
| 1021 |
ImageEngineBackThread::ImageEngineBackThread(): m_bpause(false) |
| 1022 |
{ |
| 1023 |
setAutoDelete(false); |
| 1024 |
connect(dApp->signalM, &SignalManager::sigDevStop, this, [ = ](QString devName) { |
| 1025 |
if (devName == m_devName || devName.isEmpty()) { |
| 1026 |
bbackstop = true; |
| 1027 |
} |
| 1028 |
}); |
| 1029 |
|
| 1030 |
connect(dApp->signalM, &SignalManager::sigPauseOrStart, this, &ImageEngineBackThread::onStartOrPause); |
| 1031 |
} |
| 1032 |
|
| 1033 |
void ImageEngineBackThread::setData(const QStringList &pathlist, const QString &devName) |
| 1034 |
{ |
| 1035 |
m_pathlist = pathlist; |
| 1036 |
m_devName = devName; |
| 1037 |
} |
| 1038 |
|
| 1039 |
void ImageEngineBackThread::runDetail() |
| 1040 |
{ |
| 1041 |
using namespace UnionImage_NameSpace; |
| 1042 |
for (auto temppath : m_pathlist) { |
| 1043 |
QImage tImg; |
| 1044 |
QString path = temppath; |
| 1045 |
QString errMsg; |
| 1046 |
if (!loadStaticImageFromFile(path, tImg, errMsg)) { |
| 1047 |
qDebug() << errMsg; |
| 1048 |
break; |
| 1049 |
} |
| 1050 |
if (bbackstop || ImageEngineApi::instance()->closeFg()) |
| 1051 |
return; |
| 1052 |
|
| 1053 |
if (0 != tImg.height() && 0 != tImg.width() && (tImg.height() / tImg.width()) < 10 && (tImg.width() / tImg.height()) < 10) { |
| 1054 |
bool cache_exist = false; |
| 1055 |
if (tImg.height() != 100 && tImg.width() != 100) { |
| 1056 |
if (tImg.height() >= tImg.width()) { |
| 1057 |
cache_exist = true; |
| 1058 |
tImg = tImg.scaledToWidth(100, Qt::FastTransformation); |
| 1059 |
} else if (tImg.height() <= tImg.width()) { |
| 1060 |
cache_exist = true; |
| 1061 |
tImg = tImg.scaledToHeight(100, Qt::FastTransformation); |
| 1062 |
} |
| 1063 |
} |
| 1064 |
if (!cache_exist) { |
| 1065 |
if ((static_cast<float>(tImg.height()) / (static_cast<float>(tImg.width()))) > 3) { |
| 1066 |
tImg = tImg.scaledToWidth(100, Qt::FastTransformation); |
| 1067 |
} else { |
| 1068 |
tImg = tImg.scaledToHeight(100, Qt::FastTransformation); |
| 1069 |
} |
| 1070 |
} |
| 1071 |
} |
| 1072 |
|
| 1073 |
ImageDataService::instance()->addImage(path, tImg); |
| 1074 |
if (bbackstop || ImageEngineApi::instance()->closeFg()) |
| 1075 |
return; |
| 1076 |
m_data = getDBInfo(temppath); |
| 1077 |
|
| 1078 |
if (bbackstop || ImageEngineApi::instance()->closeFg()) { |
| 1079 |
return; |
| 1080 |
} |
| 1081 |
|
| 1082 |
if (m_bpause) { |
| 1083 |
m_WatiCondition.wait(&m_mutex); //挂起 |
| 1084 |
} |
| 1085 |
emit sigImageBackLoaded(temppath, m_data); |
| 1086 |
} |
| 1087 |
} |
| 1088 |
|
| 1089 |
void ImageEngineBackThread::onStartOrPause(bool pause) |
| 1090 |
{ |
| 1091 |
if (pause) |
| 1092 |
m_bpause = true; |
| 1093 |
else { |
| 1094 |
m_WatiCondition.wakeOne(); //恢复线程 |
| 1095 |
m_bpause = false; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
GetAllPathAlbumNamesThread::GetAllPathAlbumNamesThread() |
| 1100 |
{ |
| 1101 |
|
| 1102 |
} |
| 1103 |
|
| 1104 |
GetAllPathAlbumNamesThread::~GetAllPathAlbumNamesThread() |
| 1105 |
{ |
| 1106 |
|
| 1107 |
} |
| 1108 |
|
| 1109 |
void GetAllPathAlbumNamesThread::runDetail() |
| 1110 |
{ |
| 1111 |
ImageEngineApi::instance()->setImgPathAndAlbumNames(DBManager::instance()->getAllPathAlbumNames()); |
| 1112 |
} |