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);
|
||||
}
|
||||
|
||||
QTorrentHandle::QTorrentHandle(const torrent_handle& h): torrent_handle(h) {}
|
||||
QTorrentHandle::QTorrentHandle(const torrent_handle& h): torrent_handle(h)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Getters
|
||||
//
|
||||
|
||||
QString QTorrentHandle::hash() const {
|
||||
QString QTorrentHandle::hash() const
|
||||
{
|
||||
return misc::toQString(torrent_handle::info_hash());
|
||||
}
|
||||
|
||||
QString QTorrentHandle::name() const {
|
||||
QString QTorrentHandle::name() const
|
||||
{
|
||||
QString name = TorrentPersistentData::getName(hash());
|
||||
if (name.isEmpty()) {
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
|
@ -95,7 +99,8 @@ QString QTorrentHandle::name() const {
|
|||
return name;
|
||||
}
|
||||
|
||||
QString QTorrentHandle::creation_date() const {
|
||||
QString QTorrentHandle::creation_date() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
|
||||
#else
|
||||
|
@ -104,7 +109,8 @@ QString QTorrentHandle::creation_date() const {
|
|||
return t ? misc::toQString(*t) : "";
|
||||
}
|
||||
|
||||
qlonglong QTorrentHandle::creation_date_unix() const {
|
||||
qlonglong QTorrentHandle::creation_date_unix() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
|
||||
#else
|
||||
|
@ -113,19 +119,23 @@ qlonglong QTorrentHandle::creation_date_unix() const {
|
|||
return t ? *t : -1;
|
||||
}
|
||||
|
||||
QString QTorrentHandle::current_tracker() const {
|
||||
QString QTorrentHandle::current_tracker() const
|
||||
{
|
||||
return misc::toQString(status(0x0).current_tracker);
|
||||
}
|
||||
|
||||
bool QTorrentHandle::is_paused() const {
|
||||
bool QTorrentHandle::is_paused() const
|
||||
{
|
||||
return is_paused(status(0x0));
|
||||
}
|
||||
|
||||
bool QTorrentHandle::is_queued() const {
|
||||
bool QTorrentHandle::is_queued() const
|
||||
{
|
||||
return is_queued(status(0x0));
|
||||
}
|
||||
|
||||
size_type QTorrentHandle::total_size() const {
|
||||
size_type QTorrentHandle::total_size() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return torrent_handle::get_torrent_info().total_size();
|
||||
#else
|
||||
|
@ -133,7 +143,8 @@ size_type QTorrentHandle::total_size() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
size_type QTorrentHandle::piece_length() const {
|
||||
size_type QTorrentHandle::piece_length() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return torrent_handle::get_torrent_info().piece_length();
|
||||
#else
|
||||
|
@ -141,7 +152,8 @@ size_type QTorrentHandle::piece_length() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
int QTorrentHandle::num_pieces() const {
|
||||
int QTorrentHandle::num_pieces() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return torrent_handle::get_torrent_info().num_pieces();
|
||||
#else
|
||||
|
@ -149,7 +161,8 @@ int QTorrentHandle::num_pieces() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
bool QTorrentHandle::first_last_piece_first() const {
|
||||
bool QTorrentHandle::first_last_piece_first() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
torrent_info const* t = &get_torrent_info();
|
||||
#else
|
||||
|
@ -168,14 +181,14 @@ bool QTorrentHandle::first_last_piece_first() const {
|
|||
if (index >= t->num_files()) // No media file
|
||||
return false;
|
||||
|
||||
|
||||
QPair<int, int> extremities = get_file_extremity_pieces(*t, index);
|
||||
|
||||
return (torrent_handle::piece_priority(extremities.first) == 7)
|
||||
&& (torrent_handle::piece_priority(extremities.second) == 7);
|
||||
}
|
||||
|
||||
QString QTorrentHandle::save_path() const {
|
||||
QString QTorrentHandle::save_path() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::save_path()));
|
||||
#else
|
||||
|
@ -183,11 +196,13 @@ QString QTorrentHandle::save_path() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
QString QTorrentHandle::save_path_parsed() const {
|
||||
QString QTorrentHandle::save_path_parsed() const
|
||||
{
|
||||
QString p;
|
||||
if (has_metadata() && num_files() == 1) {
|
||||
p = firstFileSavePath();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
p = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
|
||||
if (p.isEmpty())
|
||||
p = save_path();
|
||||
|
@ -195,7 +210,8 @@ QString QTorrentHandle::save_path_parsed() const {
|
|||
return p;
|
||||
}
|
||||
|
||||
QStringList QTorrentHandle::url_seeds() const {
|
||||
QStringList QTorrentHandle::url_seeds() const
|
||||
{
|
||||
QStringList res;
|
||||
try {
|
||||
const std::set<std::string> existing_seeds = torrent_handle::url_seeds();
|
||||
|
@ -213,20 +229,22 @@ QStringList QTorrentHandle::url_seeds() const {
|
|||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
bool QTorrentHandle::has_filtered_pieces() const {
|
||||
bool QTorrentHandle::has_filtered_pieces() const
|
||||
{
|
||||
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)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int QTorrentHandle::num_files() const {
|
||||
int QTorrentHandle::num_files() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return torrent_handle::get_torrent_info().num_files();
|
||||
#else
|
||||
|
@ -234,7 +252,8 @@ int QTorrentHandle::num_files() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
QString QTorrentHandle::filename_at(unsigned int index) const {
|
||||
QString QTorrentHandle::filename_at(unsigned int index) const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
|
||||
#else
|
||||
|
@ -243,7 +262,8 @@ QString QTorrentHandle::filename_at(unsigned int index) const {
|
|||
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
|
||||
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
|
||||
return torrent_handle::get_torrent_info().files().file_size(index);
|
||||
|
@ -253,7 +273,8 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
QString QTorrentHandle::filepath_at(unsigned int index) const {
|
||||
QString QTorrentHandle::filepath_at(unsigned int index) const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return filepath_at(torrent_handle::get_torrent_info(), index);
|
||||
#else
|
||||
|
@ -261,7 +282,8 @@ QString QTorrentHandle::filepath_at(unsigned int index) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
|
||||
QString QTorrentHandle::orig_filepath_at(unsigned int index) const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index)));
|
||||
#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;
|
||||
}
|
||||
|
||||
QString QTorrentHandle::creator() const {
|
||||
QString QTorrentHandle::creator() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return misc::toQStringU(torrent_handle::get_torrent_info().creator());
|
||||
#else
|
||||
|
@ -282,7 +306,8 @@ QString QTorrentHandle::creator() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
QString QTorrentHandle::comment() const {
|
||||
QString QTorrentHandle::comment() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
return misc::toQStringU(torrent_handle::get_torrent_info().comment());
|
||||
#else
|
||||
|
@ -290,22 +315,24 @@ QString QTorrentHandle::comment() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
bool QTorrentHandle::is_checking() const {
|
||||
bool QTorrentHandle::is_checking() const
|
||||
{
|
||||
return is_checking(status(0x0));
|
||||
}
|
||||
|
||||
// Return a list of absolute paths corresponding
|
||||
// to all files in a torrent
|
||||
QStringList QTorrentHandle::absolute_files_path() const {
|
||||
QStringList QTorrentHandle::absolute_files_path() const
|
||||
{
|
||||
QDir saveDir(save_path());
|
||||
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)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
QStringList QTorrentHandle::absolute_files_path_uneeded() const {
|
||||
QStringList QTorrentHandle::absolute_files_path_uneeded() const
|
||||
{
|
||||
QDir saveDir(save_path());
|
||||
QStringList res;
|
||||
std::vector<int> fp = torrent_handle::file_priorities();
|
||||
|
@ -319,19 +346,21 @@ QStringList QTorrentHandle::absolute_files_path_uneeded() const {
|
|||
return res;
|
||||
}
|
||||
|
||||
bool QTorrentHandle::has_missing_files() const {
|
||||
bool QTorrentHandle::has_missing_files() const
|
||||
{
|
||||
const QStringList paths = absolute_files_path();
|
||||
foreach (const QString &path, paths) {
|
||||
foreach (const QString &path, paths)
|
||||
if (!QFile::exists(path)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int QTorrentHandle::queue_position() const {
|
||||
int QTorrentHandle::queue_position() const
|
||||
{
|
||||
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
|
||||
//return torrent_handle::is_seed();
|
||||
// May suffer from approximation problems
|
||||
|
@ -340,11 +369,13 @@ bool QTorrentHandle::is_seed() const {
|
|||
return is_seed(status(0x0));
|
||||
}
|
||||
|
||||
bool QTorrentHandle::is_sequential_download() const {
|
||||
bool QTorrentHandle::is_sequential_download() const
|
||||
{
|
||||
return status(0x0).sequential_download;
|
||||
}
|
||||
|
||||
bool QTorrentHandle::priv() const {
|
||||
bool QTorrentHandle::priv() const
|
||||
{
|
||||
if (!has_metadata())
|
||||
return false;
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
|
@ -354,7 +385,8 @@ bool QTorrentHandle::priv() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
QString QTorrentHandle::firstFileSavePath() const {
|
||||
QString QTorrentHandle::firstFileSavePath() const
|
||||
{
|
||||
Q_ASSERT(has_metadata());
|
||||
QString fsave_path = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
|
||||
if (fsave_path.isEmpty())
|
||||
|
@ -379,35 +411,40 @@ QString QTorrentHandle::root_path() const
|
|||
return save_path();
|
||||
}
|
||||
|
||||
bool QTorrentHandle::has_error() const {
|
||||
bool QTorrentHandle::has_error() const
|
||||
{
|
||||
return has_error(status(0x0));
|
||||
}
|
||||
|
||||
QString QTorrentHandle::error() const {
|
||||
QString QTorrentHandle::error() const
|
||||
{
|
||||
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;
|
||||
torrent_handle::get_download_queue(queue);
|
||||
|
||||
std::vector<partial_piece_info>::const_iterator it = queue.begin();
|
||||
std::vector<partial_piece_info>::const_iterator itend = queue.end();
|
||||
for ( ; it!= itend; ++it) {
|
||||
for (; it!= itend; ++it)
|
||||
bf.set_bit(it->piece_index);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool QTorrentHandle::has_metadata() const {
|
||||
bool QTorrentHandle::has_metadata() const
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
QTorrentState QTorrentHandle::torrentState() const {
|
||||
QTorrentState QTorrentHandle::torrentState() const
|
||||
{
|
||||
QTorrentState state = QTorrentState::Unknown;
|
||||
libtorrent::torrent_status s = status(torrent_handle::query_accurate_download_counters);
|
||||
|
||||
|
@ -456,13 +493,15 @@ qulonglong QTorrentHandle::eta() const
|
|||
// Setters
|
||||
//
|
||||
|
||||
void QTorrentHandle::pause() const {
|
||||
void QTorrentHandle::pause() const
|
||||
{
|
||||
torrent_handle::auto_managed(false);
|
||||
torrent_handle::pause();
|
||||
torrent_handle::save_resume_data();
|
||||
}
|
||||
|
||||
void QTorrentHandle::resume() const {
|
||||
void QTorrentHandle::resume() const
|
||||
{
|
||||
if (has_error())
|
||||
torrent_handle::clear_error();
|
||||
|
||||
|
@ -480,27 +519,30 @@ void QTorrentHandle::resume() const {
|
|||
}
|
||||
torrent_handle::auto_managed(true);
|
||||
torrent_handle::resume();
|
||||
if (has_persistant_error && temp_path_enabled) {
|
||||
if (has_persistant_error && temp_path_enabled)
|
||||
// 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());
|
||||
}
|
||||
|
||||
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();
|
||||
qDebug("calling torrent_handle::add_url_seed(%s)", str_seed.c_str());
|
||||
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()));
|
||||
}
|
||||
|
||||
void QTorrentHandle::move_storage(const QString& new_path) const {
|
||||
void QTorrentHandle::move_storage(const QString& new_path) const
|
||||
{
|
||||
QString hashstr = hash();
|
||||
|
||||
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 LIBTORRENT_VERSION_NUM < 10000
|
||||
|
@ -553,7 +596,8 @@ bool QTorrentHandle::save_torrent_file(const QString& path) const {
|
|||
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();
|
||||
if (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
|
||||
torrent_info const& info = torrent_handle::get_torrent_info();
|
||||
#else
|
||||
|
@ -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
|
||||
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);
|
||||
}
|
||||
|
||||
void QTorrentHandle::prioritize_first_last_piece(bool b) const {
|
||||
void QTorrentHandle::prioritize_first_last_piece(bool b) const
|
||||
{
|
||||
if (!has_metadata()) return;
|
||||
// Download first and last pieces first for all media files in the torrent
|
||||
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;
|
||||
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
|
||||
//
|
||||
|
||||
bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const {
|
||||
bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int QTorrentHandle::queue_position(const libtorrent::torrent_status &status) {
|
||||
int QTorrentHandle::queue_position(const libtorrent::torrent_status &status)
|
||||
{
|
||||
if (status.queue_position < 0)
|
||||
return -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;
|
||||
}
|
||||
|
||||
bool QTorrentHandle::is_seed(const libtorrent::torrent_status &status) {
|
||||
bool QTorrentHandle::is_seed(const libtorrent::torrent_status &status)
|
||||
{
|
||||
return status.state == torrent_status::finished
|
||||
|| 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
|
||||
|| 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();
|
||||
}
|
||||
|
||||
float QTorrentHandle::progress(const libtorrent::torrent_status &status) {
|
||||
float QTorrentHandle::progress(const libtorrent::torrent_status &status)
|
||||
{
|
||||
if (!status.total_wanted)
|
||||
return 0.;
|
||||
if (status.total_wanted_done == status.total_wanted)
|
||||
|
@ -723,7 +779,8 @@ float QTorrentHandle::progress(const libtorrent::torrent_status &status) {
|
|||
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)));
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ QT_END_NAMESPACE
|
|||
class QTorrentState
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
Unknown = -1,
|
||||
|
||||
Error,
|
||||
|
@ -71,7 +72,8 @@ private:
|
|||
|
||||
// A wrapper for torrent_handle in libtorrent
|
||||
// to interact well with Qt types
|
||||
class QTorrentHandle : public libtorrent::torrent_handle {
|
||||
class QTorrentHandle: public libtorrent::torrent_handle
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -68,7 +68,8 @@
|
|||
using namespace libtorrent;
|
||||
|
||||
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);
|
||||
// Load settings
|
||||
|
@ -153,7 +154,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window,
|
|||
deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTorrents()), 0, Qt::WidgetShortcut);
|
||||
}
|
||||
|
||||
TransferListWidget::~TransferListWidget() {
|
||||
TransferListWidget::~TransferListWidget()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "ENTER";
|
||||
// Save settings
|
||||
saveSettings();
|
||||
|
@ -166,59 +168,65 @@ TransferListWidget::~TransferListWidget() {
|
|||
qDebug() << Q_FUNC_INFO << "EXIT";
|
||||
}
|
||||
|
||||
TorrentModel* TransferListWidget::getSourceModel() const {
|
||||
TorrentModel* TransferListWidget::getSourceModel() const
|
||||
{
|
||||
return listModel;
|
||||
}
|
||||
|
||||
void TransferListWidget::previewFile(QString filePath) {
|
||||
void TransferListWidget::previewFile(QString filePath)
|
||||
{
|
||||
openUrl(filePath);
|
||||
}
|
||||
|
||||
void TransferListWidget::setRefreshInterval(int t) {
|
||||
void TransferListWidget::setRefreshInterval(int t)
|
||||
{
|
||||
qDebug("Settings transfer list refresh interval to %dms", t);
|
||||
listModel->setRefreshInterval(t);
|
||||
}
|
||||
|
||||
int TransferListWidget::getRowFromHash(QString hash) const {
|
||||
int TransferListWidget::getRowFromHash(QString hash) const
|
||||
{
|
||||
return listModel->torrentRow(hash);
|
||||
}
|
||||
|
||||
inline QString TransferListWidget::getHashFromRow(int row) const {
|
||||
inline QString TransferListWidget::getHashFromRow(int row) const
|
||||
{
|
||||
return listModel->torrentHash(row);
|
||||
}
|
||||
|
||||
inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const {
|
||||
inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const
|
||||
{
|
||||
Q_ASSERT(index.isValid());
|
||||
if (index.model() == nameFilterModel)
|
||||
return nameFilterModel->mapToSource(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.model() == nameFilterModel);
|
||||
return nameFilterModel->mapFromSource(index);
|
||||
}
|
||||
|
||||
void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
|
||||
void TransferListWidget::torrentDoubleClicked(const QModelIndex& index)
|
||||
{
|
||||
const int row = mapToSource(index).row();
|
||||
const QString hash = getHashFromRow(row);
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if (!h.is_valid()) return;
|
||||
int action;
|
||||
if (h.is_seed()) {
|
||||
if (h.is_seed())
|
||||
action = Preferences::instance()->getActionOnDblClOnTorrentFn();
|
||||
} else {
|
||||
else
|
||||
action = Preferences::instance()->getActionOnDblClOnTorrentDl();
|
||||
}
|
||||
|
||||
switch(action) {
|
||||
case TOGGLE_PAUSE:
|
||||
if (h.is_paused()) {
|
||||
if (h.is_paused())
|
||||
h.resume();
|
||||
} else {
|
||||
else
|
||||
h.pause();
|
||||
}
|
||||
break;
|
||||
case OPEN_DEST:
|
||||
const QString path = h.root_path();
|
||||
|
@ -226,16 +234,17 @@ void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
|
|||
}
|
||||
}
|
||||
|
||||
QStringList TransferListWidget::getSelectedTorrentsHashes() const {
|
||||
QStringList TransferListWidget::getSelectedTorrentsHashes() const
|
||||
{
|
||||
QStringList hashes;
|
||||
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||
foreach (const QModelIndex &index, selectedIndexes) {
|
||||
foreach (const QModelIndex &index, selectedIndexes)
|
||||
hashes << getHashFromRow(mapToSource(index).row());
|
||||
}
|
||||
return hashes;
|
||||
}
|
||||
|
||||
void TransferListWidget::setSelectedTorrentsLocation() {
|
||||
void TransferListWidget::setSelectedTorrentsLocation()
|
||||
{
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
if (hashes.isEmpty()) return;
|
||||
QString dir;
|
||||
|
@ -254,7 +263,8 @@ void TransferListWidget::setSelectedTorrentsLocation() {
|
|||
if (!BTSession->useTemporaryFolder() || h.is_seed()) {
|
||||
if (!savePath.exists()) savePath.mkpath(savePath.absolutePath());
|
||||
h.move_storage(savePath.absolutePath());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
TorrentPersistentData::saveSavePath(h.hash(), savePath.absolutePath());
|
||||
main_window->getProperties()->updateSavePath(h);
|
||||
}
|
||||
|
@ -262,43 +272,44 @@ void TransferListWidget::setSelectedTorrentsLocation() {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::startSelectedTorrents() {
|
||||
void TransferListWidget::startSelectedTorrents()
|
||||
{
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes)
|
||||
BTSession->resumeTorrent(hash);
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::startVisibleTorrents() {
|
||||
void TransferListWidget::startVisibleTorrents()
|
||||
{
|
||||
QStringList hashes;
|
||||
for (int i = 0; i<nameFilterModel->rowCount(); ++i) {
|
||||
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
||||
hashes << getHashFromRow(row);
|
||||
}
|
||||
foreach (const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes)
|
||||
BTSession->resumeTorrent(hash);
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::pauseSelectedTorrents() {
|
||||
void TransferListWidget::pauseSelectedTorrents()
|
||||
{
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes)
|
||||
BTSession->pauseTorrent(hash);
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::pauseVisibleTorrents() {
|
||||
void TransferListWidget::pauseVisibleTorrents()
|
||||
{
|
||||
QStringList hashes;
|
||||
for (int i = 0; i<nameFilterModel->rowCount(); ++i) {
|
||||
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
||||
hashes << getHashFromRow(row);
|
||||
}
|
||||
foreach (const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes)
|
||||
BTSession->pauseTorrent(hash);
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::deleteSelectedTorrents() {
|
||||
void TransferListWidget::deleteSelectedTorrents()
|
||||
{
|
||||
if (main_window->getCurrentTabWidget() != this) return;
|
||||
const QStringList& hashes = getSelectedTorrentsHashes();
|
||||
if (hashes.empty()) return;
|
||||
|
@ -307,12 +318,12 @@ void TransferListWidget::deleteSelectedTorrents() {
|
|||
if (Preferences::instance()->confirmTorrentDeletion() &&
|
||||
!DeletionConfirmationDlg::askForDeletionConfirmation(delete_local_files, hashes.size(), torrent.name()))
|
||||
return;
|
||||
foreach (const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes)
|
||||
BTSession->deleteTorrent(hash, delete_local_files);
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::deleteVisibleTorrents() {
|
||||
void TransferListWidget::deleteVisibleTorrents()
|
||||
{
|
||||
if (nameFilterModel->rowCount() <= 0) return;
|
||||
QTorrentHandle torrent = BTSession->getTorrentHandle(getHashFromRow(0));
|
||||
bool delete_local_files = false;
|
||||
|
@ -324,12 +335,12 @@ void TransferListWidget::deleteVisibleTorrents() {
|
|||
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
||||
hashes << getHashFromRow(row);
|
||||
}
|
||||
foreach (const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes)
|
||||
BTSession->deleteTorrent(hash, delete_local_files);
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::increasePrioSelectedTorrents() {
|
||||
void TransferListWidget::increasePrioSelectedTorrents()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if (main_window->getCurrentTabWidget() != this) return;
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
|
@ -338,9 +349,8 @@ void TransferListWidget::increasePrioSelectedTorrents() {
|
|||
foreach (const QString &hash, hashes) {
|
||||
try {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if (!h.is_seed()) {
|
||||
if (!h.is_seed())
|
||||
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||
}
|
||||
}catch(invalid_handle&) {}
|
||||
}
|
||||
// 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;
|
||||
if (main_window->getCurrentTabWidget() != this) return;
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
|
@ -362,9 +373,8 @@ void TransferListWidget::decreasePrioSelectedTorrents() {
|
|||
foreach (const QString &hash, hashes) {
|
||||
try {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if (!h.is_seed()) {
|
||||
if (!h.is_seed())
|
||||
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||
}
|
||||
}catch(invalid_handle&) {}
|
||||
}
|
||||
// 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;
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if (h.is_valid() && !h.is_seed()) {
|
||||
if (h.is_valid() && !h.is_seed())
|
||||
h.queue_position_top();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::bottomPrioSelectedTorrents() {
|
||||
void TransferListWidget::bottomPrioSelectedTorrents()
|
||||
{
|
||||
if (main_window->getCurrentTabWidget() != this) return;
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if (h.is_valid() && !h.is_seed()) {
|
||||
if (h.is_valid() && !h.is_seed())
|
||||
h.queue_position_bottom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::copySelectedMagnetURIs() const {
|
||||
void TransferListWidget::copySelectedMagnetURIs() const
|
||||
{
|
||||
QStringList magnet_uris;
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
|
@ -410,12 +421,14 @@ void TransferListWidget::copySelectedMagnetURIs() const {
|
|||
qApp->clipboard()->setText(magnet_uris.join("\n"));
|
||||
}
|
||||
|
||||
void TransferListWidget::hidePriorityColumn(bool hide) {
|
||||
void TransferListWidget::hidePriorityColumn(bool hide)
|
||||
{
|
||||
qDebug("hidePriorityColumn(%d)", hide);
|
||||
setColumnHidden(TorrentModelItem::TR_PRIORITY, hide);
|
||||
}
|
||||
|
||||
void TransferListWidget::openSelectedTorrentsFolder() const {
|
||||
void TransferListWidget::openSelectedTorrentsFolder() const
|
||||
{
|
||||
QSet<QString> pathsList;
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
|
@ -431,17 +444,18 @@ void TransferListWidget::openSelectedTorrentsFolder() const {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::previewSelectedTorrents() {
|
||||
void TransferListWidget::previewSelectedTorrents()
|
||||
{
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if (h.is_valid() && h.has_metadata()) {
|
||||
if (h.is_valid() && h.has_metadata())
|
||||
new PreviewSelect(this, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::setDlLimitSelectedTorrents() {
|
||||
void TransferListWidget::setDlLimitSelectedTorrents()
|
||||
{
|
||||
QList<QTorrentHandle> selected_torrents;
|
||||
bool first = true;
|
||||
bool all_same_limit = true;
|
||||
|
@ -451,14 +465,13 @@ void TransferListWidget::setDlLimitSelectedTorrents() {
|
|||
if (h.is_valid() && !h.is_seed()) {
|
||||
selected_torrents << h;
|
||||
// Determine current limit for selected torrents
|
||||
if (first) {
|
||||
if (first)
|
||||
first = false;
|
||||
} else {
|
||||
else
|
||||
if (all_same_limit && h.download_limit() != selected_torrents.first().download_limit())
|
||||
all_same_limit = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selected_torrents.empty()) return;
|
||||
|
||||
bool ok = false;
|
||||
|
@ -474,7 +487,8 @@ void TransferListWidget::setDlLimitSelectedTorrents() {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::setUpLimitSelectedTorrents() {
|
||||
void TransferListWidget::setUpLimitSelectedTorrents()
|
||||
{
|
||||
QList<QTorrentHandle> selected_torrents;
|
||||
bool first = true;
|
||||
bool all_same_limit = true;
|
||||
|
@ -484,14 +498,13 @@ void TransferListWidget::setUpLimitSelectedTorrents() {
|
|||
if (h.is_valid()) {
|
||||
selected_torrents << h;
|
||||
// Determine current limit for selected torrents
|
||||
if (first) {
|
||||
if (first)
|
||||
first = false;
|
||||
} else {
|
||||
else
|
||||
if (all_same_limit && h.upload_limit() != selected_torrents.first().upload_limit())
|
||||
all_same_limit = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selected_torrents.empty()) return;
|
||||
|
||||
bool ok = false;
|
||||
|
@ -507,7 +520,8 @@ void TransferListWidget::setUpLimitSelectedTorrents() {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::setMaxRatioSelectedTorrents() {
|
||||
void TransferListWidget::setMaxRatioSelectedTorrents()
|
||||
{
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
if (hashes.isEmpty())
|
||||
return;
|
||||
|
@ -515,7 +529,8 @@ void TransferListWidget::setMaxRatioSelectedTorrents() {
|
|||
qreal currentMaxRatio;
|
||||
if (hashes.count() == 1) {
|
||||
currentMaxRatio = BTSession->getMaxRatioPerTorrent(hashes.first(), &useGlobalValue);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
useGlobalValue = true;
|
||||
currentMaxRatio = BTSession->getGlobalMaxRatio();
|
||||
}
|
||||
|
@ -530,18 +545,19 @@ 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);
|
||||
if (ret != QMessageBox::Yes)
|
||||
return;
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes)
|
||||
BTSession->recheckTorrent(hash);
|
||||
}
|
||||
}
|
||||
|
||||
// hide/show columns menu
|
||||
void TransferListWidget::displayDLHoSMenu(const QPoint&) {
|
||||
void TransferListWidget::displayDLHoSMenu(const QPoint&)
|
||||
{
|
||||
QMenu hideshowColumn(this);
|
||||
hideshowColumn.setTitle(tr("Column visibility"));
|
||||
QList<QAction*> actions;
|
||||
|
@ -579,17 +595,18 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&) {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const {
|
||||
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const
|
||||
{
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const {
|
||||
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const
|
||||
{
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
|
@ -602,17 +619,18 @@ void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const {
|
||||
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const
|
||||
{
|
||||
QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach (const QString &hash, hashes) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::askNewLabelForSelection() {
|
||||
void TransferListWidget::askNewLabelForSelection()
|
||||
{
|
||||
// Ask for label
|
||||
bool ok;
|
||||
bool invalid;
|
||||
|
@ -622,7 +640,8 @@ void TransferListWidget::askNewLabelForSelection() {
|
|||
if (ok && !label.isEmpty()) {
|
||||
if (fsutils::isValidFileSystemName(label)) {
|
||||
setSelectionLabel(label);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
|
||||
invalid = true;
|
||||
}
|
||||
|
@ -630,7 +649,8 @@ void TransferListWidget::askNewLabelForSelection() {
|
|||
} while(invalid);
|
||||
}
|
||||
|
||||
bool TransferListWidget::openUrl(const QString &_path) const {
|
||||
bool TransferListWidget::openUrl(const QString &_path) const
|
||||
{
|
||||
const QString path = fsutils::fromNativePath(_path);
|
||||
// Hack to access samba shares with QDesktopServices::openUrl
|
||||
if (path.startsWith("//"))
|
||||
|
@ -639,7 +659,8 @@ bool TransferListWidget::openUrl(const QString &_path) const {
|
|||
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||
}
|
||||
|
||||
void TransferListWidget::renameSelectedTorrent() {
|
||||
void TransferListWidget::renameSelectedTorrent()
|
||||
{
|
||||
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||
if (selectedIndexes.size() != 1) 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();
|
||||
foreach (const QString &hash, hashes) {
|
||||
Q_ASSERT(!hash.isEmpty());
|
||||
|
@ -670,7 +692,8 @@ void TransferListWidget::setSelectionLabel(QString label) {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::removeLabelFromRows(QString label) {
|
||||
void TransferListWidget::removeLabelFromRows(QString label)
|
||||
{
|
||||
for (int i = 0; i<listModel->rowCount(); ++i) {
|
||||
if (listModel->data(listModel->index(i, TorrentModelItem::TR_LABEL)) == label) {
|
||||
const QString hash = getHashFromRow(i);
|
||||
|
@ -682,7 +705,8 @@ void TransferListWidget::removeLabelFromRows(QString label) {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::displayListMenu(const QPoint&) {
|
||||
void TransferListWidget::displayListMenu(const QPoint&)
|
||||
{
|
||||
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||
if (selectedIndexes.size() == 0)
|
||||
return;
|
||||
|
@ -754,25 +778,23 @@ void TransferListWidget::displayListMenu(const QPoint&) {
|
|||
if (first) {
|
||||
sequential_download_mode = h.is_sequential_download();
|
||||
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;
|
||||
}
|
||||
if (prioritize_first_last != h.first_last_piece_first()) {
|
||||
if (prioritize_first_last != h.first_last_piece_first())
|
||||
all_same_prio_firstlast = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!one_not_seed && all_same_super_seeding && h.has_metadata()) {
|
||||
if (first) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (h.is_paused()) {
|
||||
|
@ -780,15 +802,15 @@ void TransferListWidget::displayListMenu(const QPoint&) {
|
|||
listMenu.addAction(&actionStart);
|
||||
has_start = true;
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
if (!has_pause) {
|
||||
listMenu.addAction(&actionPause);
|
||||
has_pause = true;
|
||||
}
|
||||
}
|
||||
if (h.has_metadata() && BTSession->isFilePreviewPossible(hash) && !has_preview) {
|
||||
if (h.has_metadata() && BTSession->isFilePreviewPossible(hash) && !has_preview)
|
||||
has_preview = true;
|
||||
}
|
||||
first = false;
|
||||
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("edit-clear"), tr("Reset", "Reset label"));
|
||||
labelMenu->addSeparator();
|
||||
foreach (const QString &label, customLabels) {
|
||||
foreach (const QString &label, customLabels)
|
||||
labelActions << labelMenu->addAction(IconProvider::instance()->getIcon("inode-directory"), label);
|
||||
}
|
||||
listMenu.addSeparator();
|
||||
if (one_not_seed)
|
||||
listMenu.addAction(&actionSet_download_limit);
|
||||
|
@ -864,7 +885,8 @@ void TransferListWidget::displayListMenu(const QPoint&) {
|
|||
if (i == 0) {
|
||||
// New Label
|
||||
askNewLabelForSelection();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
QString label = "";
|
||||
if (i > 1)
|
||||
label = customLabels.at(i - 2);
|
||||
|
@ -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");
|
||||
QTorrentHandle h;
|
||||
if (current.isValid()) {
|
||||
|
@ -887,20 +910,24 @@ void TransferListWidget::currentChanged(const QModelIndex& current, const QModel
|
|||
emit currentTorrentChanged(h);
|
||||
}
|
||||
|
||||
void TransferListWidget::applyLabelFilterAll() {
|
||||
void TransferListWidget::applyLabelFilterAll()
|
||||
{
|
||||
nameFilterModel->disableLabelFilter();
|
||||
}
|
||||
|
||||
void TransferListWidget::applyLabelFilter(QString label) {
|
||||
void TransferListWidget::applyLabelFilter(QString label)
|
||||
{
|
||||
qDebug("Applying Label filter: %s", qPrintable(label));
|
||||
nameFilterModel->setLabelFilter(label);
|
||||
}
|
||||
|
||||
void TransferListWidget::applyNameFilter(const QString& name) {
|
||||
void TransferListWidget::applyNameFilter(const QString& name)
|
||||
{
|
||||
nameFilterModel->setFilterRegExp(QRegExp(QRegExp::escape(name), Qt::CaseInsensitive));
|
||||
}
|
||||
|
||||
void TransferListWidget::applyStatusFilter(int f) {
|
||||
void TransferListWidget::applyStatusFilter(int f)
|
||||
{
|
||||
nameFilterModel->setStatusFilter((TorrentFilter::TorrentFilter)f);
|
||||
// Select first item if nothing is selected
|
||||
if (selectionModel()->selectedRows(0).empty() && nameFilterModel->rowCount() > 0) {
|
||||
|
@ -917,9 +944,8 @@ void TransferListWidget::saveSettings()
|
|||
bool TransferListWidget::loadSettings()
|
||||
{
|
||||
bool ok = header()->restoreState(Preferences::instance()->getTransHeaderState());
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
header()->resizeSection(0, 200); // Default
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,8 @@ class QSortFilterProxyModel;
|
|||
class QStandardItemModel;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class TransferListWidget: public QTreeView {
|
||||
class TransferListWidget: public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
|
@ -294,8 +294,9 @@ QByteArray btjson::getTrackersForTorrent(const QString& hash)
|
|||
tracker_dict[KEY_TRACKER_URL] = tracker_url;
|
||||
const TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
QString status;
|
||||
if (it->verified)
|
||||
if (it->verified) {
|
||||
status = tr("Working");
|
||||
}
|
||||
else {
|
||||
if (it->updating && it->fails == 0)
|
||||
status = tr("Updating...");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue