mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
Follow project coding style. Issue #2192.
This commit is contained in:
parent
44992056cf
commit
6644791458
6 changed files with 1426 additions and 1339 deletions
|
@ -73,17 +73,21 @@ static QPair<int, int> get_file_extremity_pieces(const torrent_info& t, int file
|
||||||
return qMakePair(first_piece, last_piece);
|
return qMakePair(first_piece, last_piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTorrentHandle::QTorrentHandle(const torrent_handle& h): torrent_handle(h) {}
|
QTorrentHandle::QTorrentHandle(const torrent_handle& h): torrent_handle(h)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Getters
|
// Getters
|
||||||
//
|
//
|
||||||
|
|
||||||
QString QTorrentHandle::hash() const {
|
QString QTorrentHandle::hash() const
|
||||||
|
{
|
||||||
return misc::toQString(torrent_handle::info_hash());
|
return misc::toQString(torrent_handle::info_hash());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::name() const {
|
QString QTorrentHandle::name() const
|
||||||
|
{
|
||||||
QString name = TorrentPersistentData::getName(hash());
|
QString name = TorrentPersistentData::getName(hash());
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
|
@ -95,7 +99,8 @@ QString QTorrentHandle::name() const {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::creation_date() const {
|
QString QTorrentHandle::creation_date() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
|
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
|
||||||
#else
|
#else
|
||||||
|
@ -104,7 +109,8 @@ QString QTorrentHandle::creation_date() const {
|
||||||
return t ? misc::toQString(*t) : "";
|
return t ? misc::toQString(*t) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
qlonglong QTorrentHandle::creation_date_unix() const {
|
qlonglong QTorrentHandle::creation_date_unix() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
|
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
|
||||||
#else
|
#else
|
||||||
|
@ -113,19 +119,23 @@ qlonglong QTorrentHandle::creation_date_unix() const {
|
||||||
return t ? *t : -1;
|
return t ? *t : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::current_tracker() const {
|
QString QTorrentHandle::current_tracker() const
|
||||||
|
{
|
||||||
return misc::toQString(status(0x0).current_tracker);
|
return misc::toQString(status(0x0).current_tracker);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_paused() const {
|
bool QTorrentHandle::is_paused() const
|
||||||
|
{
|
||||||
return is_paused(status(0x0));
|
return is_paused(status(0x0));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_queued() const {
|
bool QTorrentHandle::is_queued() const
|
||||||
|
{
|
||||||
return is_queued(status(0x0));
|
return is_queued(status(0x0));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_type QTorrentHandle::total_size() const {
|
size_type QTorrentHandle::total_size() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return torrent_handle::get_torrent_info().total_size();
|
return torrent_handle::get_torrent_info().total_size();
|
||||||
#else
|
#else
|
||||||
|
@ -133,7 +143,8 @@ size_type QTorrentHandle::total_size() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_type QTorrentHandle::piece_length() const {
|
size_type QTorrentHandle::piece_length() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return torrent_handle::get_torrent_info().piece_length();
|
return torrent_handle::get_torrent_info().piece_length();
|
||||||
#else
|
#else
|
||||||
|
@ -141,7 +152,8 @@ size_type QTorrentHandle::piece_length() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int QTorrentHandle::num_pieces() const {
|
int QTorrentHandle::num_pieces() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return torrent_handle::get_torrent_info().num_pieces();
|
return torrent_handle::get_torrent_info().num_pieces();
|
||||||
#else
|
#else
|
||||||
|
@ -149,7 +161,8 @@ int QTorrentHandle::num_pieces() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::first_last_piece_first() const {
|
bool QTorrentHandle::first_last_piece_first() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
torrent_info const* t = &get_torrent_info();
|
torrent_info const* t = &get_torrent_info();
|
||||||
#else
|
#else
|
||||||
|
@ -168,14 +181,14 @@ bool QTorrentHandle::first_last_piece_first() const {
|
||||||
if (index >= t->num_files()) // No media file
|
if (index >= t->num_files()) // No media file
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
QPair<int, int> extremities = get_file_extremity_pieces(*t, index);
|
QPair<int, int> extremities = get_file_extremity_pieces(*t, index);
|
||||||
|
|
||||||
return (torrent_handle::piece_priority(extremities.first) == 7)
|
return (torrent_handle::piece_priority(extremities.first) == 7)
|
||||||
&& (torrent_handle::piece_priority(extremities.second) == 7);
|
&& (torrent_handle::piece_priority(extremities.second) == 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::save_path() const {
|
QString QTorrentHandle::save_path() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::save_path()));
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::save_path()));
|
||||||
#else
|
#else
|
||||||
|
@ -183,11 +196,13 @@ QString QTorrentHandle::save_path() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::save_path_parsed() const {
|
QString QTorrentHandle::save_path_parsed() const
|
||||||
|
{
|
||||||
QString p;
|
QString p;
|
||||||
if (has_metadata() && num_files() == 1) {
|
if (has_metadata() && num_files() == 1) {
|
||||||
p = firstFileSavePath();
|
p = firstFileSavePath();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
p = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
|
p = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
|
||||||
if (p.isEmpty())
|
if (p.isEmpty())
|
||||||
p = save_path();
|
p = save_path();
|
||||||
|
@ -195,14 +210,15 @@ QString QTorrentHandle::save_path_parsed() const {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QTorrentHandle::url_seeds() const {
|
QStringList QTorrentHandle::url_seeds() const
|
||||||
|
{
|
||||||
QStringList res;
|
QStringList res;
|
||||||
try {
|
try {
|
||||||
const std::set<std::string> existing_seeds = torrent_handle::url_seeds();
|
const std::set<std::string> existing_seeds = torrent_handle::url_seeds();
|
||||||
|
|
||||||
std::set<std::string>::const_iterator it = existing_seeds.begin();
|
std::set<std::string>::const_iterator it = existing_seeds.begin();
|
||||||
std::set<std::string>::const_iterator itend = existing_seeds.end();
|
std::set<std::string>::const_iterator itend = existing_seeds.end();
|
||||||
for ( ; it != itend; ++it) {
|
for (; it != itend; ++it) {
|
||||||
qDebug("URL Seed: %s", it->c_str());
|
qDebug("URL Seed: %s", it->c_str());
|
||||||
res << misc::toQString(*it);
|
res << misc::toQString(*it);
|
||||||
}
|
}
|
||||||
|
@ -213,20 +229,22 @@ QStringList QTorrentHandle::url_seeds() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the size of the torrent without the filtered files
|
// get the size of the torrent without the filtered files
|
||||||
size_type QTorrentHandle::actual_size() const {
|
size_type QTorrentHandle::actual_size() const
|
||||||
|
{
|
||||||
return status(query_accurate_download_counters).total_wanted;
|
return status(query_accurate_download_counters).total_wanted;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::has_filtered_pieces() const {
|
bool QTorrentHandle::has_filtered_pieces() const
|
||||||
|
{
|
||||||
const std::vector<int> piece_priorities = torrent_handle::piece_priorities();
|
const std::vector<int> piece_priorities = torrent_handle::piece_priorities();
|
||||||
foreach (const int priority, piece_priorities) {
|
foreach (const int priority, piece_priorities)
|
||||||
if (priority == 0)
|
if (priority == 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QTorrentHandle::num_files() const {
|
int QTorrentHandle::num_files() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return torrent_handle::get_torrent_info().num_files();
|
return torrent_handle::get_torrent_info().num_files();
|
||||||
#else
|
#else
|
||||||
|
@ -234,7 +252,8 @@ int QTorrentHandle::num_files() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::filename_at(unsigned int index) const {
|
QString QTorrentHandle::filename_at(unsigned int index) const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
|
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
|
||||||
#else
|
#else
|
||||||
|
@ -243,7 +262,8 @@ QString QTorrentHandle::filename_at(unsigned int index) const {
|
||||||
return fsutils::fileName(filepath_at(index));
|
return fsutils::fileName(filepath_at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_type QTorrentHandle::filesize_at(unsigned int index) const {
|
size_type QTorrentHandle::filesize_at(unsigned int index) const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
|
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
|
||||||
return torrent_handle::get_torrent_info().files().file_size(index);
|
return torrent_handle::get_torrent_info().files().file_size(index);
|
||||||
|
@ -253,7 +273,8 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::filepath_at(unsigned int index) const {
|
QString QTorrentHandle::filepath_at(unsigned int index) const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return filepath_at(torrent_handle::get_torrent_info(), index);
|
return filepath_at(torrent_handle::get_torrent_info(), index);
|
||||||
#else
|
#else
|
||||||
|
@ -261,7 +282,8 @@ QString QTorrentHandle::filepath_at(unsigned int index) const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
|
QString QTorrentHandle::orig_filepath_at(unsigned int index) const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index)));
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index)));
|
||||||
#else
|
#else
|
||||||
|
@ -270,11 +292,13 @@ QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent_status::state_t QTorrentHandle::state() const {
|
torrent_status::state_t QTorrentHandle::state() const
|
||||||
|
{
|
||||||
return status(0x0).state;
|
return status(0x0).state;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::creator() const {
|
QString QTorrentHandle::creator() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return misc::toQStringU(torrent_handle::get_torrent_info().creator());
|
return misc::toQStringU(torrent_handle::get_torrent_info().creator());
|
||||||
#else
|
#else
|
||||||
|
@ -282,7 +306,8 @@ QString QTorrentHandle::creator() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::comment() const {
|
QString QTorrentHandle::comment() const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return misc::toQStringU(torrent_handle::get_torrent_info().comment());
|
return misc::toQStringU(torrent_handle::get_torrent_info().comment());
|
||||||
#else
|
#else
|
||||||
|
@ -290,22 +315,24 @@ QString QTorrentHandle::comment() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_checking() const {
|
bool QTorrentHandle::is_checking() const
|
||||||
|
{
|
||||||
return is_checking(status(0x0));
|
return is_checking(status(0x0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a list of absolute paths corresponding
|
// Return a list of absolute paths corresponding
|
||||||
// to all files in a torrent
|
// to all files in a torrent
|
||||||
QStringList QTorrentHandle::absolute_files_path() const {
|
QStringList QTorrentHandle::absolute_files_path() const
|
||||||
|
{
|
||||||
QDir saveDir(save_path());
|
QDir saveDir(save_path());
|
||||||
QStringList res;
|
QStringList res;
|
||||||
for (int i = 0; i<num_files(); ++i) {
|
for (int i = 0; i<num_files(); ++i)
|
||||||
res << fsutils::expandPathAbs(saveDir.absoluteFilePath(filepath_at(i)));
|
res << fsutils::expandPathAbs(saveDir.absoluteFilePath(filepath_at(i)));
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QTorrentHandle::absolute_files_path_uneeded() const {
|
QStringList QTorrentHandle::absolute_files_path_uneeded() const
|
||||||
|
{
|
||||||
QDir saveDir(save_path());
|
QDir saveDir(save_path());
|
||||||
QStringList res;
|
QStringList res;
|
||||||
std::vector<int> fp = torrent_handle::file_priorities();
|
std::vector<int> fp = torrent_handle::file_priorities();
|
||||||
|
@ -319,19 +346,21 @@ QStringList QTorrentHandle::absolute_files_path_uneeded() const {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::has_missing_files() const {
|
bool QTorrentHandle::has_missing_files() const
|
||||||
|
{
|
||||||
const QStringList paths = absolute_files_path();
|
const QStringList paths = absolute_files_path();
|
||||||
foreach (const QString &path, paths) {
|
foreach (const QString &path, paths)
|
||||||
if (!QFile::exists(path)) return true;
|
if (!QFile::exists(path)) return true;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QTorrentHandle::queue_position() const {
|
int QTorrentHandle::queue_position() const
|
||||||
|
{
|
||||||
return queue_position(status(0x0));
|
return queue_position(status(0x0));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_seed() const {
|
bool QTorrentHandle::is_seed() const
|
||||||
|
{
|
||||||
// Affected by bug http://code.rasterbar.com/libtorrent/ticket/402
|
// Affected by bug http://code.rasterbar.com/libtorrent/ticket/402
|
||||||
//return torrent_handle::is_seed();
|
//return torrent_handle::is_seed();
|
||||||
// May suffer from approximation problems
|
// May suffer from approximation problems
|
||||||
|
@ -340,11 +369,13 @@ bool QTorrentHandle::is_seed() const {
|
||||||
return is_seed(status(0x0));
|
return is_seed(status(0x0));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_sequential_download() const {
|
bool QTorrentHandle::is_sequential_download() const
|
||||||
|
{
|
||||||
return status(0x0).sequential_download;
|
return status(0x0).sequential_download;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::priv() const {
|
bool QTorrentHandle::priv() const
|
||||||
|
{
|
||||||
if (!has_metadata())
|
if (!has_metadata())
|
||||||
return false;
|
return false;
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
|
@ -354,7 +385,8 @@ bool QTorrentHandle::priv() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::firstFileSavePath() const {
|
QString QTorrentHandle::firstFileSavePath() const
|
||||||
|
{
|
||||||
Q_ASSERT(has_metadata());
|
Q_ASSERT(has_metadata());
|
||||||
QString fsave_path = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
|
QString fsave_path = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
|
||||||
if (fsave_path.isEmpty())
|
if (fsave_path.isEmpty())
|
||||||
|
@ -379,35 +411,40 @@ QString QTorrentHandle::root_path() const
|
||||||
return save_path();
|
return save_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::has_error() const {
|
bool QTorrentHandle::has_error() const
|
||||||
|
{
|
||||||
return has_error(status(0x0));
|
return has_error(status(0x0));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::error() const {
|
QString QTorrentHandle::error() const
|
||||||
|
{
|
||||||
return misc::toQString(status(0x0).error);
|
return misc::toQString(status(0x0).error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::downloading_pieces(bitfield &bf) const {
|
void QTorrentHandle::downloading_pieces(bitfield &bf) const
|
||||||
|
{
|
||||||
std::vector<partial_piece_info> queue;
|
std::vector<partial_piece_info> queue;
|
||||||
torrent_handle::get_download_queue(queue);
|
torrent_handle::get_download_queue(queue);
|
||||||
|
|
||||||
std::vector<partial_piece_info>::const_iterator it = queue.begin();
|
std::vector<partial_piece_info>::const_iterator it = queue.begin();
|
||||||
std::vector<partial_piece_info>::const_iterator itend = queue.end();
|
std::vector<partial_piece_info>::const_iterator itend = queue.end();
|
||||||
for ( ; it!= itend; ++it) {
|
for (; it!= itend; ++it)
|
||||||
bf.set_bit(it->piece_index);
|
bf.set_bit(it->piece_index);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::has_metadata() const {
|
bool QTorrentHandle::has_metadata() const
|
||||||
|
{
|
||||||
return status(0x0).has_metadata;
|
return status(0x0).has_metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::file_progress(std::vector<size_type>& fp) const {
|
void QTorrentHandle::file_progress(std::vector<size_type>& fp) const
|
||||||
|
{
|
||||||
torrent_handle::file_progress(fp, torrent_handle::piece_granularity);
|
torrent_handle::file_progress(fp, torrent_handle::piece_granularity);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTorrentState QTorrentHandle::torrentState() const {
|
QTorrentState QTorrentHandle::torrentState() const
|
||||||
|
{
|
||||||
QTorrentState state = QTorrentState::Unknown;
|
QTorrentState state = QTorrentState::Unknown;
|
||||||
libtorrent::torrent_status s = status(torrent_handle::query_accurate_download_counters);
|
libtorrent::torrent_status s = status(torrent_handle::query_accurate_download_counters);
|
||||||
|
|
||||||
|
@ -456,13 +493,15 @@ qulonglong QTorrentHandle::eta() const
|
||||||
// Setters
|
// Setters
|
||||||
//
|
//
|
||||||
|
|
||||||
void QTorrentHandle::pause() const {
|
void QTorrentHandle::pause() const
|
||||||
|
{
|
||||||
torrent_handle::auto_managed(false);
|
torrent_handle::auto_managed(false);
|
||||||
torrent_handle::pause();
|
torrent_handle::pause();
|
||||||
torrent_handle::save_resume_data();
|
torrent_handle::save_resume_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::resume() const {
|
void QTorrentHandle::resume() const
|
||||||
|
{
|
||||||
if (has_error())
|
if (has_error())
|
||||||
torrent_handle::clear_error();
|
torrent_handle::clear_error();
|
||||||
|
|
||||||
|
@ -480,27 +519,30 @@ void QTorrentHandle::resume() const {
|
||||||
}
|
}
|
||||||
torrent_handle::auto_managed(true);
|
torrent_handle::auto_managed(true);
|
||||||
torrent_handle::resume();
|
torrent_handle::resume();
|
||||||
if (has_persistant_error && temp_path_enabled) {
|
if (has_persistant_error && temp_path_enabled)
|
||||||
// Force recheck
|
// Force recheck
|
||||||
torrent_handle::force_recheck();
|
torrent_handle::force_recheck();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::remove_url_seed(const QString& seed) const {
|
void QTorrentHandle::remove_url_seed(const QString& seed) const
|
||||||
|
{
|
||||||
torrent_handle::remove_url_seed(seed.toStdString());
|
torrent_handle::remove_url_seed(seed.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::add_url_seed(const QString& seed) const {
|
void QTorrentHandle::add_url_seed(const QString& seed) const
|
||||||
|
{
|
||||||
const std::string str_seed = seed.toStdString();
|
const std::string str_seed = seed.toStdString();
|
||||||
qDebug("calling torrent_handle::add_url_seed(%s)", str_seed.c_str());
|
qDebug("calling torrent_handle::add_url_seed(%s)", str_seed.c_str());
|
||||||
torrent_handle::add_url_seed(str_seed);
|
torrent_handle::add_url_seed(str_seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::set_tracker_login(const QString& username, const QString& password) const {
|
void QTorrentHandle::set_tracker_login(const QString& username, const QString& password) const
|
||||||
|
{
|
||||||
torrent_handle::set_tracker_login(std::string(username.toLocal8Bit().constData()), std::string(password.toLocal8Bit().constData()));
|
torrent_handle::set_tracker_login(std::string(username.toLocal8Bit().constData()), std::string(password.toLocal8Bit().constData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::move_storage(const QString& new_path) const {
|
void QTorrentHandle::move_storage(const QString& new_path) const
|
||||||
|
{
|
||||||
QString hashstr = hash();
|
QString hashstr = hash();
|
||||||
|
|
||||||
if (TorrentTempData::isMoveInProgress(hashstr)) {
|
if (TorrentTempData::isMoveInProgress(hashstr)) {
|
||||||
|
@ -525,7 +567,8 @@ void QTorrentHandle::move_storage(const QString& new_path) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::save_torrent_file(const QString& path) const {
|
bool QTorrentHandle::save_torrent_file(const QString& path) const
|
||||||
|
{
|
||||||
if (!has_metadata()) return false;
|
if (!has_metadata()) return false;
|
||||||
|
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
|
@ -553,7 +596,8 @@ bool QTorrentHandle::save_torrent_file(const QString& path) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::file_priority(int index, int priority) const {
|
void QTorrentHandle::file_priority(int index, int priority) const
|
||||||
|
{
|
||||||
vector<int> priorities = torrent_handle::file_priorities();
|
vector<int> priorities = torrent_handle::file_priorities();
|
||||||
if (priorities[index] != priority) {
|
if (priorities[index] != priority) {
|
||||||
priorities[index] = priority;
|
priorities[index] = priority;
|
||||||
|
@ -561,7 +605,8 @@ void QTorrentHandle::file_priority(int index, int priority) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
void QTorrentHandle::prioritize_files(const vector<int> &files) const
|
||||||
|
{
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
torrent_info const& info = torrent_handle::get_torrent_info();
|
torrent_info const& info = torrent_handle::get_torrent_info();
|
||||||
#else
|
#else
|
||||||
|
@ -585,8 +630,8 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
QString parent_abspath = fsutils::branchPath(old_abspath);
|
QString parent_abspath = fsutils::branchPath(old_abspath);
|
||||||
// Make sure the file does not already exists
|
// Make sure the file does not already exists
|
||||||
if (QDir(parent_abspath).dirName() != ".unwanted") {
|
if (QDir(parent_abspath).dirName() != ".unwanted") {
|
||||||
QString unwanted_abspath = parent_abspath+"/.unwanted";
|
QString unwanted_abspath = parent_abspath + "/.unwanted";
|
||||||
QString new_abspath = unwanted_abspath+"/"+fsutils::fileName(filepath);
|
QString new_abspath = unwanted_abspath + "/" + fsutils::fileName(filepath);
|
||||||
qDebug() << "Unwanted path is" << unwanted_abspath;
|
qDebug() << "Unwanted path is" << unwanted_abspath;
|
||||||
if (QFile::exists(new_abspath)) {
|
if (QFile::exists(new_abspath)) {
|
||||||
qWarning() << "File" << new_abspath << "already exists at destination.";
|
qWarning() << "File" << new_abspath << "already exists at destination.";
|
||||||
|
@ -600,7 +645,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
qDebug() << "Hiding folder (Windows)";
|
qDebug() << "Hiding folder (Windows)";
|
||||||
wstring win_path = fsutils::toNativePath(unwanted_abspath).toStdWString();
|
wstring win_path = fsutils::toNativePath(unwanted_abspath).toStdWString();
|
||||||
DWORD dwAttrs = GetFileAttributesW(win_path.c_str());
|
DWORD dwAttrs = GetFileAttributesW(win_path.c_str());
|
||||||
bool ret = SetFileAttributesW(win_path.c_str(), dwAttrs|FILE_ATTRIBUTE_HIDDEN);
|
bool ret = SetFileAttributesW(win_path.c_str(), dwAttrs | FILE_ATTRIBUTE_HIDDEN);
|
||||||
Q_ASSERT(ret != 0); Q_UNUSED(ret);
|
Q_ASSERT(ret != 0); Q_UNUSED(ret);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -609,7 +654,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
QString parent_path = fsutils::branchPath(filepath);
|
QString parent_path = fsutils::branchPath(filepath);
|
||||||
if (!parent_path.isEmpty() && !parent_path.endsWith("/"))
|
if (!parent_path.isEmpty() && !parent_path.endsWith("/"))
|
||||||
parent_path += "/";
|
parent_path += "/";
|
||||||
rename_file(i, parent_path+".unwanted/"+fsutils::fileName(filepath));
|
rename_file(i, parent_path + ".unwanted/" + fsutils::fileName(filepath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Move wanted files back to their original folder
|
// Move wanted files back to their original folder
|
||||||
|
@ -643,7 +688,8 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
|
void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const
|
||||||
|
{
|
||||||
// Determine the priority to set
|
// Determine the priority to set
|
||||||
int prio = b ? 7 : torrent_handle::file_priority(file_index);
|
int prio = b ? 7 : torrent_handle::file_priority(file_index);
|
||||||
|
|
||||||
|
@ -658,7 +704,8 @@ void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
|
||||||
piece_priority(extremities.second, prio);
|
piece_priority(extremities.second, prio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::prioritize_first_last_piece(bool b) const {
|
void QTorrentHandle::prioritize_first_last_piece(bool b) const
|
||||||
|
{
|
||||||
if (!has_metadata()) return;
|
if (!has_metadata()) return;
|
||||||
// Download first and last pieces first for all media files in the torrent
|
// Download first and last pieces first for all media files in the torrent
|
||||||
const uint nbfiles = num_files();
|
const uint nbfiles = num_files();
|
||||||
|
@ -672,7 +719,8 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTorrentHandle::rename_file(int index, const QString& name) const {
|
void QTorrentHandle::rename_file(int index, const QString& name) const
|
||||||
|
{
|
||||||
qDebug() << Q_FUNC_INFO << index << name;
|
qDebug() << Q_FUNC_INFO << index << name;
|
||||||
torrent_handle::rename_file(index, std::string(fsutils::toNativePath(name).toUtf8().constData()));
|
torrent_handle::rename_file(index, std::string(fsutils::toNativePath(name).toUtf8().constData()));
|
||||||
}
|
}
|
||||||
|
@ -681,39 +729,47 @@ void QTorrentHandle::rename_file(int index, const QString& name) const {
|
||||||
// Operators
|
// Operators
|
||||||
//
|
//
|
||||||
|
|
||||||
bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const {
|
bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const
|
||||||
|
{
|
||||||
return info_hash() == new_h.info_hash();
|
return info_hash() == new_h.info_hash();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_paused(const libtorrent::torrent_status &status) {
|
bool QTorrentHandle::is_paused(const libtorrent::torrent_status &status)
|
||||||
|
{
|
||||||
return status.paused && !status.auto_managed;
|
return status.paused && !status.auto_managed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QTorrentHandle::queue_position(const libtorrent::torrent_status &status) {
|
int QTorrentHandle::queue_position(const libtorrent::torrent_status &status)
|
||||||
|
{
|
||||||
if (status.queue_position < 0)
|
if (status.queue_position < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return status.queue_position+1;
|
return status.queue_position + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_queued(const libtorrent::torrent_status &status) {
|
bool QTorrentHandle::is_queued(const libtorrent::torrent_status &status)
|
||||||
|
{
|
||||||
return status.paused && status.auto_managed;
|
return status.paused && status.auto_managed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_seed(const libtorrent::torrent_status &status) {
|
bool QTorrentHandle::is_seed(const libtorrent::torrent_status &status)
|
||||||
|
{
|
||||||
return status.state == torrent_status::finished
|
return status.state == torrent_status::finished
|
||||||
|| status.state == torrent_status::seeding;
|
|| status.state == torrent_status::seeding;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::is_checking(const libtorrent::torrent_status &status) {
|
bool QTorrentHandle::is_checking(const libtorrent::torrent_status &status)
|
||||||
|
{
|
||||||
return status.state == torrent_status::checking_files
|
return status.state == torrent_status::checking_files
|
||||||
|| status.state == torrent_status::checking_resume_data;
|
|| status.state == torrent_status::checking_resume_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::has_error(const libtorrent::torrent_status &status) {
|
bool QTorrentHandle::has_error(const libtorrent::torrent_status &status)
|
||||||
|
{
|
||||||
return status.paused && !status.error.empty();
|
return status.paused && !status.error.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
float QTorrentHandle::progress(const libtorrent::torrent_status &status) {
|
float QTorrentHandle::progress(const libtorrent::torrent_status &status)
|
||||||
|
{
|
||||||
if (!status.total_wanted)
|
if (!status.total_wanted)
|
||||||
return 0.;
|
return 0.;
|
||||||
if (status.total_wanted_done == status.total_wanted)
|
if (status.total_wanted_done == status.total_wanted)
|
||||||
|
@ -723,7 +779,8 @@ float QTorrentHandle::progress(const libtorrent::torrent_status &status) {
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::filepath_at(const libtorrent::torrent_info &info, unsigned int index) {
|
QString QTorrentHandle::filepath_at(const libtorrent::torrent_info &info, unsigned int index)
|
||||||
|
{
|
||||||
return fsutils::fromNativePath(misc::toQStringU(info.files().file_path(index)));
|
return fsutils::fromNativePath(misc::toQStringU(info.files().file_path(index)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@ QT_END_NAMESPACE
|
||||||
class QTorrentState
|
class QTorrentState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
Unknown = -1,
|
Unknown = -1,
|
||||||
|
|
||||||
Error,
|
Error,
|
||||||
|
@ -71,7 +72,8 @@ private:
|
||||||
|
|
||||||
// A wrapper for torrent_handle in libtorrent
|
// A wrapper for torrent_handle in libtorrent
|
||||||
// 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:
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,8 @@
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession *_BTSession):
|
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession *_BTSession):
|
||||||
QTreeView(parent), BTSession(_BTSession), main_window(main_window) {
|
QTreeView(parent), BTSession(_BTSession), main_window(main_window)
|
||||||
|
{
|
||||||
|
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
// Load settings
|
// Load settings
|
||||||
|
@ -125,7 +126,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window,
|
||||||
|
|
||||||
//Ensure that at least one column is visible at all times
|
//Ensure that at least one column is visible at all times
|
||||||
bool atLeastOne = false;
|
bool atLeastOne = false;
|
||||||
for (unsigned int i=0; i<TorrentModelItem::NB_COLUMNS; i++) {
|
for (unsigned int i = 0; i<TorrentModelItem::NB_COLUMNS; i++) {
|
||||||
if (!isColumnHidden(i)) {
|
if (!isColumnHidden(i)) {
|
||||||
atLeastOne = true;
|
atLeastOne = true;
|
||||||
break;
|
break;
|
||||||
|
@ -137,7 +138,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window,
|
||||||
//When adding/removing columns between versions some may
|
//When adding/removing columns between versions some may
|
||||||
//end up being size 0 when the new version is launched with
|
//end up being size 0 when the new version is launched with
|
||||||
//a conf file from the previous version.
|
//a conf file from the previous version.
|
||||||
for (unsigned int i=0; i<TorrentModelItem::NB_COLUMNS; i++)
|
for (unsigned int i = 0; i<TorrentModelItem::NB_COLUMNS; i++)
|
||||||
if (!columnWidth(i))
|
if (!columnWidth(i))
|
||||||
resizeColumnToContents(i);
|
resizeColumnToContents(i);
|
||||||
|
|
||||||
|
@ -145,15 +146,16 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window,
|
||||||
|
|
||||||
// Listen for list events
|
// Listen for list events
|
||||||
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(torrentDoubleClicked(QModelIndex)));
|
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(torrentDoubleClicked(QModelIndex)));
|
||||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&)));
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayListMenu(const QPoint &)));
|
||||||
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&)));
|
connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayDLHoSMenu(const QPoint &)));
|
||||||
|
|
||||||
editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(renameSelectedTorrent()), 0, Qt::WidgetShortcut);
|
editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(renameSelectedTorrent()), 0, Qt::WidgetShortcut);
|
||||||
deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTorrents()), 0, Qt::WidgetShortcut);
|
deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTorrents()), 0, Qt::WidgetShortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
TransferListWidget::~TransferListWidget() {
|
TransferListWidget::~TransferListWidget()
|
||||||
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "ENTER";
|
qDebug() << Q_FUNC_INFO << "ENTER";
|
||||||
// Save settings
|
// Save settings
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
@ -166,59 +168,65 @@ TransferListWidget::~TransferListWidget() {
|
||||||
qDebug() << Q_FUNC_INFO << "EXIT";
|
qDebug() << Q_FUNC_INFO << "EXIT";
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentModel* TransferListWidget::getSourceModel() const {
|
TorrentModel* TransferListWidget::getSourceModel() const
|
||||||
|
{
|
||||||
return listModel;
|
return listModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::previewFile(QString filePath) {
|
void TransferListWidget::previewFile(QString filePath)
|
||||||
|
{
|
||||||
openUrl(filePath);
|
openUrl(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::setRefreshInterval(int t) {
|
void TransferListWidget::setRefreshInterval(int t)
|
||||||
|
{
|
||||||
qDebug("Settings transfer list refresh interval to %dms", t);
|
qDebug("Settings transfer list refresh interval to %dms", t);
|
||||||
listModel->setRefreshInterval(t);
|
listModel->setRefreshInterval(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TransferListWidget::getRowFromHash(QString hash) const {
|
int TransferListWidget::getRowFromHash(QString hash) const
|
||||||
|
{
|
||||||
return listModel->torrentRow(hash);
|
return listModel->torrentRow(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QString TransferListWidget::getHashFromRow(int row) const {
|
inline QString TransferListWidget::getHashFromRow(int row) const
|
||||||
|
{
|
||||||
return listModel->torrentHash(row);
|
return listModel->torrentHash(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const {
|
inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const
|
||||||
|
{
|
||||||
Q_ASSERT(index.isValid());
|
Q_ASSERT(index.isValid());
|
||||||
if (index.model() == nameFilterModel)
|
if (index.model() == nameFilterModel)
|
||||||
return nameFilterModel->mapToSource(index);
|
return nameFilterModel->mapToSource(index);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) const {
|
inline QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) const
|
||||||
|
{
|
||||||
Q_ASSERT(index.isValid());
|
Q_ASSERT(index.isValid());
|
||||||
Q_ASSERT(index.model() == nameFilterModel);
|
Q_ASSERT(index.model() == nameFilterModel);
|
||||||
return nameFilterModel->mapFromSource(index);
|
return nameFilterModel->mapFromSource(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
|
void TransferListWidget::torrentDoubleClicked(const QModelIndex& index)
|
||||||
|
{
|
||||||
const int row = mapToSource(index).row();
|
const int row = mapToSource(index).row();
|
||||||
const QString hash = getHashFromRow(row);
|
const QString hash = getHashFromRow(row);
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if (!h.is_valid()) return;
|
if (!h.is_valid()) return;
|
||||||
int action;
|
int action;
|
||||||
if (h.is_seed()) {
|
if (h.is_seed())
|
||||||
action = Preferences::instance()->getActionOnDblClOnTorrentFn();
|
action = Preferences::instance()->getActionOnDblClOnTorrentFn();
|
||||||
} else {
|
else
|
||||||
action = Preferences::instance()->getActionOnDblClOnTorrentDl();
|
action = Preferences::instance()->getActionOnDblClOnTorrentDl();
|
||||||
}
|
|
||||||
|
|
||||||
switch(action) {
|
switch(action) {
|
||||||
case TOGGLE_PAUSE:
|
case TOGGLE_PAUSE:
|
||||||
if (h.is_paused()) {
|
if (h.is_paused())
|
||||||
h.resume();
|
h.resume();
|
||||||
} else {
|
else
|
||||||
h.pause();
|
h.pause();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case OPEN_DEST:
|
case OPEN_DEST:
|
||||||
const QString path = h.root_path();
|
const QString path = h.root_path();
|
||||||
|
@ -226,23 +234,24 @@ void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList TransferListWidget::getSelectedTorrentsHashes() const {
|
QStringList TransferListWidget::getSelectedTorrentsHashes() const
|
||||||
|
{
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||||
foreach (const QModelIndex &index, selectedIndexes) {
|
foreach (const QModelIndex &index, selectedIndexes)
|
||||||
hashes << getHashFromRow(mapToSource(index).row());
|
hashes << getHashFromRow(mapToSource(index).row());
|
||||||
}
|
|
||||||
return hashes;
|
return hashes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::setSelectedTorrentsLocation() {
|
void TransferListWidget::setSelectedTorrentsLocation()
|
||||||
|
{
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
if (hashes.isEmpty()) return;
|
if (hashes.isEmpty()) return;
|
||||||
QString dir;
|
QString dir;
|
||||||
const QDir saveDir(TorrentPersistentData::getSavePath(hashes.first()));
|
const QDir saveDir(TorrentPersistentData::getSavePath(hashes.first()));
|
||||||
qDebug("Old save path is %s", qPrintable(saveDir.absolutePath()));
|
qDebug("Old save path is %s", qPrintable(saveDir.absolutePath()));
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.absolutePath(),
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.absolutePath(),
|
||||||
QFileDialog::DontConfirmOverwrite|QFileDialog::ShowDirsOnly|QFileDialog::HideNameFilterDetails);
|
QFileDialog::DontConfirmOverwrite | QFileDialog::ShowDirsOnly | QFileDialog::HideNameFilterDetails);
|
||||||
if (!dir.isNull()) {
|
if (!dir.isNull()) {
|
||||||
qDebug("New path is %s", qPrintable(dir));
|
qDebug("New path is %s", qPrintable(dir));
|
||||||
// Check if savePath exists
|
// Check if savePath exists
|
||||||
|
@ -254,7 +263,8 @@ void TransferListWidget::setSelectedTorrentsLocation() {
|
||||||
if (!BTSession->useTemporaryFolder() || h.is_seed()) {
|
if (!BTSession->useTemporaryFolder() || h.is_seed()) {
|
||||||
if (!savePath.exists()) savePath.mkpath(savePath.absolutePath());
|
if (!savePath.exists()) savePath.mkpath(savePath.absolutePath());
|
||||||
h.move_storage(savePath.absolutePath());
|
h.move_storage(savePath.absolutePath());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
TorrentPersistentData::saveSavePath(h.hash(), savePath.absolutePath());
|
TorrentPersistentData::saveSavePath(h.hash(), savePath.absolutePath());
|
||||||
main_window->getProperties()->updateSavePath(h);
|
main_window->getProperties()->updateSavePath(h);
|
||||||
}
|
}
|
||||||
|
@ -262,43 +272,44 @@ void TransferListWidget::setSelectedTorrentsLocation() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::startSelectedTorrents() {
|
void TransferListWidget::startSelectedTorrents()
|
||||||
|
{
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes)
|
||||||
BTSession->resumeTorrent(hash);
|
BTSession->resumeTorrent(hash);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::startVisibleTorrents() {
|
void TransferListWidget::startVisibleTorrents()
|
||||||
|
{
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
for (int i=0; i<nameFilterModel->rowCount(); ++i) {
|
for (int i = 0; i<nameFilterModel->rowCount(); ++i) {
|
||||||
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
||||||
hashes << getHashFromRow(row);
|
hashes << getHashFromRow(row);
|
||||||
}
|
}
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes)
|
||||||
BTSession->resumeTorrent(hash);
|
BTSession->resumeTorrent(hash);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::pauseSelectedTorrents() {
|
void TransferListWidget::pauseSelectedTorrents()
|
||||||
|
{
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes)
|
||||||
BTSession->pauseTorrent(hash);
|
BTSession->pauseTorrent(hash);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::pauseVisibleTorrents() {
|
void TransferListWidget::pauseVisibleTorrents()
|
||||||
|
{
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
for (int i=0; i<nameFilterModel->rowCount(); ++i) {
|
for (int i = 0; i<nameFilterModel->rowCount(); ++i) {
|
||||||
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
||||||
hashes << getHashFromRow(row);
|
hashes << getHashFromRow(row);
|
||||||
}
|
}
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes)
|
||||||
BTSession->pauseTorrent(hash);
|
BTSession->pauseTorrent(hash);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::deleteSelectedTorrents() {
|
void TransferListWidget::deleteSelectedTorrents()
|
||||||
|
{
|
||||||
if (main_window->getCurrentTabWidget() != this) return;
|
if (main_window->getCurrentTabWidget() != this) return;
|
||||||
const QStringList& hashes = getSelectedTorrentsHashes();
|
const QStringList& hashes = getSelectedTorrentsHashes();
|
||||||
if (hashes.empty()) return;
|
if (hashes.empty()) return;
|
||||||
|
@ -307,12 +318,12 @@ void TransferListWidget::deleteSelectedTorrents() {
|
||||||
if (Preferences::instance()->confirmTorrentDeletion() &&
|
if (Preferences::instance()->confirmTorrentDeletion() &&
|
||||||
!DeletionConfirmationDlg::askForDeletionConfirmation(delete_local_files, hashes.size(), torrent.name()))
|
!DeletionConfirmationDlg::askForDeletionConfirmation(delete_local_files, hashes.size(), torrent.name()))
|
||||||
return;
|
return;
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes)
|
||||||
BTSession->deleteTorrent(hash, delete_local_files);
|
BTSession->deleteTorrent(hash, delete_local_files);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::deleteVisibleTorrents() {
|
void TransferListWidget::deleteVisibleTorrents()
|
||||||
|
{
|
||||||
if (nameFilterModel->rowCount() <= 0) return;
|
if (nameFilterModel->rowCount() <= 0) return;
|
||||||
QTorrentHandle torrent = BTSession->getTorrentHandle(getHashFromRow(0));
|
QTorrentHandle torrent = BTSession->getTorrentHandle(getHashFromRow(0));
|
||||||
bool delete_local_files = false;
|
bool delete_local_files = false;
|
||||||
|
@ -320,16 +331,16 @@ void TransferListWidget::deleteVisibleTorrents() {
|
||||||
!DeletionConfirmationDlg::askForDeletionConfirmation(delete_local_files, nameFilterModel->rowCount(), torrent.name()))
|
!DeletionConfirmationDlg::askForDeletionConfirmation(delete_local_files, nameFilterModel->rowCount(), torrent.name()))
|
||||||
return;
|
return;
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
for (int i=0; i<nameFilterModel->rowCount(); ++i) {
|
for (int i = 0; i<nameFilterModel->rowCount(); ++i) {
|
||||||
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
||||||
hashes << getHashFromRow(row);
|
hashes << getHashFromRow(row);
|
||||||
}
|
}
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes)
|
||||||
BTSession->deleteTorrent(hash, delete_local_files);
|
BTSession->deleteTorrent(hash, delete_local_files);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::increasePrioSelectedTorrents() {
|
void TransferListWidget::increasePrioSelectedTorrents()
|
||||||
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
if (main_window->getCurrentTabWidget() != this) return;
|
if (main_window->getCurrentTabWidget() != this) return;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
|
@ -338,9 +349,8 @@ void TransferListWidget::increasePrioSelectedTorrents() {
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
try {
|
try {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if (!h.is_seed()) {
|
if (!h.is_seed())
|
||||||
torrent_queue.push(qMakePair(h.queue_position(), h));
|
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||||
}
|
|
||||||
}catch(invalid_handle&) {}
|
}catch(invalid_handle&) {}
|
||||||
}
|
}
|
||||||
// Increase torrents priority (starting with the ones with highest priority)
|
// Increase torrents priority (starting with the ones with highest priority)
|
||||||
|
@ -353,7 +363,8 @@ void TransferListWidget::increasePrioSelectedTorrents() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::decreasePrioSelectedTorrents() {
|
void TransferListWidget::decreasePrioSelectedTorrents()
|
||||||
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
if (main_window->getCurrentTabWidget() != this) return;
|
if (main_window->getCurrentTabWidget() != this) return;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
|
@ -362,9 +373,8 @@ void TransferListWidget::decreasePrioSelectedTorrents() {
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
try {
|
try {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if (!h.is_seed()) {
|
if (!h.is_seed())
|
||||||
torrent_queue.push(qMakePair(h.queue_position(), h));
|
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||||
}
|
|
||||||
}catch(invalid_handle&) {}
|
}catch(invalid_handle&) {}
|
||||||
}
|
}
|
||||||
// Decrease torrents priority (starting with the ones with lowest priority)
|
// Decrease torrents priority (starting with the ones with lowest priority)
|
||||||
|
@ -377,29 +387,30 @@ void TransferListWidget::decreasePrioSelectedTorrents() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::topPrioSelectedTorrents() {
|
void TransferListWidget::topPrioSelectedTorrents()
|
||||||
|
{
|
||||||
if (main_window->getCurrentTabWidget() != this) return;
|
if (main_window->getCurrentTabWidget() != this) return;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if (h.is_valid() && !h.is_seed()) {
|
if (h.is_valid() && !h.is_seed())
|
||||||
h.queue_position_top();
|
h.queue_position_top();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::bottomPrioSelectedTorrents() {
|
void TransferListWidget::bottomPrioSelectedTorrents()
|
||||||
|
{
|
||||||
if (main_window->getCurrentTabWidget() != this) return;
|
if (main_window->getCurrentTabWidget() != this) return;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if (h.is_valid() && !h.is_seed()) {
|
if (h.is_valid() && !h.is_seed())
|
||||||
h.queue_position_bottom();
|
h.queue_position_bottom();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::copySelectedMagnetURIs() const {
|
void TransferListWidget::copySelectedMagnetURIs() const
|
||||||
|
{
|
||||||
QStringList magnet_uris;
|
QStringList magnet_uris;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
|
@ -410,12 +421,14 @@ void TransferListWidget::copySelectedMagnetURIs() const {
|
||||||
qApp->clipboard()->setText(magnet_uris.join("\n"));
|
qApp->clipboard()->setText(magnet_uris.join("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::hidePriorityColumn(bool hide) {
|
void TransferListWidget::hidePriorityColumn(bool hide)
|
||||||
|
{
|
||||||
qDebug("hidePriorityColumn(%d)", hide);
|
qDebug("hidePriorityColumn(%d)", hide);
|
||||||
setColumnHidden(TorrentModelItem::TR_PRIORITY, hide);
|
setColumnHidden(TorrentModelItem::TR_PRIORITY, hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::openSelectedTorrentsFolder() const {
|
void TransferListWidget::openSelectedTorrentsFolder() const
|
||||||
|
{
|
||||||
QSet<QString> pathsList;
|
QSet<QString> pathsList;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
|
@ -431,17 +444,18 @@ void TransferListWidget::openSelectedTorrentsFolder() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::previewSelectedTorrents() {
|
void TransferListWidget::previewSelectedTorrents()
|
||||||
|
{
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if (h.is_valid() && h.has_metadata()) {
|
if (h.is_valid() && h.has_metadata())
|
||||||
new PreviewSelect(this, h);
|
new PreviewSelect(this, h);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::setDlLimitSelectedTorrents() {
|
void TransferListWidget::setDlLimitSelectedTorrents()
|
||||||
|
{
|
||||||
QList<QTorrentHandle> selected_torrents;
|
QList<QTorrentHandle> selected_torrents;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
bool all_same_limit = true;
|
bool all_same_limit = true;
|
||||||
|
@ -451,30 +465,30 @@ void TransferListWidget::setDlLimitSelectedTorrents() {
|
||||||
if (h.is_valid() && !h.is_seed()) {
|
if (h.is_valid() && !h.is_seed()) {
|
||||||
selected_torrents << h;
|
selected_torrents << h;
|
||||||
// Determine current limit for selected torrents
|
// Determine current limit for selected torrents
|
||||||
if (first) {
|
if (first)
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
else
|
||||||
if (all_same_limit && h.download_limit() != selected_torrents.first().download_limit())
|
if (all_same_limit && h.download_limit() != selected_torrents.first().download_limit())
|
||||||
all_same_limit = false;
|
all_same_limit = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (selected_torrents.empty()) return;
|
if (selected_torrents.empty()) return;
|
||||||
|
|
||||||
bool ok=false;
|
bool ok = false;
|
||||||
int default_limit = -1;
|
int default_limit = -1;
|
||||||
if (all_same_limit)
|
if (all_same_limit)
|
||||||
default_limit = selected_torrents.first().download_limit();
|
default_limit = selected_torrents.first().download_limit();
|
||||||
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit, Preferences::instance()->getGlobalDownloadLimit()*1024.);
|
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit, Preferences::instance()->getGlobalDownloadLimit() * 1024.);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
foreach (const QTorrentHandle &h, selected_torrents) {
|
foreach (const QTorrentHandle &h, selected_torrents) {
|
||||||
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), qPrintable(h.hash()));
|
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit / 1024.), qPrintable(h.hash()));
|
||||||
BTSession->setDownloadLimit(h.hash(), new_limit);
|
BTSession->setDownloadLimit(h.hash(), new_limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::setUpLimitSelectedTorrents() {
|
void TransferListWidget::setUpLimitSelectedTorrents()
|
||||||
|
{
|
||||||
QList<QTorrentHandle> selected_torrents;
|
QList<QTorrentHandle> selected_torrents;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
bool all_same_limit = true;
|
bool all_same_limit = true;
|
||||||
|
@ -484,30 +498,30 @@ void TransferListWidget::setUpLimitSelectedTorrents() {
|
||||||
if (h.is_valid()) {
|
if (h.is_valid()) {
|
||||||
selected_torrents << h;
|
selected_torrents << h;
|
||||||
// Determine current limit for selected torrents
|
// Determine current limit for selected torrents
|
||||||
if (first) {
|
if (first)
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
else
|
||||||
if (all_same_limit && h.upload_limit() != selected_torrents.first().upload_limit())
|
if (all_same_limit && h.upload_limit() != selected_torrents.first().upload_limit())
|
||||||
all_same_limit = false;
|
all_same_limit = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (selected_torrents.empty()) return;
|
if (selected_torrents.empty()) return;
|
||||||
|
|
||||||
bool ok=false;
|
bool ok = false;
|
||||||
int default_limit = -1;
|
int default_limit = -1;
|
||||||
if (all_same_limit)
|
if (all_same_limit)
|
||||||
default_limit = selected_torrents.first().upload_limit();
|
default_limit = selected_torrents.first().upload_limit();
|
||||||
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit, Preferences::instance()->getGlobalUploadLimit()*1024.);
|
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit, Preferences::instance()->getGlobalUploadLimit() * 1024.);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
foreach (const QTorrentHandle &h, selected_torrents) {
|
foreach (const QTorrentHandle &h, selected_torrents) {
|
||||||
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), qPrintable(h.hash()));
|
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit / 1024.), qPrintable(h.hash()));
|
||||||
BTSession->setUploadLimit(h.hash(), new_limit);
|
BTSession->setUploadLimit(h.hash(), new_limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::setMaxRatioSelectedTorrents() {
|
void TransferListWidget::setMaxRatioSelectedTorrents()
|
||||||
|
{
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
if (hashes.isEmpty())
|
if (hashes.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -515,7 +529,8 @@ void TransferListWidget::setMaxRatioSelectedTorrents() {
|
||||||
qreal currentMaxRatio;
|
qreal currentMaxRatio;
|
||||||
if (hashes.count() == 1) {
|
if (hashes.count() == 1) {
|
||||||
currentMaxRatio = BTSession->getMaxRatioPerTorrent(hashes.first(), &useGlobalValue);
|
currentMaxRatio = BTSession->getMaxRatioPerTorrent(hashes.first(), &useGlobalValue);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
useGlobalValue = true;
|
useGlobalValue = true;
|
||||||
currentMaxRatio = BTSession->getGlobalMaxRatio();
|
currentMaxRatio = BTSession->getGlobalMaxRatio();
|
||||||
}
|
}
|
||||||
|
@ -530,22 +545,23 @@ void TransferListWidget::setMaxRatioSelectedTorrents() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::recheckSelectedTorrents() {
|
void TransferListWidget::recheckSelectedTorrents()
|
||||||
QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Recheck confirmation"), tr("Are you sure you want to recheck the selected torrent(s)?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
|
{
|
||||||
|
QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Recheck confirmation"), tr("Are you sure you want to recheck the selected torrent(s)?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||||
if (ret != QMessageBox::Yes)
|
if (ret != QMessageBox::Yes)
|
||||||
return;
|
return;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes)
|
||||||
BTSession->recheckTorrent(hash);
|
BTSession->recheckTorrent(hash);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide/show columns menu
|
// hide/show columns menu
|
||||||
void TransferListWidget::displayDLHoSMenu(const QPoint&) {
|
void TransferListWidget::displayDLHoSMenu(const QPoint&)
|
||||||
|
{
|
||||||
QMenu hideshowColumn(this);
|
QMenu hideshowColumn(this);
|
||||||
hideshowColumn.setTitle(tr("Column visibility"));
|
hideshowColumn.setTitle(tr("Column visibility"));
|
||||||
QList<QAction*> actions;
|
QList<QAction*> actions;
|
||||||
for (int i=0; i < listModel->columnCount(); ++i) {
|
for (int i = 0; i < listModel->columnCount(); ++i) {
|
||||||
if (!BTSession->isQueueingEnabled() && i == TorrentModelItem::TR_PRIORITY) {
|
if (!BTSession->isQueueingEnabled() && i == TorrentModelItem::TR_PRIORITY) {
|
||||||
actions.append(0);
|
actions.append(0);
|
||||||
continue;
|
continue;
|
||||||
|
@ -556,7 +572,7 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&) {
|
||||||
actions.append(myAct);
|
actions.append(myAct);
|
||||||
}
|
}
|
||||||
int visibleCols = 0;
|
int visibleCols = 0;
|
||||||
for (unsigned int i=0; i<TorrentModelItem::NB_COLUMNS; i++) {
|
for (unsigned int i = 0; i<TorrentModelItem::NB_COLUMNS; i++) {
|
||||||
if (!isColumnHidden(i))
|
if (!isColumnHidden(i))
|
||||||
visibleCols++;
|
visibleCols++;
|
||||||
|
|
||||||
|
@ -579,17 +595,18 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const {
|
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const
|
||||||
|
{
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if (h.is_valid() && h.has_metadata()) {
|
if (h.is_valid() && h.has_metadata())
|
||||||
h.super_seeding(!h.status(0).super_seeding);
|
h.super_seeding(!h.status(0).super_seeding);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const {
|
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const
|
||||||
|
{
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
|
@ -602,17 +619,18 @@ void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const {
|
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const
|
||||||
|
{
|
||||||
QStringList hashes = getSelectedTorrentsHashes();
|
QStringList hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if (h.is_valid() && h.has_metadata()) {
|
if (h.is_valid() && h.has_metadata())
|
||||||
h.prioritize_first_last_piece(!h.first_last_piece_first());
|
h.prioritize_first_last_piece(!h.first_last_piece_first());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::askNewLabelForSelection() {
|
void TransferListWidget::askNewLabelForSelection()
|
||||||
|
{
|
||||||
// Ask for label
|
// Ask for label
|
||||||
bool ok;
|
bool ok;
|
||||||
bool invalid;
|
bool invalid;
|
||||||
|
@ -622,15 +640,17 @@ void TransferListWidget::askNewLabelForSelection() {
|
||||||
if (ok && !label.isEmpty()) {
|
if (ok && !label.isEmpty()) {
|
||||||
if (fsutils::isValidFileSystemName(label)) {
|
if (fsutils::isValidFileSystemName(label)) {
|
||||||
setSelectionLabel(label);
|
setSelectionLabel(label);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
|
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
|
||||||
invalid = true;
|
invalid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}while(invalid);
|
} while(invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TransferListWidget::openUrl(const QString &_path) const {
|
bool TransferListWidget::openUrl(const QString &_path) const
|
||||||
|
{
|
||||||
const QString path = fsutils::fromNativePath(_path);
|
const QString path = fsutils::fromNativePath(_path);
|
||||||
// Hack to access samba shares with QDesktopServices::openUrl
|
// Hack to access samba shares with QDesktopServices::openUrl
|
||||||
if (path.startsWith("//"))
|
if (path.startsWith("//"))
|
||||||
|
@ -639,7 +659,8 @@ bool TransferListWidget::openUrl(const QString &_path) const {
|
||||||
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::renameSelectedTorrent() {
|
void TransferListWidget::renameSelectedTorrent()
|
||||||
|
{
|
||||||
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||||
if (selectedIndexes.size() != 1) return;
|
if (selectedIndexes.size() != 1) return;
|
||||||
if (!selectedIndexes.first().isValid()) return;
|
if (!selectedIndexes.first().isValid()) return;
|
||||||
|
@ -657,7 +678,8 @@ void TransferListWidget::renameSelectedTorrent() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::setSelectionLabel(QString label) {
|
void TransferListWidget::setSelectionLabel(QString label)
|
||||||
|
{
|
||||||
const QStringList& hashes = getSelectedTorrentsHashes();
|
const QStringList& hashes = getSelectedTorrentsHashes();
|
||||||
foreach (const QString &hash, hashes) {
|
foreach (const QString &hash, hashes) {
|
||||||
Q_ASSERT(!hash.isEmpty());
|
Q_ASSERT(!hash.isEmpty());
|
||||||
|
@ -670,8 +692,9 @@ void TransferListWidget::setSelectionLabel(QString label) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::removeLabelFromRows(QString label) {
|
void TransferListWidget::removeLabelFromRows(QString label)
|
||||||
for (int i=0; i<listModel->rowCount(); ++i) {
|
{
|
||||||
|
for (int i = 0; i<listModel->rowCount(); ++i) {
|
||||||
if (listModel->data(listModel->index(i, TorrentModelItem::TR_LABEL)) == label) {
|
if (listModel->data(listModel->index(i, TorrentModelItem::TR_LABEL)) == label) {
|
||||||
const QString hash = getHashFromRow(i);
|
const QString hash = getHashFromRow(i);
|
||||||
listModel->setData(listModel->index(i, TorrentModelItem::TR_LABEL), "", Qt::DisplayRole);
|
listModel->setData(listModel->index(i, TorrentModelItem::TR_LABEL), "", Qt::DisplayRole);
|
||||||
|
@ -682,7 +705,8 @@ void TransferListWidget::removeLabelFromRows(QString label) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::displayListMenu(const QPoint&) {
|
void TransferListWidget::displayListMenu(const QPoint&)
|
||||||
|
{
|
||||||
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||||
if (selectedIndexes.size() == 0)
|
if (selectedIndexes.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -754,25 +778,23 @@ void TransferListWidget::displayListMenu(const QPoint&) {
|
||||||
if (first) {
|
if (first) {
|
||||||
sequential_download_mode = h.is_sequential_download();
|
sequential_download_mode = h.is_sequential_download();
|
||||||
prioritize_first_last = h.first_last_piece_first();
|
prioritize_first_last = h.first_last_piece_first();
|
||||||
} else {
|
}
|
||||||
if (sequential_download_mode != h.is_sequential_download()) {
|
else {
|
||||||
|
if (sequential_download_mode != h.is_sequential_download())
|
||||||
all_same_sequential_download_mode = false;
|
all_same_sequential_download_mode = false;
|
||||||
}
|
if (prioritize_first_last != h.first_last_piece_first())
|
||||||
if (prioritize_first_last != h.first_last_piece_first()) {
|
|
||||||
all_same_prio_firstlast = false;
|
all_same_prio_firstlast = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (!one_not_seed && all_same_super_seeding && h.has_metadata()) {
|
if (!one_not_seed && all_same_super_seeding && h.has_metadata()) {
|
||||||
if (first) {
|
if (first) {
|
||||||
super_seeding_mode = h.status(0).super_seeding;
|
super_seeding_mode = h.status(0).super_seeding;
|
||||||
} else {
|
}
|
||||||
if (super_seeding_mode != h.status(0).super_seeding) {
|
else if (super_seeding_mode != h.status(0).super_seeding)
|
||||||
all_same_super_seeding = false;
|
all_same_super_seeding = false;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (h.is_paused()) {
|
if (h.is_paused()) {
|
||||||
|
@ -780,15 +802,15 @@ void TransferListWidget::displayListMenu(const QPoint&) {
|
||||||
listMenu.addAction(&actionStart);
|
listMenu.addAction(&actionStart);
|
||||||
has_start = true;
|
has_start = true;
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
if (!has_pause) {
|
if (!has_pause) {
|
||||||
listMenu.addAction(&actionPause);
|
listMenu.addAction(&actionPause);
|
||||||
has_pause = true;
|
has_pause = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (h.has_metadata() && BTSession->isFilePreviewPossible(hash) && !has_preview) {
|
if (h.has_metadata() && BTSession->isFilePreviewPossible(hash) && !has_preview)
|
||||||
has_preview = true;
|
has_preview = true;
|
||||||
}
|
|
||||||
first = false;
|
first = false;
|
||||||
if (has_pause && has_start && has_preview && one_not_seed) break;
|
if (has_pause && has_start && has_preview && one_not_seed) break;
|
||||||
}
|
}
|
||||||
|
@ -806,9 +828,8 @@ void TransferListWidget::displayListMenu(const QPoint&) {
|
||||||
labelActions << labelMenu->addAction(IconProvider::instance()->getIcon("list-add"), tr("New...", "New label..."));
|
labelActions << labelMenu->addAction(IconProvider::instance()->getIcon("list-add"), tr("New...", "New label..."));
|
||||||
labelActions << labelMenu->addAction(IconProvider::instance()->getIcon("edit-clear"), tr("Reset", "Reset label"));
|
labelActions << labelMenu->addAction(IconProvider::instance()->getIcon("edit-clear"), tr("Reset", "Reset label"));
|
||||||
labelMenu->addSeparator();
|
labelMenu->addSeparator();
|
||||||
foreach (const QString &label, customLabels) {
|
foreach (const QString &label, customLabels)
|
||||||
labelActions << labelMenu->addAction(IconProvider::instance()->getIcon("inode-directory"), label);
|
labelActions << labelMenu->addAction(IconProvider::instance()->getIcon("inode-directory"), label);
|
||||||
}
|
|
||||||
listMenu.addSeparator();
|
listMenu.addSeparator();
|
||||||
if (one_not_seed)
|
if (one_not_seed)
|
||||||
listMenu.addAction(&actionSet_download_limit);
|
listMenu.addAction(&actionSet_download_limit);
|
||||||
|
@ -864,10 +885,11 @@ void TransferListWidget::displayListMenu(const QPoint&) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
// New Label
|
// New Label
|
||||||
askNewLabelForSelection();
|
askNewLabelForSelection();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
QString label = "";
|
QString label = "";
|
||||||
if (i > 1)
|
if (i > 1)
|
||||||
label = customLabels.at(i-2);
|
label = customLabels.at(i - 2);
|
||||||
// Update Label
|
// Update Label
|
||||||
setSelectionLabel(label);
|
setSelectionLabel(label);
|
||||||
}
|
}
|
||||||
|
@ -875,7 +897,8 @@ void TransferListWidget::displayListMenu(const QPoint&) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::currentChanged(const QModelIndex& current, const QModelIndex&) {
|
void TransferListWidget::currentChanged(const QModelIndex& current, const QModelIndex&)
|
||||||
|
{
|
||||||
qDebug("CURRENT CHANGED");
|
qDebug("CURRENT CHANGED");
|
||||||
QTorrentHandle h;
|
QTorrentHandle h;
|
||||||
if (current.isValid()) {
|
if (current.isValid()) {
|
||||||
|
@ -887,25 +910,29 @@ void TransferListWidget::currentChanged(const QModelIndex& current, const QModel
|
||||||
emit currentTorrentChanged(h);
|
emit currentTorrentChanged(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::applyLabelFilterAll() {
|
void TransferListWidget::applyLabelFilterAll()
|
||||||
|
{
|
||||||
nameFilterModel->disableLabelFilter();
|
nameFilterModel->disableLabelFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::applyLabelFilter(QString label) {
|
void TransferListWidget::applyLabelFilter(QString label)
|
||||||
|
{
|
||||||
qDebug("Applying Label filter: %s", qPrintable(label));
|
qDebug("Applying Label filter: %s", qPrintable(label));
|
||||||
nameFilterModel->setLabelFilter(label);
|
nameFilterModel->setLabelFilter(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::applyNameFilter(const QString& name) {
|
void TransferListWidget::applyNameFilter(const QString& name)
|
||||||
|
{
|
||||||
nameFilterModel->setFilterRegExp(QRegExp(QRegExp::escape(name), Qt::CaseInsensitive));
|
nameFilterModel->setFilterRegExp(QRegExp(QRegExp::escape(name), Qt::CaseInsensitive));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::applyStatusFilter(int f) {
|
void TransferListWidget::applyStatusFilter(int f)
|
||||||
|
{
|
||||||
nameFilterModel->setStatusFilter((TorrentFilter::TorrentFilter)f);
|
nameFilterModel->setStatusFilter((TorrentFilter::TorrentFilter)f);
|
||||||
// Select first item if nothing is selected
|
// Select first item if nothing is selected
|
||||||
if (selectionModel()->selectedRows(0).empty() && nameFilterModel->rowCount() > 0) {
|
if (selectionModel()->selectedRows(0).empty() && nameFilterModel->rowCount() > 0) {
|
||||||
qDebug("Nothing is selected, selecting first row: %s", qPrintable(nameFilterModel->index(0, TorrentModelItem::TR_NAME).data().toString()));
|
qDebug("Nothing is selected, selecting first row: %s", qPrintable(nameFilterModel->index(0, TorrentModelItem::TR_NAME).data().toString()));
|
||||||
selectionModel()->setCurrentIndex(nameFilterModel->index(0, TorrentModelItem::TR_NAME), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
|
selectionModel()->setCurrentIndex(nameFilterModel->index(0, TorrentModelItem::TR_NAME), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,9 +944,8 @@ void TransferListWidget::saveSettings()
|
||||||
bool TransferListWidget::loadSettings()
|
bool TransferListWidget::loadSettings()
|
||||||
{
|
{
|
||||||
bool ok = header()->restoreState(Preferences::instance()->getTransHeaderState());
|
bool ok = header()->restoreState(Preferences::instance()->getTransHeaderState());
|
||||||
if (!ok) {
|
if (!ok)
|
||||||
header()->resizeSection(0, 200); // Default
|
header()->resizeSection(0, 200); // Default
|
||||||
}
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ class QSortFilterProxyModel;
|
||||||
class QStandardItemModel;
|
class QStandardItemModel;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class TransferListWidget: public QTreeView {
|
class TransferListWidget: public QTreeView
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -245,7 +245,7 @@ QByteArray btjson::getTorrents(QString filter, QString label,
|
||||||
std::vector<torrent_handle>::const_iterator end = torrents.end();
|
std::vector<torrent_handle>::const_iterator end = torrents.end();
|
||||||
|
|
||||||
QTorrentFilter torrentFilter(filter, label);
|
QTorrentFilter torrentFilter(filter, label);
|
||||||
for( ; it != end; ++it) {
|
for(; it != end; ++it) {
|
||||||
QTorrentHandle torrent = QTorrentHandle(*it);
|
QTorrentHandle torrent = QTorrentHandle(*it);
|
||||||
|
|
||||||
if (torrentFilter.apply(torrent))
|
if (torrentFilter.apply(torrent))
|
||||||
|
@ -294,8 +294,9 @@ QByteArray btjson::getTrackersForTorrent(const QString& hash)
|
||||||
tracker_dict[KEY_TRACKER_URL] = tracker_url;
|
tracker_dict[KEY_TRACKER_URL] = tracker_url;
|
||||||
const TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
const TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||||
QString status;
|
QString status;
|
||||||
if (it->verified)
|
if (it->verified) {
|
||||||
status = tr("Working");
|
status = tr("Working");
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if (it->updating && it->fails == 0)
|
if (it->updating && it->fails == 0)
|
||||||
status = tr("Updating...");
|
status = tr("Updating...");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue