mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-10-22 10:46:04 +03:00
FEATURE: Download first/last pieces first now applies to all media files in the torrent (Thanks Ahmad)
This commit is contained in:
parent
38aca6af6f
commit
6d1ad28d8c
4 changed files with 299 additions and 299 deletions
|
@ -14,6 +14,8 @@
|
||||||
- FEATURE: Optimized and improved the peer country resolution code
|
- FEATURE: Optimized and improved the peer country resolution code
|
||||||
- FEATURE: Download first/last pieces first when sequential download is
|
- FEATURE: Download first/last pieces first when sequential download is
|
||||||
enabled (Thanks Ahmad)
|
enabled (Thanks Ahmad)
|
||||||
|
- FEATURE: Download first/last pieces first now applies to all media files
|
||||||
|
in the torrent (Thanks Ahmad)
|
||||||
- BUGFIX: Fix SOCKS5 proxy authentication in search engine(closes #680072)
|
- BUGFIX: Fix SOCKS5 proxy authentication in search engine(closes #680072)
|
||||||
- BUGFIX: Fix two advanced settings (ignore limits on LAN and protocol
|
- BUGFIX: Fix two advanced settings (ignore limits on LAN and protocol
|
||||||
overhead inclusion in rate limiter)
|
overhead inclusion in rate limiter)
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList):
|
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList):
|
||||||
QWidget(parent), transferList(transferList), main_window(main_window) {
|
QWidget(parent), transferList(transferList), main_window(main_window) {
|
||||||
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
state = VISIBLE;
|
state = VISIBLE;
|
||||||
|
@ -565,192 +565,190 @@ void PropertiesWidget::renameSelectedFile() {
|
||||||
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
||||||
if(h.filepath_at(i).compare(new_name, Qt::CaseSensitive) == 0) {
|
if(h.filepath_at(i).compare(new_name, Qt::CaseSensitive) == 0) {
|
||||||
#else
|
#else
|
||||||
if(h.filepath_at(i).compare(new_name, Qt::CaseInsensitive) == 0) {
|
if(h.filepath_at(i).compare(new_name, Qt::CaseInsensitive) == 0) {
|
||||||
#endif
|
#endif
|
||||||
// Display error message
|
// Display error message
|
||||||
QMessageBox::warning(this, tr("The file could not be renamed"),
|
QMessageBox::warning(this, tr("The file could not be renamed"),
|
||||||
tr("This name is already in use in this folder. Please use a different name."),
|
tr("This name is already in use in this folder. Please use a different name."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const bool force_recheck = QFile::exists(h.save_path()+QDir::separator()+new_name);
|
}
|
||||||
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
|
const bool force_recheck = QFile::exists(h.save_path()+QDir::separator()+new_name);
|
||||||
h.rename_file(file_index, new_name);
|
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
|
||||||
// Force recheck
|
h.rename_file(file_index, new_name);
|
||||||
if(force_recheck) h.force_recheck();
|
// Force recheck
|
||||||
// Rename if torrent files model too
|
if(force_recheck) h.force_recheck();
|
||||||
if(new_name_last.endsWith(".!qB"))
|
// Rename if torrent files model too
|
||||||
new_name_last.chop(4);
|
if(new_name_last.endsWith(".!qB"))
|
||||||
PropListModel->setData(index, new_name_last);
|
new_name_last.chop(4);
|
||||||
} else {
|
PropListModel->setData(index, new_name_last);
|
||||||
// Folder renaming
|
} else {
|
||||||
QStringList path_items;
|
// Folder renaming
|
||||||
path_items << index.data().toString();
|
QStringList path_items;
|
||||||
QModelIndex parent = PropListModel->parent(index);
|
path_items << index.data().toString();
|
||||||
while(parent.isValid()) {
|
QModelIndex parent = PropListModel->parent(index);
|
||||||
path_items.prepend(parent.data().toString());
|
while(parent.isValid()) {
|
||||||
parent = PropListModel->parent(parent);
|
path_items.prepend(parent.data().toString());
|
||||||
}
|
parent = PropListModel->parent(parent);
|
||||||
const QString old_path = path_items.join("/");
|
}
|
||||||
path_items.removeLast();
|
const QString old_path = path_items.join("/");
|
||||||
path_items << new_name_last;
|
path_items.removeLast();
|
||||||
QString new_path = path_items.join("/");
|
path_items << new_name_last;
|
||||||
if(!new_path.endsWith("/")) new_path += "/";
|
QString new_path = path_items.join("/");
|
||||||
// Check for overwriting
|
if(!new_path.endsWith("/")) new_path += "/";
|
||||||
const int num_files = h.num_files();
|
// Check for overwriting
|
||||||
for(int i=0; i<num_files; ++i) {
|
const int num_files = h.num_files();
|
||||||
const QString current_name = h.filepath_at(i);
|
for(int i=0; i<num_files; ++i) {
|
||||||
|
const QString current_name = h.filepath_at(i);
|
||||||
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
||||||
if(current_name.startsWith(new_path, Qt::CaseSensitive)) {
|
if(current_name.startsWith(new_path, Qt::CaseSensitive)) {
|
||||||
#else
|
#else
|
||||||
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) {
|
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) {
|
||||||
#endif
|
#endif
|
||||||
QMessageBox::warning(this, tr("The folder could not be renamed"),
|
QMessageBox::warning(this, tr("The folder could not be renamed"),
|
||||||
tr("This name is already in use in this folder. Please use a different name."),
|
tr("This name is already in use in this folder. Please use a different name."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
bool force_recheck = false;
|
|
||||||
// Replace path in all files
|
|
||||||
for(int i=0; i<num_files; ++i) {
|
|
||||||
const QString current_name = h.filepath_at(i);
|
|
||||||
if(current_name.startsWith(old_path)) {
|
|
||||||
QString new_name = current_name;
|
|
||||||
new_name.replace(0, old_path.length(), new_path);
|
|
||||||
if(!force_recheck && QDir(h.save_path()).exists(new_name))
|
|
||||||
force_recheck = true;
|
|
||||||
new_name = QDir::cleanPath(new_name);
|
|
||||||
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
|
|
||||||
h.rename_file(i, new_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Force recheck
|
|
||||||
if(force_recheck) h.force_recheck();
|
|
||||||
// Rename folder in torrent files model too
|
|
||||||
PropListModel->setData(index, new_name_last);
|
|
||||||
// Remove old folder
|
|
||||||
const QDir old_folder(h.save_path()+"/"+old_path);
|
|
||||||
int timeout = 10;
|
|
||||||
while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) {
|
|
||||||
SleeperThread::msleep(100);
|
|
||||||
--timeout;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
bool force_recheck = false;
|
||||||
|
// Replace path in all files
|
||||||
void PropertiesWidget::askWebSeed(){
|
for(int i=0; i<num_files; ++i) {
|
||||||
bool ok;
|
const QString current_name = h.filepath_at(i);
|
||||||
// Ask user for a new url seed
|
if(current_name.startsWith(old_path)) {
|
||||||
const QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
QString new_name = current_name;
|
||||||
tr("New url seed:"), QLineEdit::Normal,
|
new_name.replace(0, old_path.length(), new_path);
|
||||||
QString::fromUtf8("http://www."), &ok);
|
if(!force_recheck && QDir(h.save_path()).exists(new_name))
|
||||||
if(!ok) return;
|
force_recheck = true;
|
||||||
qDebug("Adding %s web seed", qPrintable(url_seed));
|
new_name = QDir::cleanPath(new_name);
|
||||||
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
|
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
|
||||||
QMessageBox::warning(this, tr("qBittorrent"),
|
h.rename_file(i, new_name);
|
||||||
tr("This url seed is already in the list."),
|
|
||||||
QMessageBox::Ok);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
h.add_url_seed(url_seed);
|
|
||||||
// Refresh the seeds list
|
|
||||||
loadUrlSeeds();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::deleteSelectedUrlSeeds(){
|
|
||||||
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
|
||||||
bool change = false;
|
|
||||||
foreach(const QListWidgetItem *item, selectedItems){
|
|
||||||
QString url_seed = item->text();
|
|
||||||
h.remove_url_seed(url_seed);
|
|
||||||
change = true;
|
|
||||||
}
|
|
||||||
if(change){
|
|
||||||
// Refresh list
|
|
||||||
loadUrlSeeds();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PropertiesWidget::applyPriorities() {
|
|
||||||
qDebug("Saving files priorities");
|
|
||||||
const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
|
|
||||||
bool first_last_piece_first = false;
|
|
||||||
// Save first/last piece first option state
|
|
||||||
if(h.first_last_piece_first())
|
|
||||||
first_last_piece_first = true;
|
|
||||||
// Prioritize the files
|
|
||||||
qDebug("prioritize files: %d", priorities[0]);
|
|
||||||
h.prioritize_files(priorities);
|
|
||||||
// Restore first/last piece first option if necessary
|
|
||||||
if(first_last_piece_first)
|
|
||||||
h.prioritize_first_last_piece(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
|
||||||
if(!h.is_valid()) return;
|
|
||||||
QString new_path;
|
|
||||||
if(h.has_metadata() && h.num_files() == 1) {
|
|
||||||
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), h.firstFileSavePath());
|
|
||||||
} else {
|
|
||||||
const QDir saveDir(TorrentPersistentData::getSavePath(h.hash()));
|
|
||||||
QFileDialog dlg(this, tr("Choose save path"), saveDir.absolutePath());
|
|
||||||
dlg.setConfirmOverwrite(false);
|
|
||||||
dlg.setFileMode(QFileDialog::Directory);
|
|
||||||
dlg.setOption(QFileDialog::ShowDirsOnly, true);
|
|
||||||
dlg.setFilter(QDir::AllDirs);
|
|
||||||
dlg.setAcceptMode(QFileDialog::AcceptSave);
|
|
||||||
dlg.setNameFilterDetailsVisible(false);
|
|
||||||
if(dlg.exec())
|
|
||||||
new_path = dlg.selectedFiles().first();
|
|
||||||
}
|
|
||||||
if(!new_path.isEmpty()){
|
|
||||||
// Check if savePath exists
|
|
||||||
QString save_path_dir = new_path.replace("\\", "/");
|
|
||||||
QString new_file_name;
|
|
||||||
if(h.has_metadata() && h.num_files() == 1) {
|
|
||||||
QStringList parts = save_path_dir.split("/");
|
|
||||||
new_file_name = parts.takeLast(); // Skip file name
|
|
||||||
save_path_dir = parts.join("/");
|
|
||||||
}
|
}
|
||||||
QDir savePath(misc::expandPath(save_path_dir));
|
}
|
||||||
// Actually move storage
|
// Force recheck
|
||||||
if(!QBtSession::instance()->useTemporaryFolder() || h.is_seed()) {
|
if(force_recheck) h.force_recheck();
|
||||||
if(!savePath.exists()) savePath.mkpath(savePath.absolutePath());
|
// Rename folder in torrent files model too
|
||||||
h.move_storage(savePath.absolutePath());
|
PropListModel->setData(index, new_name_last);
|
||||||
}
|
// Remove old folder
|
||||||
// Update save_path in dialog
|
const QDir old_folder(h.save_path()+"/"+old_path);
|
||||||
QString display_path;
|
int timeout = 10;
|
||||||
if(h.has_metadata() && h.num_files() == 1) {
|
while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) {
|
||||||
// Rename the file
|
SleeperThread::msleep(100);
|
||||||
Q_ASSERT(!new_file_name.isEmpty());
|
--timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertiesWidget::askWebSeed(){
|
||||||
|
bool ok;
|
||||||
|
// Ask user for a new url seed
|
||||||
|
const QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
||||||
|
tr("New url seed:"), QLineEdit::Normal,
|
||||||
|
QString::fromUtf8("http://www."), &ok);
|
||||||
|
if(!ok) return;
|
||||||
|
qDebug("Adding %s web seed", qPrintable(url_seed));
|
||||||
|
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
|
||||||
|
QMessageBox::warning(this, tr("qBittorrent"),
|
||||||
|
tr("This url seed is already in the list."),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
h.add_url_seed(url_seed);
|
||||||
|
// Refresh the seeds list
|
||||||
|
loadUrlSeeds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertiesWidget::deleteSelectedUrlSeeds(){
|
||||||
|
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
||||||
|
bool change = false;
|
||||||
|
foreach(const QListWidgetItem *item, selectedItems){
|
||||||
|
QString url_seed = item->text();
|
||||||
|
h.remove_url_seed(url_seed);
|
||||||
|
change = true;
|
||||||
|
}
|
||||||
|
if(change){
|
||||||
|
// Refresh list
|
||||||
|
loadUrlSeeds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PropertiesWidget::applyPriorities() {
|
||||||
|
qDebug("Saving files priorities");
|
||||||
|
const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
|
||||||
|
// Save first/last piece first option state
|
||||||
|
bool first_last_piece_first = h.first_last_piece_first();
|
||||||
|
// Prioritize the files
|
||||||
|
qDebug("prioritize files: %d", priorities[0]);
|
||||||
|
h.prioritize_files(priorities);
|
||||||
|
// Restore first/last piece first option if necessary
|
||||||
|
if(first_last_piece_first)
|
||||||
|
h.prioritize_first_last_piece(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
||||||
|
if(!h.is_valid()) return;
|
||||||
|
QString new_path;
|
||||||
|
if(h.has_metadata() && h.num_files() == 1) {
|
||||||
|
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), h.firstFileSavePath());
|
||||||
|
} else {
|
||||||
|
const QDir saveDir(TorrentPersistentData::getSavePath(h.hash()));
|
||||||
|
QFileDialog dlg(this, tr("Choose save path"), saveDir.absolutePath());
|
||||||
|
dlg.setConfirmOverwrite(false);
|
||||||
|
dlg.setFileMode(QFileDialog::Directory);
|
||||||
|
dlg.setOption(QFileDialog::ShowDirsOnly, true);
|
||||||
|
dlg.setFilter(QDir::AllDirs);
|
||||||
|
dlg.setAcceptMode(QFileDialog::AcceptSave);
|
||||||
|
dlg.setNameFilterDetailsVisible(false);
|
||||||
|
if(dlg.exec())
|
||||||
|
new_path = dlg.selectedFiles().first();
|
||||||
|
}
|
||||||
|
if(!new_path.isEmpty()){
|
||||||
|
// Check if savePath exists
|
||||||
|
QString save_path_dir = new_path.replace("\\", "/");
|
||||||
|
QString new_file_name;
|
||||||
|
if(h.has_metadata() && h.num_files() == 1) {
|
||||||
|
QStringList parts = save_path_dir.split("/");
|
||||||
|
new_file_name = parts.takeLast(); // Skip file name
|
||||||
|
save_path_dir = parts.join("/");
|
||||||
|
}
|
||||||
|
QDir savePath(misc::expandPath(save_path_dir));
|
||||||
|
// Actually move storage
|
||||||
|
if(!QBtSession::instance()->useTemporaryFolder() || h.is_seed()) {
|
||||||
|
if(!savePath.exists()) savePath.mkpath(savePath.absolutePath());
|
||||||
|
h.move_storage(savePath.absolutePath());
|
||||||
|
}
|
||||||
|
// Update save_path in dialog
|
||||||
|
QString display_path;
|
||||||
|
if(h.has_metadata() && h.num_files() == 1) {
|
||||||
|
// Rename the file
|
||||||
|
Q_ASSERT(!new_file_name.isEmpty());
|
||||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
if(h.filename_at(0).compare(new_file_name, Qt::CaseInsensitive) != 0) {
|
if(h.filename_at(0).compare(new_file_name, Qt::CaseInsensitive) != 0) {
|
||||||
#else
|
#else
|
||||||
if(h.filename_at(0).compare(new_file_name, Qt::CaseSensitive) != 0) {
|
if(h.filename_at(0).compare(new_file_name, Qt::CaseSensitive) != 0) {
|
||||||
#endif
|
#endif
|
||||||
qDebug("Renaming single file to %s", qPrintable(new_file_name));
|
qDebug("Renaming single file to %s", qPrintable(new_file_name));
|
||||||
h.rename_file(0, new_file_name);
|
h.rename_file(0, new_file_name);
|
||||||
// Also rename it in the files list model
|
// Also rename it in the files list model
|
||||||
PropListModel->setData(PropListModel->index(0, 0), new_file_name);
|
PropListModel->setData(PropListModel->index(0, 0), new_file_name);
|
||||||
}
|
}
|
||||||
display_path = h.firstFileSavePath();
|
display_path = h.firstFileSavePath();
|
||||||
} else {
|
} else {
|
||||||
display_path = savePath.absolutePath();
|
display_path = savePath.absolutePath();
|
||||||
}
|
}
|
||||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
display_path = display_path.replace("/", "\\");
|
display_path = display_path.replace("/", "\\");
|
||||||
#endif
|
#endif
|
||||||
save_path->setText(display_path);
|
save_path->setText(display_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesWidget::filteredFilesChanged() {
|
void PropertiesWidget::filteredFilesChanged() {
|
||||||
if(h.is_valid()) {
|
if(h.is_valid()) {
|
||||||
applyPriorities();
|
applyPriorities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,27 +122,23 @@ int QTorrentHandle::num_pieces() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::first_last_piece_first() const {
|
bool QTorrentHandle::first_last_piece_first() const {
|
||||||
// Detect main file
|
// Detect first media file
|
||||||
int rank=0;
|
torrent_info::file_iterator it;
|
||||||
int main_file_index = 0;
|
int index = 0;
|
||||||
file_entry main_file = torrent_handle::get_torrent_info().file_at(0);
|
for(it = get_torrent_info().begin_files(); it != get_torrent_info().end_files(); it++) {
|
||||||
torrent_info::file_iterator it = torrent_handle::get_torrent_info().begin_files();
|
const QString ext = misc::toQStringU(it->path.string()).split(".").last();
|
||||||
it++; ++rank;
|
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
|
||||||
while(it != torrent_handle::get_torrent_info().end_files()) {
|
break;
|
||||||
if(it->size > main_file.size) {
|
|
||||||
main_file = *it;
|
|
||||||
main_file_index = rank;
|
|
||||||
}
|
}
|
||||||
it++;
|
++index;
|
||||||
++rank;
|
|
||||||
}
|
}
|
||||||
qDebug() << "Main file in the torrent is" << filepath(main_file);
|
file_entry media_file = torrent_handle::get_torrent_info().file_at(index);
|
||||||
int piece_size = torrent_handle::get_torrent_info().piece_length();
|
int piece_size = torrent_handle::get_torrent_info().piece_length();
|
||||||
Q_ASSERT(piece_size>0);
|
Q_ASSERT(piece_size>0);
|
||||||
int first_piece = floor((main_file.offset+1)/(double)piece_size);
|
int first_piece = floor((media_file.offset+1)/(double)piece_size);
|
||||||
Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces());
|
Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces());
|
||||||
qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1);
|
qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1);
|
||||||
int num_pieces_in_file = ceil(main_file.size/(double)piece_size);
|
int num_pieces_in_file = ceil(media_file.size/(double)piece_size);
|
||||||
int last_piece = first_piece+num_pieces_in_file-1;
|
int last_piece = first_piece+num_pieces_in_file-1;
|
||||||
Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces());
|
Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces());
|
||||||
qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1);
|
qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1);
|
||||||
|
@ -550,32 +546,18 @@ void QTorrentHandle::add_tracker(const announce_entry& url) const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::prioritize_first_last_piece(bool b) const {
|
void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
|
||||||
// Detect main file
|
|
||||||
int rank=0;
|
|
||||||
int main_file_index = 0;
|
|
||||||
file_entry main_file = torrent_handle::get_torrent_info().file_at(0);
|
|
||||||
torrent_info::file_iterator it = torrent_handle::get_torrent_info().begin_files();
|
|
||||||
it++; ++rank;
|
|
||||||
while(it != torrent_handle::get_torrent_info().end_files()) {
|
|
||||||
if(it->size > main_file.size) {
|
|
||||||
main_file = *it;
|
|
||||||
main_file_index = rank;
|
|
||||||
}
|
|
||||||
it++;
|
|
||||||
++rank;
|
|
||||||
}
|
|
||||||
qDebug() << "Main file in the torrent is" << filepath(main_file);
|
|
||||||
// Determine the priority to set
|
// Determine the priority to set
|
||||||
int prio = 7; // MAX
|
int prio = 7; // MAX
|
||||||
if(!b) prio = torrent_handle::file_priority(main_file_index);
|
if(!b) prio = torrent_handle::file_priority(file_index);
|
||||||
// Determine the first and last piece of the main file
|
file_entry file = get_torrent_info().file_at(file_index);
|
||||||
|
// Determine the first and last piece of the file
|
||||||
int piece_size = torrent_handle::get_torrent_info().piece_length();
|
int piece_size = torrent_handle::get_torrent_info().piece_length();
|
||||||
Q_ASSERT(piece_size>0);
|
Q_ASSERT(piece_size>0);
|
||||||
int first_piece = floor((main_file.offset+1)/(double)piece_size);
|
int first_piece = floor((file.offset+1)/(double)piece_size);
|
||||||
Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces());
|
Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces());
|
||||||
qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1);
|
qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1);
|
||||||
int num_pieces_in_file = ceil(main_file.size/(double)piece_size);
|
int num_pieces_in_file = ceil(file.size/(double)piece_size);
|
||||||
int last_piece = first_piece+num_pieces_in_file-1;
|
int last_piece = first_piece+num_pieces_in_file-1;
|
||||||
Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces());
|
Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces());
|
||||||
qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1);
|
qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1);
|
||||||
|
@ -583,6 +565,20 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const {
|
||||||
torrent_handle::piece_priority(last_piece, prio);
|
torrent_handle::piece_priority(last_piece, prio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QTorrentHandle::prioritize_first_last_piece(bool b) const {
|
||||||
|
// Download first and last pieces first for all media files in the torrent
|
||||||
|
torrent_info::file_iterator it;
|
||||||
|
int index = 0;
|
||||||
|
for(it = get_torrent_info().begin_files(); it != get_torrent_info().end_files(); it++) {
|
||||||
|
const QString ext = misc::toQStringU(it->path.string()).split(".").last();
|
||||||
|
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
|
||||||
|
qDebug() << "File" << it->path.string().c_str() << "is previewable, toggle downloading of first/last pieces first";
|
||||||
|
prioritize_first_last_piece(index, b);
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QTorrentHandle::rename_file(int index, QString name) const {
|
void QTorrentHandle::rename_file(int index, QString name) const {
|
||||||
torrent_handle::rename_file(index, std::string(name.toUtf8().constData()));
|
torrent_handle::rename_file(index, std::string(name.toUtf8().constData()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,99 +42,103 @@ class QStringList;
|
||||||
// to interact well with Qt types
|
// to interact well with Qt types
|
||||||
class QTorrentHandle : public libtorrent::torrent_handle {
|
class QTorrentHandle : public libtorrent::torrent_handle {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//
|
//
|
||||||
// Constructors
|
// Constructors
|
||||||
//
|
//
|
||||||
|
|
||||||
QTorrentHandle() {}
|
QTorrentHandle() {}
|
||||||
explicit QTorrentHandle(libtorrent::torrent_handle h);
|
explicit QTorrentHandle(libtorrent::torrent_handle h);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Getters
|
// Getters
|
||||||
//
|
//
|
||||||
QString hash() const;
|
QString hash() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
float progress() const;
|
float progress() const;
|
||||||
libtorrent::bitfield pieces() const;
|
libtorrent::bitfield pieces() const;
|
||||||
QString current_tracker() const;
|
QString current_tracker() const;
|
||||||
bool is_paused() const;
|
bool is_paused() const;
|
||||||
bool has_filtered_pieces() const;
|
bool has_filtered_pieces() const;
|
||||||
libtorrent::size_type total_size() const;
|
libtorrent::size_type total_size() const;
|
||||||
libtorrent::size_type piece_length() const;
|
libtorrent::size_type piece_length() const;
|
||||||
int num_pieces() const;
|
int num_pieces() const;
|
||||||
libtorrent::size_type total_wanted_done() const;
|
libtorrent::size_type total_wanted_done() const;
|
||||||
libtorrent::size_type total_wanted() const;
|
libtorrent::size_type total_wanted() const;
|
||||||
float download_payload_rate() const;
|
float download_payload_rate() const;
|
||||||
float upload_payload_rate() const;
|
float upload_payload_rate() const;
|
||||||
int num_connections() const;
|
int num_connections() const;
|
||||||
int connections_limit() const;
|
int connections_limit() const;
|
||||||
int num_peers() const;
|
int num_peers() const;
|
||||||
int num_seeds() const;
|
int num_seeds() const;
|
||||||
int num_complete() const;
|
int num_complete() const;
|
||||||
int num_incomplete() const;
|
int num_incomplete() const;
|
||||||
QString save_path() const;
|
QString save_path() const;
|
||||||
QStringList url_seeds() const;
|
QStringList url_seeds() const;
|
||||||
libtorrent::size_type actual_size() const;
|
libtorrent::size_type actual_size() const;
|
||||||
int num_files() const;
|
int num_files() const;
|
||||||
int queue_position() const;
|
int queue_position() const;
|
||||||
bool is_queued() const;
|
bool is_queued() const;
|
||||||
QString filename_at(unsigned int index) const;
|
QString filename_at(unsigned int index) const;
|
||||||
libtorrent::size_type filesize_at(unsigned int index) const;
|
libtorrent::size_type filesize_at(unsigned int index) const;
|
||||||
QString filepath_at(unsigned int index) const;
|
QString filepath_at(unsigned int index) const;
|
||||||
QString orig_filepath_at(unsigned int index) const;
|
QString orig_filepath_at(unsigned int index) const;
|
||||||
QString filepath(const libtorrent::file_entry &f) const;
|
QString filepath(const libtorrent::file_entry &f) const;
|
||||||
libtorrent::torrent_status::state_t state() const;
|
libtorrent::torrent_status::state_t state() const;
|
||||||
QString creator() const;
|
QString creator() const;
|
||||||
QString comment() const;
|
QString comment() const;
|
||||||
libtorrent::size_type total_failed_bytes() const;
|
libtorrent::size_type total_failed_bytes() const;
|
||||||
libtorrent::size_type total_redundant_bytes() const;
|
libtorrent::size_type total_redundant_bytes() const;
|
||||||
libtorrent::size_type total_payload_download() const;
|
libtorrent::size_type total_payload_download() const;
|
||||||
libtorrent::size_type total_payload_upload() const;
|
libtorrent::size_type total_payload_upload() const;
|
||||||
libtorrent::size_type all_time_upload() const;
|
libtorrent::size_type all_time_upload() const;
|
||||||
libtorrent::size_type all_time_download() const;
|
libtorrent::size_type all_time_download() const;
|
||||||
libtorrent::size_type total_done() const;
|
libtorrent::size_type total_done() const;
|
||||||
QStringList files_path() const;
|
QStringList files_path() const;
|
||||||
QStringList uneeded_files_path() const;
|
QStringList uneeded_files_path() const;
|
||||||
bool has_missing_files() const;
|
bool has_missing_files() const;
|
||||||
int num_uploads() const;
|
int num_uploads() const;
|
||||||
bool is_seed() const;
|
bool is_seed() const;
|
||||||
bool is_checking() const;
|
bool is_checking() const;
|
||||||
bool is_auto_managed() const;
|
bool is_auto_managed() const;
|
||||||
qlonglong active_time() const;
|
qlonglong active_time() const;
|
||||||
qlonglong seeding_time() const;
|
qlonglong seeding_time() const;
|
||||||
QString creation_date() const;
|
QString creation_date() const;
|
||||||
QString next_announce() const;
|
QString next_announce() const;
|
||||||
qlonglong next_announce_s() const;
|
qlonglong next_announce_s() const;
|
||||||
bool priv() const;
|
bool priv() const;
|
||||||
bool first_last_piece_first() const;
|
bool first_last_piece_first() const;
|
||||||
QString root_path() const;
|
QString root_path() const;
|
||||||
QString firstFileSavePath() const;
|
QString firstFileSavePath() const;
|
||||||
bool has_error() const;
|
bool has_error() const;
|
||||||
QString error() const;
|
QString error() const;
|
||||||
void downloading_pieces(libtorrent::bitfield &bf) const;
|
void downloading_pieces(libtorrent::bitfield &bf) const;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setters
|
// Setters
|
||||||
//
|
//
|
||||||
void pause() const;
|
void pause() const;
|
||||||
void resume() const;
|
void resume() const;
|
||||||
void remove_url_seed(QString seed) const;
|
void remove_url_seed(QString seed) const;
|
||||||
void add_url_seed(QString seed) const;
|
void add_url_seed(QString seed) const;
|
||||||
void prioritize_files(const std::vector<int> &v) const;
|
void prioritize_files(const std::vector<int> &v) const;
|
||||||
void file_priority(int index, int priority) const;
|
void file_priority(int index, int priority) const;
|
||||||
void set_tracker_login(QString username, QString password) const;
|
void set_tracker_login(QString username, QString password) const;
|
||||||
void move_storage(QString path) const;
|
void move_storage(QString path) const;
|
||||||
void add_tracker(const libtorrent::announce_entry& url) const;
|
void add_tracker(const libtorrent::announce_entry& url) const;
|
||||||
void prioritize_first_last_piece(bool b) const;
|
void prioritize_first_last_piece(bool b) const;
|
||||||
void rename_file(int index, QString name) const;
|
void rename_file(int index, QString name) const;
|
||||||
bool save_torrent_file(QString path) const;
|
bool save_torrent_file(QString path) const;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Operators
|
||||||
|
//
|
||||||
|
bool operator ==(const QTorrentHandle& new_h) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void prioritize_first_last_piece(int file_index, bool b) const;
|
||||||
|
|
||||||
//
|
|
||||||
// Operators
|
|
||||||
//
|
|
||||||
bool operator ==(const QTorrentHandle& new_h) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue