1 /* SPDX-FileCopyrightText: 2012-2019 The KPhotoAlbum Development Team
2 
3    SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "ReadVideoLengthJob.h"
7 
8 #include <BackgroundTaskManager/JobInfo.h>
9 #include <DB/ImageDB.h>
10 #include <ImageManager/VideoLengthExtractor.h>
11 #include <MainWindow/DirtyIndicator.h>
12 
13 #include <KLocalizedString>
14 
ReadVideoLengthJob(const DB::FileName & fileName,BackgroundTaskManager::Priority priority)15 BackgroundJobs::ReadVideoLengthJob::ReadVideoLengthJob(const DB::FileName &fileName, BackgroundTaskManager::Priority priority)
16     : JobInterface(priority)
17     , m_fileName(fileName)
18 {
19 }
20 
execute()21 void BackgroundJobs::ReadVideoLengthJob::execute()
22 {
23     ImageManager::VideoLengthExtractor *extractor = new ImageManager::VideoLengthExtractor(this);
24     extractor->extract(m_fileName);
25     connect(extractor, &ImageManager::VideoLengthExtractor::lengthFound, this, &ReadVideoLengthJob::lengthFound);
26     connect(extractor, &ImageManager::VideoLengthExtractor::unableToDetermineLength, this, &ReadVideoLengthJob::unableToDetermineLength);
27 }
28 
title() const29 QString BackgroundJobs::ReadVideoLengthJob::title() const
30 {
31     return i18n("Read Video Length");
32 }
33 
details() const34 QString BackgroundJobs::ReadVideoLengthJob::details() const
35 {
36     return m_fileName.relative();
37 }
38 
lengthFound(int length)39 void BackgroundJobs::ReadVideoLengthJob::lengthFound(int length)
40 {
41     DB::ImageInfoPtr info = DB::ImageDB::instance()->info(m_fileName);
42     // Only mark dirty if it is required
43     if (info->videoLength() != length) {
44         info->setVideoLength(length);
45         MainWindow::DirtyIndicator::markDirty();
46     }
47     emit completed();
48 }
49 
unableToDetermineLength()50 void BackgroundJobs::ReadVideoLengthJob::unableToDetermineLength()
51 {
52     // PENDING(blackie) Should we mark these as trouble, so we don't try them over and over again?
53     emit completed();
54 }
55 // vi:expandtab:tabstop=4 shiftwidth=4:
56