2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2024 Radu Carpa <radu.carpa@cern.ch>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
30 #include "torrentcreationtask.h"
32 #include "base/addtorrentmanager.h"
33 #include "base/interfaces/iapplication.h"
34 #include "base/bittorrent/addtorrentparams.h"
36 BitTorrent::TorrentCreationTask::TorrentCreationTask(IApplication
*app
, const QString
&id
37 , TorrentCreator
*torrentCreator
, bool startSeeding
, QObject
*parent
)
38 : ApplicationComponent(app
, parent
)
40 , m_params
{torrentCreator
->params()}
41 , m_timeAdded
{QDateTime::currentDateTime()}
43 Q_ASSERT(torrentCreator
);
45 connect(torrentCreator
, &BitTorrent::TorrentCreator::started
, this, [this]
47 m_timeStarted
= QDateTime::currentDateTime();
50 connect(torrentCreator
, &BitTorrent::TorrentCreator::progressUpdated
, this
51 , [this](const int progress
)
53 m_progress
= progress
;
56 connect(torrentCreator
, &BitTorrent::TorrentCreator::creationSuccess
, this
57 , [this, app
, startSeeding
](const TorrentCreatorResult
&result
)
59 m_timeFinished
= QDateTime::currentDateTime();
65 BitTorrent::AddTorrentParams params
;
66 params
.savePath
= result
.savePath
;
67 params
.skipChecking
= true;
68 params
.useAutoTMM
= false; // otherwise if it is on by default, it will overwrite `savePath` to the default save path
70 if (!app
->addTorrentManager()->addTorrent(result
.torrentFilePath
.data(), params
))
71 m_errorMsg
= tr("Failed to start seeding.");
74 connect(torrentCreator
, &BitTorrent::TorrentCreator::creationFailure
, this
75 , [this](const QString
&errorMsg
)
77 m_timeFinished
= QDateTime::currentDateTime();
78 m_errorMsg
= errorMsg
;
82 QString
BitTorrent::TorrentCreationTask::id() const
87 const BitTorrent::TorrentCreatorParams
&BitTorrent::TorrentCreationTask::params() const
92 BitTorrent::TorrentCreationTask::State
BitTorrent::TorrentCreationTask::state() const
94 if (m_timeStarted
.isNull())
96 if (m_timeFinished
.isNull())
101 bool BitTorrent::TorrentCreationTask::isQueued() const
103 return (state() == Queued
);
106 bool BitTorrent::TorrentCreationTask::isRunning() const
108 return (state() == Running
);
111 bool BitTorrent::TorrentCreationTask::isFinished() const
113 return (state() == Finished
);
116 bool BitTorrent::TorrentCreationTask::isFailed() const
118 return !m_errorMsg
.isEmpty();
121 int BitTorrent::TorrentCreationTask::progress() const
126 const BitTorrent::TorrentCreatorResult
&BitTorrent::TorrentCreationTask::result() const
131 QString
BitTorrent::TorrentCreationTask::errorMsg() const
136 QDateTime
BitTorrent::TorrentCreationTask::timeAdded() const
141 QDateTime
BitTorrent::TorrentCreationTask::timeStarted() const
143 return m_timeStarted
;
146 QDateTime
BitTorrent::TorrentCreationTask::timeFinished() const
148 return m_timeFinished
;