Skip to content

Commit 25bef03

Browse files
committed
showFreeDiskSpaceInAddTorrentDialogue
1 parent b2d9da6 commit 25bef03

File tree

4 files changed

+27
-85
lines changed

4 files changed

+27
-85
lines changed

src/webui/www/private/addtorrent.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<script defer src="scripts/addtorrent.js?locale=${LANG}&v=${CACHEID}"></script>
1717
<script defer src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
1818
<script defer src="scripts/pathAutofill.js?v=${CACHEID}"></script>
19-
<script defer src="scripts/freespaceAutofill.js?v=${CACHEID}"></script>
2019
<script defer src="scripts/file-tree.js?v=${CACHEID}"></script>
2120
<script defer src="scripts/filesystem.js?v=${CACHEID}"></script>
2221
<script defer src="scripts/contextmenu.js?locale=${LANG}&v=${CACHEID}"></script>
@@ -85,7 +84,6 @@
8584
window.qBittorrent.AddTorrent.metadataCompleted(false);
8685
});
8786

88-
window.qBittorrent.freespaceAutofill.attachFreeSpaceAutofill();
8987
window.qBittorrent.pathAutofill.attachPathAutofill();
9088
window.qBittorrent.AddTorrent.init(source, downloader, fetchMetadata);
9189
});
@@ -182,7 +180,7 @@
182180
<label for="savepath">QBT_TR(Save files to location:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
183181
</td>
184182
<td class="fullWidth">
185-
<input type="text" id="savepath" name="savepath" class="pathDirectory pathFreeSpace" style="width: 100%;">
183+
<input type="text" id="savepath" name="savepath" class="pathDirectory" style="width: 100%;">
186184
</td>
187185
</tr>
188186
</tbody>

src/webui/www/private/scripts/addtorrent.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ window.qBittorrent.AddTorrent ??= (() => {
3838
};
3939

4040
let table = null;
41+
let size = "";
4142
let defaultSavePath = "";
4243
let defaultTempPath = "";
4344
let defaultTempPathEnabled = false;
@@ -146,7 +147,7 @@ window.qBittorrent.AddTorrent ??= (() => {
146147

147148
if (isAutoTMMEnabled()) {
148149
document.getElementById("savepath").value = defaultSavePath;
149-
document.getElementById("size").textContent = window.qBittorrent.freespaceAutofill.showFreeSpace({ value: defaultSavePath });
150+
document.getElementById("size").textContent = showFreeSpace(defaultSavePath);
150151

151152
const downloadPathEnabled = categoryDownloadPathEnabled(categoryName);
152153
document.getElementById("useDownloadPath").checked = downloadPathEnabled;
@@ -161,7 +162,7 @@ window.qBittorrent.AddTorrent ??= (() => {
161162
if (isAutoTMMEnabled()) {
162163
const tempCategoryPath = categorySavePath(categoryName);
163164
document.getElementById("savepath").value = tempCategoryPath;
164-
document.getElementById("size").textContent = window.qBittorrent.freespaceAutofill.showFreeSpace({ value: tempCategoryPath });
165+
document.getElementById("size").textContent = showFreeSpace(tempCategoryPath);
165166

166167
const downloadPathEnabled = categoryDownloadPathEnabled(categoryName);
167168
document.getElementById("useDownloadPath").checked = downloadPathEnabled;
@@ -195,7 +196,7 @@ window.qBittorrent.AddTorrent ??= (() => {
195196
useDownloadPath.checked = defaultTempPathEnabled;
196197
}
197198

198-
document.getElementById("size").textContent = window.qBittorrent.freespaceAutofill.showFreeSpace({ value: savepath.value });
199+
document.getElementById("size").textContent = showFreeSpace(savepath.value);
199200
savepath.disabled = autoTMMEnabled;
200201
useDownloadPath.disabled = autoTMMEnabled;
201202

@@ -219,6 +220,25 @@ window.qBittorrent.AddTorrent ??= (() => {
219220
}
220221
};
221222

223+
const showFreeSpace = (element) => {
224+
if (element === "")
225+
return;
226+
227+
fetch(`api/v2/app/getFreeSpaceAtPath?path=${element}`, {
228+
method: "GET",
229+
cache: "no-store"
230+
})
231+
.then(response => response.text())
232+
.then(freeSpace => { filloutFreeSpace(freeSpace); })
233+
.catch(error => {});
234+
};
235+
236+
const filloutFreeSpace = (freeSpace) => {
237+
document.getElementById("size").textContent = `${" QBT_TR(%1 (Free space on disk: %2))QBT_TR[CONTEXT=AddNewTorrentDialog]"
238+
.replace("%1", size)
239+
.replace("%2", window.qBittorrent.Misc.friendlyUnit(freeSpace, false))}`;
240+
};
241+
222242
let loadMetadataTimer = -1;
223243
const loadMetadata = (sourceUrl = undefined, downloaderName = undefined) => {
224244
if (sourceUrl !== undefined)
@@ -285,9 +305,8 @@ window.qBittorrent.AddTorrent ??= (() => {
285305
document.getElementById("infoHashV2").textContent = (metadata.infohash_v2 === undefined) ? notAvailable : (metadata.infohash_v2 || notApplicable);
286306

287307
if (metadata.info?.length !== undefined) {
288-
const size = document.getElementById("size");
289-
size.setAttribute("size", window.qBittorrent.Misc.friendlyUnit(metadata.info.length, false));
290-
size.textContent = window.qBittorrent.freespaceAutofill.showFreeSpace({ value: document.getElementById("savepath").value });
308+
size = window.qBittorrent.Misc.friendlyUnit(metadata.info.length, false);
309+
document.getElementById("size").textContent = showFreeSpace(document.getElementById("savepath").value);
291310
}
292311
if ((metadata.creation_date !== undefined) && (metadata.creation_date > 1))
293312
document.getElementById("createdDate").textContent = window.qBittorrent.Misc.formatDate(new Date(metadata.creation_date * 1000));
@@ -333,6 +352,7 @@ window.qBittorrent.AddTorrent ??= (() => {
333352

334353
const init = (source, downloader, fetchMetadata) => {
335354
table = window.qBittorrent.TorrentContent.init("addTorrentFilesTableDiv", window.qBittorrent.DynamicTable.AddTorrentFilesTable);
355+
document.getElementById("savepath").addEventListener("input", function(event) { showFreeSpace(this.value); });
336356
if (fetchMetadata)
337357
loadMetadata(source, downloader);
338358
};

src/webui/www/private/scripts/freespaceAutofill.js

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/webui/www/webui.qrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@
396396
<file>private/scripts/dynamicTable.js</file>
397397
<file>private/scripts/file-tree.js</file>
398398
<file>private/scripts/filesystem.js</file>
399-
<file>private/scripts/freespaceAutofill.js</file>
400399
<file>private/scripts/lib/clipboard-copy.js</file>
401400
<file>private/scripts/lib/mocha.min.js</file>
402401
<file>private/scripts/lib/MooTools-Core-1.6.0-compat-compressed.js</file>

0 commit comments

Comments
 (0)