Enable customizing the save statistics time interval
[qBittorrent.git] / src / base / bittorrent / categoryoptions.cpp
blobfec609ff7e5e3ae3289d4bde8bd2624231ed22c8
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2021-2023 Vladimir Golovnev <glassez@yandex.ru>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
29 #include "categoryoptions.h"
31 #include <QJsonObject>
32 #include <QJsonValue>
34 #include "base/global.h"
36 const QString OPTION_SAVEPATH = u"save_path"_s;
37 const QString OPTION_DOWNLOADPATH = u"download_path"_s;
39 BitTorrent::CategoryOptions BitTorrent::CategoryOptions::fromJSON(const QJsonObject &jsonObj)
41 CategoryOptions options;
42 options.savePath = Path(jsonObj.value(OPTION_SAVEPATH).toString());
44 const QJsonValue downloadPathValue = jsonObj.value(OPTION_DOWNLOADPATH);
45 if (downloadPathValue.isBool())
46 options.downloadPath = {downloadPathValue.toBool(), {}};
47 else if (downloadPathValue.isString())
48 options.downloadPath = {true, Path(downloadPathValue.toString())};
50 return options;
53 QJsonObject BitTorrent::CategoryOptions::toJSON() const
55 QJsonValue downloadPathValue = QJsonValue::Undefined;
56 if (downloadPath)
58 if (downloadPath->enabled)
59 downloadPathValue = downloadPath->path.data();
60 else
61 downloadPathValue = false;
64 return {
65 {OPTION_SAVEPATH, savePath.data()},
66 {OPTION_DOWNLOADPATH, downloadPathValue}
70 bool BitTorrent::operator==(const BitTorrent::CategoryOptions &left, const BitTorrent::CategoryOptions &right)
72 return ((left.savePath == right.savePath)
73 && (left.downloadPath == right.downloadPath));