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.
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"
49 struct DownloadResult
;
54 class AddNewTorrentDialog
;
58 class TorrentFileGuard
;
60 class AddNewTorrentDialog final
: public QDialog
63 Q_DISABLE_COPY_MOVE(AddNewTorrentDialog
)
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
);
78 static void show(const QString
&source
, const BitTorrent::AddTorrentParams
&inParams
, QWidget
*parent
);
79 static void show(const QString
&source
, QWidget
*parent
);
82 void updateDiskSpaceLabel();
83 void onSavePathChanged(const Path
&newPath
);
84 void onDownloadPathChanged(const Path
&newPath
);
85 void onUseDownloadPathChanged(bool checked
);
86 void updateMetadata(const BitTorrent::TorrentInfo
&metadata
);
87 void handleDownloadFinished(const Net::DownloadResult
&downloadResult
);
88 void TMMChanged(int index
);
89 void categoryChanged(int index
);
90 void contentLayoutChanged();
91 void doNotDeleteTorrentClicked(bool checked
);
93 void accept() override
;
94 void reject() override
;
97 class TorrentContentAdaptor
;
99 explicit AddNewTorrentDialog(const BitTorrent::AddTorrentParams
&inParams
, QWidget
*parent
);
101 bool loadTorrentFile(const QString
&source
);
102 bool loadTorrentImpl();
103 bool loadMagnet(const BitTorrent::MagnetUri
&magnetUri
);
104 void populateSavePaths();
107 void setMetadataProgressIndicator(bool visibleIndicator
, const QString
&labelText
= {});
108 void setupTreeview();
109 void saveTorrentFile();
110 bool hasMetadata() const;
112 void showEvent(QShowEvent
*event
) override
;
114 Ui::AddNewTorrentDialog
*m_ui
= nullptr;
115 TorrentContentAdaptor
*m_contentAdaptor
= nullptr;
116 BitTorrent::MagnetUri m_magnetURI
;
117 BitTorrent::TorrentInfo m_torrentInfo
;
118 int m_savePathIndex
= -1;
119 int m_downloadPathIndex
= -1;
120 bool m_useDownloadPath
= false;
121 LineEdit
*m_filterLine
= nullptr;
122 std::unique_ptr
<TorrentFileGuard
> m_torrentGuard
;
123 BitTorrent::AddTorrentParams m_torrentParams
;
125 SettingValue
<QSize
> m_storeDialogSize
;
126 SettingValue
<QString
> m_storeDefaultCategory
;
127 SettingValue
<bool> m_storeRememberLastSavePath
;
128 SettingValue
<QByteArray
> m_storeTreeHeaderState
;
129 SettingValue
<QByteArray
> m_storeSplitterState
;