Bump to 4.6.7
[qBittorrent.git] / src / gui / addnewtorrentdialog.h
blob557df9b9ef7a9282dba31d16325d5afb45c80c1a
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2012 Christophe Dumez <chris@qbittorrent.org>
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 #pragma once
32 #include <memory>
34 #include <QDialog>
36 #include "base/bittorrent/addtorrentparams.h"
37 #include "base/bittorrent/magneturi.h"
38 #include "base/bittorrent/torrentinfo.h"
39 #include "base/path.h"
40 #include "base/settingvalue.h"
42 class LineEdit;
43 class TorrentFileGuard;
45 namespace BitTorrent
47 class InfoHash;
50 namespace Net
52 struct DownloadResult;
55 namespace Ui
57 class AddNewTorrentDialog;
60 class AddNewTorrentDialog final : public QDialog
62 Q_OBJECT
63 Q_DISABLE_COPY_MOVE(AddNewTorrentDialog)
65 public:
66 static const int minPathHistoryLength = 0;
67 static const int maxPathHistoryLength = 99;
69 ~AddNewTorrentDialog() override;
71 static bool isEnabled();
72 static void setEnabled(bool value);
73 static bool isTopLevel();
74 static void setTopLevel(bool value);
75 static int savePathHistoryLength();
76 static void setSavePathHistoryLength(int value);
77 #ifndef Q_OS_MACOS
78 static bool isAttached();
79 static void setAttached(bool value);
80 #endif
82 static void show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
83 static void show(const QString &source, QWidget *parent);
85 private slots:
86 void updateDiskSpaceLabel();
87 void onSavePathChanged(const Path &newPath);
88 void onDownloadPathChanged(const Path &newPath);
89 void onUseDownloadPathChanged(bool checked);
90 void updateMetadata(const BitTorrent::TorrentInfo &metadata);
91 void handleDownloadFinished(const Net::DownloadResult &downloadResult);
92 void TMMChanged(int index);
93 void categoryChanged(int index);
94 void contentLayoutChanged();
95 void doNotDeleteTorrentClicked(bool checked);
97 void accept() override;
98 void reject() override;
100 private:
101 class TorrentContentAdaptor;
103 explicit AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
105 bool loadTorrentFile(const QString &source);
106 bool loadTorrentImpl();
107 bool loadMagnet(const BitTorrent::MagnetUri &magnetUri);
108 void populateSavePaths();
109 void loadState();
110 void saveState();
111 void setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText = {});
112 void setupTreeview();
113 void saveTorrentFile();
114 bool hasMetadata() const;
116 void showEvent(QShowEvent *event) override;
118 Ui::AddNewTorrentDialog *m_ui = nullptr;
119 std::unique_ptr<TorrentContentAdaptor> m_contentAdaptor;
120 BitTorrent::MagnetUri m_magnetURI;
121 BitTorrent::TorrentInfo m_torrentInfo;
122 int m_savePathIndex = -1;
123 int m_downloadPathIndex = -1;
124 bool m_useDownloadPath = false;
125 LineEdit *m_filterLine = nullptr;
126 std::unique_ptr<TorrentFileGuard> m_torrentGuard;
127 BitTorrent::AddTorrentParams m_torrentParams;
129 SettingValue<QSize> m_storeDialogSize;
130 SettingValue<QString> m_storeDefaultCategory;
131 SettingValue<bool> m_storeRememberLastSavePath;
132 SettingValue<QByteArray> m_storeTreeHeaderState;
133 SettingValue<QByteArray> m_storeSplitterState;