WebUI: disallow unnecessary quotes in property name
[qBittorrent.git] / src / base / bittorrent / torrentcreationtask.cpp
blobb1cb25f0c3b285cfa6bf5296f724cee56249d69a
1 /*
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)
39 , m_id {id}
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();
48 });
50 connect(torrentCreator, &BitTorrent::TorrentCreator::progressUpdated, this
51 , [this](const int progress)
53 m_progress = progress;
54 });
56 connect(torrentCreator, &BitTorrent::TorrentCreator::creationSuccess, this
57 , [this, app, startSeeding](const TorrentCreatorResult &result)
59 m_timeFinished = QDateTime::currentDateTime();
60 m_result = result;
62 if (!startSeeding)
63 return;
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.");
72 });
74 connect(torrentCreator, &BitTorrent::TorrentCreator::creationFailure, this
75 , [this](const QString &errorMsg)
77 m_timeFinished = QDateTime::currentDateTime();
78 m_errorMsg = errorMsg;
79 });
82 QString BitTorrent::TorrentCreationTask::id() const
84 return m_id;
87 const BitTorrent::TorrentCreatorParams &BitTorrent::TorrentCreationTask::params() const
89 return m_params;
92 BitTorrent::TorrentCreationTask::State BitTorrent::TorrentCreationTask::state() const
94 if (m_timeStarted.isNull())
95 return Queued;
96 if (m_timeFinished.isNull())
97 return Running;
98 return Finished;
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
123 return m_progress;
126 const BitTorrent::TorrentCreatorResult &BitTorrent::TorrentCreationTask::result() const
128 return m_result;
131 QString BitTorrent::TorrentCreationTask::errorMsg() const
133 return m_errorMsg;
136 QDateTime BitTorrent::TorrentCreationTask::timeAdded() const
138 return m_timeAdded;
141 QDateTime BitTorrent::TorrentCreationTask::timeStarted() const
143 return m_timeStarted;
146 QDateTime BitTorrent::TorrentCreationTask::timeFinished() const
148 return m_timeFinished;