File indexing completed on 2025-01-05 03:53:10

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-12-05
0007  * Description : a tool to create panorama by fusion of several images.
0008  *
0009  * SPDX-FileCopyrightText: 2012-2016 by Benjamin Girault <benjamin dot girault at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "createfinalptotask.h"
0016 
0017 // Qt includes
0018 
0019 #include <QFile>
0020 
0021 // KDE includes
0022 
0023 #include <klocalizedstring.h>
0024 
0025 namespace DigikamGenericPanoramaPlugin
0026 {
0027 
0028 CreateFinalPtoTask::CreateFinalPtoTask(const QString& workDirPath,
0029                                        QSharedPointer<const PTOType> ptoData,
0030                                        QUrl& finalPtoUrl,
0031                                        const QRect& crop)
0032     : PanoTask(PANO_CREATEFINALPTO, workDirPath),
0033       ptoData(*ptoData),
0034       finalPtoUrl(finalPtoUrl),
0035       crop(crop)
0036 {
0037 }
0038 
0039 CreateFinalPtoTask::~CreateFinalPtoTask()
0040 {
0041 }
0042 
0043 void CreateFinalPtoTask::run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*)
0044 {
0045     finalPtoUrl = tmpDir;
0046     finalPtoUrl.setPath(finalPtoUrl.path() + QLatin1String("final.pto"));
0047 
0048     QFile pto(finalPtoUrl.toLocalFile());
0049 
0050     if (pto.exists())
0051     {
0052         errString   = i18n("PTO file already created in the temporary directory.");
0053         successFlag = false;
0054         return;
0055     }
0056 
0057     if (!pto.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
0058     {
0059         errString   = i18n("PTO file cannot be created in the temporary directory.");
0060         successFlag = false;
0061         return;
0062     }
0063 
0064     pto.close();
0065 
0066     ptoData.project.crop = crop;
0067     ptoData.createFile(finalPtoUrl.toLocalFile());
0068     successFlag          = true;
0069 
0070     return;
0071 }
0072 
0073 } // namespace DigikamGenericPanoramaPlugin