2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2015-06-10 21:27:11 +00:00
|
|
|
* This file Copyright (C) 2009-2015 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-12-21 23:49:39 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QFileInfo>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h> /* mime64 */
|
2012-12-14 04:34:42 +00:00
|
|
|
#include <libtransmission/variant.h>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "AddData.h"
|
|
|
|
#include "FreeSpaceLabel.h"
|
|
|
|
#include "OptionsDialog.h"
|
|
|
|
#include "Prefs.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Torrent.h"
|
|
|
|
#include "Utils.h"
|
2020-07-27 04:30:58 +00:00
|
|
|
#include "VariantHelpers.h"
|
|
|
|
|
|
|
|
using ::trqt::variant_helpers::dictAdd;
|
|
|
|
using ::trqt::variant_helpers::listAdd;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
OptionsDialog::OptionsDialog(Session& session, Prefs const& prefs, AddData addme, QWidget* parent) :
|
2017-04-19 12:04:45 +00:00
|
|
|
BaseDialog(parent),
|
2020-06-05 19:02:11 +00:00
|
|
|
add_(std::move(addme)),
|
2020-05-27 21:53:12 +00:00
|
|
|
verify_button_(new QPushButton(tr("&Verify Local Data"), this)),
|
|
|
|
session_(session),
|
|
|
|
is_local_(session_.isLocal())
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.setupUi(this);
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString title;
|
2013-02-09 23:11:17 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (add_.type == AddData::FILENAME)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
title = tr("Open Torrent from File");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
title = tr("Open Torrent from URL or Magnet Link");
|
|
|
|
}
|
2013-02-09 23:11:17 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
setWindowTitle(title);
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
edit_timer_.setInterval(2000);
|
|
|
|
edit_timer_.setSingleShot(true);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&edit_timer_, &QTimer::timeout, this, &OptionsDialog::onDestinationChanged);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (add_.type == AddData::FILENAME)
|
2013-02-09 23:11:17 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.sourceStack->setCurrentWidget(ui_.sourceButton);
|
|
|
|
ui_.sourceButton->setMode(PathButton::FileMode);
|
|
|
|
ui_.sourceButton->setTitle(tr("Open Torrent"));
|
|
|
|
ui_.sourceButton->setNameFilter(tr("Torrent Files (*.torrent);;All Files (*.*)"));
|
|
|
|
ui_.sourceButton->setPath(add_.filename);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.sourceButton, &PathButton::pathChanged, this, &OptionsDialog::onSourceChanged);
|
2013-02-09 23:11:17 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-02-09 23:11:17 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.sourceStack->setCurrentWidget(ui_.sourceEdit);
|
|
|
|
ui_.sourceEdit->setText(add_.readableName());
|
|
|
|
ui_.sourceEdit->selectAll();
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.sourceEdit, &QLineEdit::editingFinished, this, &OptionsDialog::onSourceChanged);
|
2013-02-09 23:11:17 +00:00
|
|
|
}
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.sourceStack->setFixedHeight(ui_.sourceStack->currentWidget()->sizeHint().height());
|
|
|
|
ui_.sourceLabel->setBuddy(ui_.sourceStack->currentWidget());
|
2014-12-29 04:03:56 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
QFontMetrics const font_metrics(font());
|
|
|
|
int const width = font_metrics.size(0, QStringLiteral("This is a pretty long torrent filename indeed.torrent")).width();
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.sourceStack->setMinimumWidth(width);
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const download_dir(Utils::removeTrailingDirSeparator(prefs.getString(Prefs::DOWNLOAD_DIR)));
|
|
|
|
ui_.freeSpaceLabel->setSession(session_);
|
|
|
|
ui_.freeSpaceLabel->setPath(download_dir);
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.destinationButton->setMode(PathButton::DirectoryMode);
|
|
|
|
ui_.destinationButton->setTitle(tr("Select Destination"));
|
|
|
|
ui_.destinationButton->setPath(download_dir);
|
|
|
|
ui_.destinationEdit->setText(download_dir);
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_local_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
local_destination_.setPath(download_dir);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2016-10-03 18:26:28 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.destinationButton, &PathButton::pathChanged, this, &OptionsDialog::onDestinationChanged);
|
|
|
|
connect(ui_.destinationEdit, &QLineEdit::textEdited, &edit_timer_, qOverload<>(&QTimer::start));
|
|
|
|
connect(ui_.destinationEdit, &QLineEdit::editingFinished, this, &OptionsDialog::onDestinationChanged);
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.filesView->setEditable(false);
|
2014-12-29 04:03:56 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.priorityCombo->addItem(tr("High"), TR_PRI_HIGH);
|
|
|
|
ui_.priorityCombo->addItem(tr("Normal"), TR_PRI_NORMAL);
|
|
|
|
ui_.priorityCombo->addItem(tr("Low"), TR_PRI_LOW);
|
|
|
|
ui_.priorityCombo->setCurrentIndex(1); // Normal
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.dialogButtons->addButton(verify_button_, QDialogButtonBox::ActionRole);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(verify_button_, &QAbstractButton::clicked, this, &OptionsDialog::onVerify);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.startCheck->setChecked(prefs.getBool(Prefs::START));
|
|
|
|
ui_.trashCheck->setChecked(prefs.getBool(Prefs::TRASH_ORIGINAL));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.dialogButtons, &QDialogButtonBox::rejected, this, &QObject::deleteLater);
|
|
|
|
connect(ui_.dialogButtons, &QDialogButtonBox::accepted, this, &OptionsDialog::onAccepted);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.filesView, &FileTreeView::priorityChanged, this, &OptionsDialog::onPriorityChanged);
|
|
|
|
connect(ui_.filesView, &FileTreeView::wantedChanged, this, &OptionsDialog::onWantedChanged);
|
2009-05-03 22:00:56 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&verify_timer_, &QTimer::timeout, this, &OptionsDialog::onTimeout);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&session_, &Session::sessionUpdated, this, &OptionsDialog::onSessionUpdated);
|
2016-10-03 18:26:28 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
updateWidgetsLocality();
|
|
|
|
reload();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
OptionsDialog::~OptionsDialog()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
clearInfo();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::clearInfo()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (have_info_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_metainfoFree(&info_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
have_info_ = false;
|
|
|
|
files_.clear();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::reload()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
clearInfo();
|
|
|
|
clearVerify();
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
tr_ctor* ctor = tr_ctorNew(nullptr);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
switch (add_.type)
|
2013-02-09 21:47:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case AddData::MAGNET:
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_ctorSetMetainfoFromMagnetLink(ctor, add_.magnet.toUtf8().constData());
|
2013-02-09 21:47:42 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case AddData::FILENAME:
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_ctorSetMetainfoFromFile(ctor, add_.filename.toUtf8().constData());
|
2013-02-09 21:47:42 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case AddData::METAINFO:
|
2020-06-15 14:30:29 +00:00
|
|
|
tr_ctorSetMetainfo(ctor, add_.metainfo.constData(), add_.metainfo.size());
|
2013-02-09 21:47:42 +00:00
|
|
|
break;
|
2010-08-01 18:55:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
2013-02-09 21:47:42 +00:00
|
|
|
break;
|
2010-08-01 18:55:04 +00:00
|
|
|
}
|
2010-05-13 23:54:32 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
int const err = tr_torrentParse(ctor, &info_);
|
|
|
|
have_info_ = err == 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_ctorFree(ctor);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.filesView->clear();
|
|
|
|
files_.clear();
|
|
|
|
priorities_.clear();
|
|
|
|
wanted_.clear();
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const have_files_to_show = have_info_ && info_.fileCount > 0;
|
2014-12-29 04:03:56 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.filesView->setVisible(have_files_to_show);
|
|
|
|
verify_button_->setEnabled(have_files_to_show);
|
|
|
|
layout()->setSizeConstraint(have_files_to_show ? QLayout::SetDefaultConstraint : QLayout::SetFixedSize);
|
2013-02-10 22:44:25 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (have_info_)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
priorities_.insert(0, info_.fileCount, TR_PRI_NORMAL);
|
|
|
|
wanted_.insert(0, info_.fileCount, true);
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (tr_file_index_t i = 0; i < info_.fileCount; ++i)
|
2013-02-09 21:47:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TorrentFile file;
|
|
|
|
file.index = i;
|
2020-05-27 21:53:12 +00:00
|
|
|
file.priority = priorities_[i];
|
|
|
|
file.wanted = wanted_[i];
|
|
|
|
file.size = info_.files[i].length;
|
2017-04-19 12:04:45 +00:00
|
|
|
file.have = 0;
|
2020-05-27 21:53:12 +00:00
|
|
|
file.filename = QString::fromUtf8(info_.files[i].name);
|
|
|
|
files_.append(file);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.filesView->update(files_);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::updateWidgetsLocality()
|
2016-10-03 18:26:28 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.destinationStack->setCurrentWidget(is_local_ ? static_cast<QWidget*>(ui_.destinationButton) : ui_.destinationEdit);
|
|
|
|
ui_.destinationStack->setFixedHeight(ui_.destinationStack->currentWidget()->sizeHint().height());
|
|
|
|
ui_.destinationLabel->setBuddy(ui_.destinationStack->currentWidget());
|
2016-10-03 18:26:28 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// hide the % done when non-local, since we've no way of knowing
|
2020-05-27 21:53:12 +00:00
|
|
|
(ui_.filesView->*(is_local_ ? &QTreeView::showColumn : &QTreeView::hideColumn))(2);
|
2016-10-03 18:26:28 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
verify_button_->setVisible(is_local_);
|
2016-10-03 18:26:28 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::onSessionUpdated()
|
2016-10-03 18:26:28 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const is_local = session_.isLocal();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_local_ != is_local)
|
2016-10-03 18:26:28 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
is_local_ = is_local;
|
2017-04-19 12:04:45 +00:00
|
|
|
updateWidgetsLocality();
|
2016-10-03 18:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void OptionsDialog::onPriorityChanged(QSet<int> const& file_indices, int priority)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int const i : file_indices)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
priorities_[i] = priority;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void OptionsDialog::onWantedChanged(QSet<int> const& file_indices, bool is_wanted)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int const i : file_indices)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
wanted_[i] = is_wanted;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::onAccepted()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
// rpc spec section 3.4 "adding a torrent"
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 10);
|
2020-05-27 21:53:12 +00:00
|
|
|
QString download_dir;
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// "download-dir"
|
2020-05-27 21:53:12 +00:00
|
|
|
if (ui_.destinationStack->currentWidget() == ui_.destinationButton)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
download_dir = local_destination_.absolutePath();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
download_dir = ui_.destinationEdit->text();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-02-09 23:11:17 +00:00
|
|
|
|
2020-07-27 04:30:58 +00:00
|
|
|
dictAdd(&args, TR_KEY_download_dir, download_dir);
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// paused
|
2020-07-27 04:30:58 +00:00
|
|
|
dictAdd(&args, TR_KEY_paused, !ui_.startCheck->isChecked());
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// priority
|
2020-05-27 21:53:12 +00:00
|
|
|
int const index = ui_.priorityCombo->currentIndex();
|
|
|
|
int const priority = ui_.priorityCombo->itemData(index).toInt();
|
2020-07-27 04:30:58 +00:00
|
|
|
dictAdd(&args, TR_KEY_bandwidthPriority, priority);
|
2013-02-09 21:47:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// files-unwanted
|
2020-05-27 21:53:12 +00:00
|
|
|
int count = wanted_.count(false);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (count > 0)
|
2013-02-09 21:47:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant* l = tr_variantDictAddList(&args, TR_KEY_files_unwanted, count);
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int i = 0, n = wanted_.size(); i < n; ++i)
|
2014-12-29 04:03:56 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!wanted_.at(i))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-07-27 04:30:58 +00:00
|
|
|
listAdd(l, i);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2014-12-29 04:03:56 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// priority-low
|
2020-05-27 21:53:12 +00:00
|
|
|
count = priorities_.count(TR_PRI_LOW);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (count > 0)
|
2013-02-09 21:47:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant* l = tr_variantDictAddList(&args, TR_KEY_priority_low, count);
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int i = 0, n = priorities_.size(); i < n; ++i)
|
2014-12-29 04:03:56 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (priorities_.at(i) == TR_PRI_LOW)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-07-27 04:30:58 +00:00
|
|
|
listAdd(l, i);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2014-12-29 04:03:56 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// priority-high
|
2020-05-27 21:53:12 +00:00
|
|
|
count = priorities_.count(TR_PRI_HIGH);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (count > 0)
|
2013-02-09 21:47:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant* l = tr_variantDictAddList(&args, TR_KEY_priority_high, count);
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int i = 0, n = priorities_.size(); i < n; ++i)
|
2014-12-29 04:03:56 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (priorities_.at(i) == TR_PRI_HIGH)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-07-27 04:30:58 +00:00
|
|
|
listAdd(l, i);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2014-12-29 04:03:56 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.addTorrent(add_, &args, ui_.trashCheck->isChecked());
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
deleteLater();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::onSourceChanged()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (ui_.sourceStack->currentWidget() == ui_.sourceButton)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
add_.set(ui_.sourceButton->path());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
add_.set(ui_.sourceEdit->text());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2014-12-29 04:03:56 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
reload();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::onDestinationChanged()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (ui_.destinationStack->currentWidget() == ui_.destinationButton)
|
2014-12-31 21:00:34 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
local_destination_.setPath(ui_.destinationButton->path());
|
|
|
|
ui_.freeSpaceLabel->setPath(local_destination_.absolutePath());
|
2014-12-31 21:00:34 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2014-12-31 21:00:34 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.freeSpaceLabel->setPath(ui_.destinationEdit->text());
|
2014-12-31 21:00:34 +00:00
|
|
|
}
|
2013-02-09 04:42:07 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** VERIFY
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::clearVerify()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
verify_hash_.reset();
|
|
|
|
verify_file_.close();
|
|
|
|
verify_file_pos_ = 0;
|
|
|
|
verify_flags_.clear();
|
|
|
|
verify_file_index_ = 0;
|
|
|
|
verify_piece_index_ = 0;
|
|
|
|
verify_piece_pos_ = 0;
|
|
|
|
verify_timer_.stop();
|
|
|
|
|
|
|
|
for (TorrentFile& f : files_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
f.have = 0;
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.filesView->update(files_);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void OptionsDialog::onVerify()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
clearVerify();
|
2020-05-27 21:53:12 +00:00
|
|
|
verify_flags_.insert(0, info_.pieceCount, false);
|
|
|
|
verify_timer_.setSingleShot(false);
|
|
|
|
verify_timer_.start(0);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
uint64_t getPieceSize(tr_info const* info, tr_piece_index_t piece_index)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (piece_index != info->pieceCount - 1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return info->pieceSize;
|
|
|
|
}
|
|
|
|
|
2013-02-09 21:47:42 +00:00
|
|
|
return info->totalSize % info->pieceSize;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void OptionsDialog::onTimeout()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (files_.isEmpty())
|
2013-02-10 22:44:25 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
verify_timer_.stop();
|
2017-04-19 12:04:45 +00:00
|
|
|
return;
|
2013-02-10 22:44:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_file const* file = &info_.files[verify_file_index_];
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (verify_file_pos_ == 0 && !verify_file_.isOpen())
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QFileInfo const file_info(local_destination_, QString::fromUtf8(file->name));
|
|
|
|
verify_file_.setFileName(file_info.absoluteFilePath());
|
|
|
|
verify_file_.open(QIODevice::ReadOnly);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
int64_t left_in_piece = getPieceSize(&info_, verify_piece_index_) - verify_piece_pos_;
|
|
|
|
int64_t left_in_file = file->length - verify_file_pos_;
|
|
|
|
int64_t bytes_this_pass = qMin(left_in_file, left_in_piece);
|
|
|
|
bytes_this_pass = qMin(bytes_this_pass, static_cast<int64_t>(sizeof(verify_buf_)));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (verify_file_.isOpen() && verify_file_.seek(verify_file_pos_))
|
2013-02-09 21:47:42 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
int64_t num_read = verify_file_.read(verify_buf_, bytes_this_pass);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
if (num_read == bytes_this_pass)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
verify_hash_.addData(verify_buf_, num_read);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
left_in_piece -= bytes_this_pass;
|
|
|
|
left_in_file -= bytes_this_pass;
|
|
|
|
verify_piece_pos_ += bytes_this_pass;
|
|
|
|
verify_file_pos_ += bytes_this_pass;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
verify_bins_[verify_file_index_] += bytes_this_pass;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (left_in_piece == 0)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QByteArray const result(verify_hash_.result());
|
|
|
|
bool const matches = memcmp(result.constData(), info_.pieces[verify_piece_index_].hash, SHA_DIGEST_LENGTH) == 0;
|
|
|
|
verify_flags_[verify_piece_index_] = matches;
|
|
|
|
verify_piece_pos_ = 0;
|
|
|
|
++verify_piece_index_;
|
|
|
|
verify_hash_.reset();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
FileList changed_files;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (matches)
|
2013-02-09 21:47:42 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
for (auto i = verify_bins_.begin(), end = verify_bins_.end(); i != end; ++i)
|
2013-02-09 21:47:42 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
TorrentFile& f(files_[i.key()]);
|
2017-04-19 12:04:45 +00:00
|
|
|
f.have += i.value();
|
2020-05-27 21:53:12 +00:00
|
|
|
changed_files.append(f);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.filesView->update(changed_files);
|
|
|
|
verify_bins_.clear();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (left_in_file == 0)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
verify_file_.close();
|
|
|
|
++verify_file_index_;
|
|
|
|
verify_file_pos_ = 0;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
bool done = verify_piece_index_ >= info_.pieceCount;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (done)
|
2010-08-04 16:25:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
uint64_t have = 0;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (TorrentFile const& f : files_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
have += f.have;
|
|
|
|
}
|
2010-08-04 16:25:30 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (have == 0) // everything failed
|
2010-08-04 16:25:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
// did the user accidentally specify the child directory instead of the parent?
|
2017-04-20 16:02:19 +00:00
|
|
|
QStringList const tokens = QString::fromUtf8(file->name).split(QLatin1Char('/'));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!tokens.empty() && local_destination_.dirName() == tokens.at(0))
|
2010-08-04 16:25:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
// move up one directory and try again
|
2020-05-27 21:53:12 +00:00
|
|
|
local_destination_.cdUp();
|
2017-04-19 12:04:45 +00:00
|
|
|
onVerify();
|
|
|
|
done = false;
|
2010-08-04 16:25:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (done)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
verify_timer_.stop();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|