Merge pull request #18104 from sledgehammer999/remove_dead_code
[qBittorrent.git] / src / gui / addnewtorrentdialog.h
blob3eeeb7624a9d7d6cd29e324f6bccf1f8f74e758d
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2012 Christophe Dumez <chris@qbittorrent.org>
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 #pragma once
31 #include <memory>
33 #include <QDialog>
35 #include "base/bittorrent/addtorrentparams.h"
36 #include "base/bittorrent/magneturi.h"
37 #include "base/bittorrent/torrentinfo.h"
38 #include "base/path.h"
39 #include "base/settingvalue.h"
41 namespace BitTorrent
43 class InfoHash;
46 namespace Net
48 struct DownloadResult;
51 namespace Ui
53 class AddNewTorrentDialog;
56 class LineEdit;
57 class PropListDelegate;
58 class TorrentContentFilterModel;
59 class TorrentFileGuard;
61 class AddNewTorrentDialog final : public QDialog
63 Q_OBJECT
64 Q_DISABLE_COPY_MOVE(AddNewTorrentDialog)
66 public:
67 static const int minPathHistoryLength = 0;
68 static const int maxPathHistoryLength = 99;
70 ~AddNewTorrentDialog() override;
72 static bool isEnabled();
73 static void setEnabled(bool value);
74 static bool isTopLevel();
75 static void setTopLevel(bool value);
76 static int savePathHistoryLength();
77 static void setSavePathHistoryLength(int value);
79 static void show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
80 static void show(const QString &source, QWidget *parent);
82 private slots:
83 void displayContentTreeMenu();
84 void displayColumnHeaderMenu();
85 void updateDiskSpaceLabel();
86 void onSavePathChanged(const Path &newPath);
87 void onDownloadPathChanged(const Path &newPath);
88 void onUseDownloadPathChanged(bool checked);
89 void updateMetadata(const BitTorrent::TorrentInfo &metadata);
90 void handleDownloadFinished(const Net::DownloadResult &downloadResult);
91 void TMMChanged(int index);
92 void categoryChanged(int index);
93 void contentLayoutChanged();
94 void doNotDeleteTorrentClicked(bool checked);
95 void renameSelectedFile();
96 void handleFilterTextChanged(const QString &filter);
98 void accept() override;
99 void reject() override;
101 private:
102 explicit AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
104 void applyContentLayout();
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 TorrentContentFilterModel *m_contentModel = nullptr;
120 PropListDelegate *m_contentDelegate = nullptr;
121 BitTorrent::MagnetUri m_magnetURI;
122 BitTorrent::TorrentInfo m_torrentInfo;
123 Path m_originalRootFolder;
124 BitTorrent::TorrentContentLayout m_currentContentLayout;
125 int m_savePathIndex = -1;
126 int m_downloadPathIndex = -1;
127 bool m_useDownloadPath = false;
128 LineEdit *m_filterLine = nullptr;
129 std::unique_ptr<TorrentFileGuard> m_torrentGuard;
130 BitTorrent::AddTorrentParams m_torrentParams;
132 SettingValue<QSize> m_storeDialogSize;
133 SettingValue<QString> m_storeDefaultCategory;
134 SettingValue<bool> m_storeRememberLastSavePath;
135 SettingValue<QByteArray> m_storeTreeHeaderState;
136 SettingValue<QByteArray> m_storeSplitterState;