File indexing completed on 2025-01-19 03:52:56

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2019-03-27
0007  * Description : file copy thread.
0008  *
0009  * SPDX-FileCopyrightText: 2012      by Smit Mehta <smit dot meh at gmail dot com>
0010  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2019-2020 by Maik Qualmann <metzpinguin at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #include "fcthread.h"
0018 
0019 // Local includes
0020 
0021 #include "fctask.h"
0022 
0023 namespace DigikamGenericFileCopyPlugin
0024 {
0025 
0026 FCThread::FCThread(QObject* const parent)
0027     : ActionThreadBase(parent)
0028 {
0029 }
0030 
0031 FCThread::~FCThread()
0032 {
0033     // cancel the thread
0034     cancel();
0035     // wait for the thread to finish
0036     wait();
0037 }
0038 
0039 void FCThread::createCopyJobs(const QList<QUrl>& itemsList,
0040                               const FCContainer& settings)
0041 {
0042     ActionJobCollection collection;
0043 
0044     Q_FOREACH (const QUrl& srcUrl, itemsList)
0045     {
0046         FCTask* const t = new FCTask(srcUrl, settings);
0047 
0048         connect(t, SIGNAL(signalUrlProcessed(QUrl,QUrl)),
0049                 this, SIGNAL(signalUrlProcessed(QUrl,QUrl)));
0050 
0051         connect(this, SIGNAL(signalCancelTask()),
0052                 t, SLOT(cancel()), Qt::QueuedConnection);
0053 
0054         collection.insert(t, 0);
0055      }
0056 
0057     appendJobs(collection);
0058 }
0059 
0060 void FCThread::cancel()
0061 {
0062     if (isRunning())
0063     {
0064         Q_EMIT signalCancelTask();
0065     }
0066 
0067     ActionThreadBase::cancel();
0068 }
0069 
0070 } // namespace DigikamGenericFileCopyPlugin
0071 
0072 #include "moc_fcthread.cpp"