File indexing completed on 2024-04-28 15:39:47

0001 // SPDX-FileCopyrightText: 2012-2022 The KPhotoAlbum Development Team
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #include "ReadVideoLengthJob.h"
0006 
0007 #include <BackgroundTaskManager/JobInfo.h>
0008 #include <DB/ImageDB.h>
0009 #include <ImageManager/VideoLengthExtractor.h>
0010 #include <MainWindow/DirtyIndicator.h>
0011 
0012 #include <KLocalizedString>
0013 
0014 BackgroundJobs::ReadVideoLengthJob::ReadVideoLengthJob(const DB::FileName &fileName, BackgroundTaskManager::Priority priority)
0015     : JobInterface(priority)
0016     , m_fileName(fileName)
0017 {
0018 }
0019 
0020 void BackgroundJobs::ReadVideoLengthJob::execute()
0021 {
0022     ImageManager::VideoLengthExtractor *extractor = new ImageManager::VideoLengthExtractor(this);
0023     extractor->extract(m_fileName);
0024     connect(extractor, &ImageManager::VideoLengthExtractor::lengthFound, this, &ReadVideoLengthJob::lengthFound);
0025     connect(extractor, &ImageManager::VideoLengthExtractor::unableToDetermineLength, this, &ReadVideoLengthJob::unableToDetermineLength);
0026 }
0027 
0028 QString BackgroundJobs::ReadVideoLengthJob::title() const
0029 {
0030     return i18n("Read Video Length");
0031 }
0032 
0033 QString BackgroundJobs::ReadVideoLengthJob::details() const
0034 {
0035     return m_fileName.relative();
0036 }
0037 
0038 void BackgroundJobs::ReadVideoLengthJob::lengthFound(int length)
0039 {
0040     DB::ImageInfoPtr info = DB::ImageDB::instance()->info(m_fileName);
0041     // Only mark dirty if it is required
0042     if (info->videoLength() != length) {
0043         info->setVideoLength(length);
0044         MainWindow::DirtyIndicator::markDirty();
0045     }
0046     Q_EMIT completed();
0047 }
0048 
0049 void BackgroundJobs::ReadVideoLengthJob::unableToDetermineLength()
0050 {
0051     // PENDING(blackie) Should we mark these as trouble, so we don't try them over and over again?
0052     Q_EMIT completed();
0053 }
0054 // vi:expandtab:tabstop=4 shiftwidth=4:
0055 
0056 #include "moc_ReadVideoLengthJob.cpp"