File indexing completed on 2025-01-05 04:37:17
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "torrentfileinterface.h" 0007 #include <QTextCodec> 0008 #include <util/fileops.h> 0009 #include <util/functions.h> 0010 0011 namespace bt 0012 { 0013 TorrentFileInterface::TorrentFileInterface(Uint32 index, const QString &path, Uint64 size) 0014 : index(index) 0015 , first_chunk(0) 0016 , last_chunk(0) 0017 , num_chunks_downloaded(0) 0018 , size(size) 0019 , first_chunk_off(0) 0020 , last_chunk_size(0) 0021 0022 , preexisting(false) 0023 , emit_status_changed(true) 0024 , preview(false) 0025 , filetype(UNKNOWN) 0026 , priority(NORMAL_PRIORITY) 0027 0028 , path(path) 0029 { 0030 } 0031 0032 TorrentFileInterface::~TorrentFileInterface() 0033 { 0034 } 0035 0036 float TorrentFileInterface::getDownloadPercentage() const 0037 { 0038 Uint32 num = last_chunk - first_chunk + 1; 0039 return 100.0f * (float)num_chunks_downloaded / num; 0040 } 0041 0042 void TorrentFileInterface::setUnencodedPath(const QList<QByteArray> up) 0043 { 0044 unencoded_path = up; 0045 } 0046 0047 void TorrentFileInterface::changeTextCodec(QTextCodec *codec) 0048 { 0049 path.clear(); 0050 int idx = 0; 0051 for (const QByteArray &b : std::as_const(unencoded_path)) { 0052 path += codec->toUnicode(b); 0053 if (idx < unencoded_path.size() - 1) 0054 path += bt::DirSeparator(); 0055 idx++; 0056 } 0057 } 0058 0059 QString TorrentFileInterface::getMountPoint() const 0060 { 0061 if (!bt::Exists(path_on_disk)) 0062 return QString(); 0063 0064 if (mount_point.isEmpty()) 0065 mount_point = bt::MountPoint(path_on_disk); 0066 0067 return mount_point; 0068 } 0069 0070 } 0071 0072 #include "moc_torrentfileinterface.cpp"