1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-05 11:24:15 +00:00

Several fixes to the new torrent model (still buggy)

This commit is contained in:
Christophe Dumez 2010-11-14 18:46:16 +00:00
parent af562ecf89
commit 9c67aaf641
6 changed files with 18 additions and 67 deletions

View File

@ -752,6 +752,7 @@ void QBtSession::deleteTorrent(QString hash, bool delete_local_files) {
qDebug("/!\\ Error: Invalid handle"); qDebug("/!\\ Error: Invalid handle");
return; return;
} }
emit torrentAboutToBeRemoved(h);
qDebug("h is valid, getting name or hash..."); qDebug("h is valid, getting name or hash...");
QString fileName; QString fileName;
if(h.has_metadata()) if(h.has_metadata())

View File

@ -192,6 +192,7 @@ protected slots:
signals: signals:
void addedTorrent(const QTorrentHandle& h); void addedTorrent(const QTorrentHandle& h);
void deletedTorrent(QString hash); void deletedTorrent(QString hash);
void torrentAboutToBeRemoved(const QTorrentHandle &h);
void pausedTorrent(QTorrentHandle& h); void pausedTorrent(QTorrentHandle& h);
void resumedTorrent(QTorrentHandle& h); void resumedTorrent(QTorrentHandle& h);
void finishedTorrent(QTorrentHandle& h); void finishedTorrent(QTorrentHandle& h);

View File

@ -52,12 +52,10 @@ QTorrentHandle::QTorrentHandle(torrent_handle h): torrent_handle(h) {}
// //
QString QTorrentHandle::hash() const { QString QTorrentHandle::hash() const {
Q_ASSERT(torrent_handle::is_valid());
return misc::toQString(torrent_handle::info_hash()); return misc::toQString(torrent_handle::info_hash());
} }
QString QTorrentHandle::name() const { QString QTorrentHandle::name() const {
Q_ASSERT(torrent_handle::is_valid());
QString name = TorrentPersistentData::getName(hash()); QString name = TorrentPersistentData::getName(hash());
if(name.isEmpty()) { if(name.isEmpty()) {
name = misc::toQStringU(torrent_handle::name()); name = misc::toQStringU(torrent_handle::name());
@ -66,23 +64,19 @@ QString QTorrentHandle::name() const {
} }
QString QTorrentHandle::creation_date() const { QString QTorrentHandle::creation_date() const {
Q_ASSERT(torrent_handle::is_valid());
boost::optional<boost::posix_time::ptime> boostDate = torrent_handle::get_torrent_info().creation_date(); boost::optional<boost::posix_time::ptime> boostDate = torrent_handle::get_torrent_info().creation_date();
return misc::boostTimeToQString(boostDate); return misc::boostTimeToQString(boostDate);
} }
QString QTorrentHandle::next_announce() const { QString QTorrentHandle::next_announce() const {
Q_ASSERT(torrent_handle::is_valid());
return misc::userFriendlyDuration(torrent_handle::status().next_announce.total_seconds()); return misc::userFriendlyDuration(torrent_handle::status().next_announce.total_seconds());
} }
qlonglong QTorrentHandle::next_announce_s() const { qlonglong QTorrentHandle::next_announce_s() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().next_announce.total_seconds(); return torrent_handle::status().next_announce.total_seconds();
} }
float QTorrentHandle::progress() const { float QTorrentHandle::progress() const {
Q_ASSERT(torrent_handle::is_valid());
if(!torrent_handle::status().total_wanted) if(!torrent_handle::status().total_wanted)
return 0.; return 0.;
if (torrent_handle::status().total_wanted_done == torrent_handle::status().total_wanted) if (torrent_handle::status().total_wanted_done == torrent_handle::status().total_wanted)
@ -93,42 +87,34 @@ float QTorrentHandle::progress() const {
} }
bitfield QTorrentHandle::pieces() const { bitfield QTorrentHandle::pieces() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().pieces; return torrent_handle::status().pieces;
} }
QString QTorrentHandle::current_tracker() const { QString QTorrentHandle::current_tracker() const {
Q_ASSERT(torrent_handle::is_valid());
return misc::toQString(torrent_handle::status().current_tracker); return misc::toQString(torrent_handle::status().current_tracker);
} }
bool QTorrentHandle::is_paused() const { bool QTorrentHandle::is_paused() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::is_paused() && !torrent_handle::is_auto_managed(); return torrent_handle::is_paused() && !torrent_handle::is_auto_managed();
} }
bool QTorrentHandle::is_queued() const { bool QTorrentHandle::is_queued() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::is_paused() && torrent_handle::is_auto_managed(); return torrent_handle::is_paused() && torrent_handle::is_auto_managed();
} }
size_type QTorrentHandle::total_size() const { size_type QTorrentHandle::total_size() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::get_torrent_info().total_size(); return torrent_handle::get_torrent_info().total_size();
} }
size_type QTorrentHandle::piece_length() const { size_type QTorrentHandle::piece_length() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::get_torrent_info().piece_length(); return torrent_handle::get_torrent_info().piece_length();
} }
int QTorrentHandle::num_pieces() const { int QTorrentHandle::num_pieces() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::get_torrent_info().num_pieces(); return torrent_handle::get_torrent_info().num_pieces();
} }
bool QTorrentHandle::first_last_piece_first() const { bool QTorrentHandle::first_last_piece_first() const {
Q_ASSERT(torrent_handle::is_valid());
// Detect main file // Detect main file
int rank=0; int rank=0;
int main_file_index = 0; int main_file_index = 0;
@ -157,47 +143,38 @@ bool QTorrentHandle::first_last_piece_first() const {
} }
size_type QTorrentHandle::total_wanted_done() const { size_type QTorrentHandle::total_wanted_done() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().total_wanted_done; return torrent_handle::status().total_wanted_done;
} }
float QTorrentHandle::download_payload_rate() const { float QTorrentHandle::download_payload_rate() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().download_payload_rate; return torrent_handle::status().download_payload_rate;
} }
float QTorrentHandle::upload_payload_rate() const { float QTorrentHandle::upload_payload_rate() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().upload_payload_rate; return torrent_handle::status().upload_payload_rate;
} }
int QTorrentHandle::num_peers() const { int QTorrentHandle::num_peers() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().num_peers; return torrent_handle::status().num_peers;
} }
int QTorrentHandle::num_seeds() const { int QTorrentHandle::num_seeds() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().num_seeds; return torrent_handle::status().num_seeds;
} }
int QTorrentHandle::num_complete() const { int QTorrentHandle::num_complete() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().num_complete; return torrent_handle::status().num_complete;
} }
int QTorrentHandle::num_incomplete() const { int QTorrentHandle::num_incomplete() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().num_incomplete; return torrent_handle::status().num_incomplete;
} }
QString QTorrentHandle::save_path() const { QString QTorrentHandle::save_path() const {
Q_ASSERT(torrent_handle::is_valid());
return misc::toQStringU(torrent_handle::save_path().string()).replace("\\", "/"); return misc::toQStringU(torrent_handle::save_path().string()).replace("\\", "/");
} }
QStringList QTorrentHandle::url_seeds() const { QStringList QTorrentHandle::url_seeds() const {
Q_ASSERT(torrent_handle::is_valid());
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();
@ -214,12 +191,10 @@ 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{
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().total_wanted; return torrent_handle::status().total_wanted;
} }
bool QTorrentHandle::has_filtered_pieces() const { bool QTorrentHandle::has_filtered_pieces() const {
Q_ASSERT(torrent_handle::is_valid());
std::vector<int> piece_priorities = torrent_handle::piece_priorities(); std::vector<int> piece_priorities = torrent_handle::piece_priorities();
for(unsigned int i = 0; i<piece_priorities.size(); ++i) { for(unsigned int i = 0; i<piece_priorities.size(); ++i) {
if(!piece_priorities[i]) return true; if(!piece_priorities[i]) return true;
@ -228,81 +203,66 @@ bool QTorrentHandle::has_filtered_pieces() const {
} }
int QTorrentHandle::num_files() const { int QTorrentHandle::num_files() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::get_torrent_info().num_files(); return torrent_handle::get_torrent_info().num_files();
} }
QString QTorrentHandle::filename_at(unsigned int index) const { QString QTorrentHandle::filename_at(unsigned int index) const {
Q_ASSERT(torrent_handle::is_valid());
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 misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.leaf()); return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.leaf());
} }
size_type QTorrentHandle::filesize_at(unsigned int index) const { size_type QTorrentHandle::filesize_at(unsigned int index) const {
Q_ASSERT(torrent_handle::is_valid());
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().file_at(index).size; return torrent_handle::get_torrent_info().file_at(index).size;
} }
torrent_status::state_t QTorrentHandle::state() const { torrent_status::state_t QTorrentHandle::state() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().state; return torrent_handle::status().state;
} }
QString QTorrentHandle::creator() const { QString QTorrentHandle::creator() const {
Q_ASSERT(torrent_handle::is_valid());
return misc::toQStringU(torrent_handle::get_torrent_info().creator()); return misc::toQStringU(torrent_handle::get_torrent_info().creator());
} }
QString QTorrentHandle::comment() const { QString QTorrentHandle::comment() const {
Q_ASSERT(torrent_handle::is_valid());
return misc::toQStringU(torrent_handle::get_torrent_info().comment()); return misc::toQStringU(torrent_handle::get_torrent_info().comment());
} }
size_type QTorrentHandle::total_failed_bytes() const { size_type QTorrentHandle::total_failed_bytes() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().total_failed_bytes; return torrent_handle::status().total_failed_bytes;
} }
size_type QTorrentHandle::total_redundant_bytes() const { size_type QTorrentHandle::total_redundant_bytes() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().total_redundant_bytes; return torrent_handle::status().total_redundant_bytes;
} }
bool QTorrentHandle::is_checking() const { bool QTorrentHandle::is_checking() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().state == torrent_status::checking_files || torrent_handle::status().state == torrent_status::checking_resume_data; return torrent_handle::status().state == torrent_status::checking_files || torrent_handle::status().state == torrent_status::checking_resume_data;
} }
size_type QTorrentHandle::total_done() const { size_type QTorrentHandle::total_done() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().total_done; return torrent_handle::status().total_done;
} }
size_type QTorrentHandle::all_time_download() const { size_type QTorrentHandle::all_time_download() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().all_time_download; return torrent_handle::status().all_time_download;
} }
size_type QTorrentHandle::all_time_upload() const { size_type QTorrentHandle::all_time_upload() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().all_time_upload; return torrent_handle::status().all_time_upload;
} }
size_type QTorrentHandle::total_payload_download() const { size_type QTorrentHandle::total_payload_download() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().total_payload_download; return torrent_handle::status().total_payload_download;
} }
size_type QTorrentHandle::total_payload_upload() const { size_type QTorrentHandle::total_payload_upload() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().total_payload_upload; return torrent_handle::status().total_payload_upload;
} }
// 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::files_path() const { QStringList QTorrentHandle::files_path() const {
Q_ASSERT(torrent_handle::is_valid());
QDir saveDir(save_path()); QDir saveDir(save_path());
QStringList res; QStringList res;
torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files(); torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files();
@ -314,7 +274,6 @@ QStringList QTorrentHandle::files_path() const {
} }
QStringList QTorrentHandle::uneeded_files_path() const { QStringList QTorrentHandle::uneeded_files_path() const {
Q_ASSERT(torrent_handle::is_valid());
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();
@ -338,19 +297,16 @@ bool QTorrentHandle::has_missing_files() const {
} }
int QTorrentHandle::queue_position() const { int QTorrentHandle::queue_position() const {
Q_ASSERT(torrent_handle::is_valid());
if(torrent_handle::queue_position() < 0) if(torrent_handle::queue_position() < 0)
return -1; return -1;
return torrent_handle::queue_position()+1; return torrent_handle::queue_position()+1;
} }
int QTorrentHandle::num_uploads() const { int QTorrentHandle::num_uploads() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().num_uploads; return torrent_handle::status().num_uploads;
} }
bool QTorrentHandle::is_seed() const { bool QTorrentHandle::is_seed() const {
Q_ASSERT(torrent_handle::is_valid());
// 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
@ -360,37 +316,30 @@ bool QTorrentHandle::is_seed() const {
} }
bool QTorrentHandle::is_auto_managed() const { bool QTorrentHandle::is_auto_managed() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::is_auto_managed(); return torrent_handle::is_auto_managed();
} }
qlonglong QTorrentHandle::active_time() const { qlonglong QTorrentHandle::active_time() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().active_time; return torrent_handle::status().active_time;
} }
qlonglong QTorrentHandle::seeding_time() const { qlonglong QTorrentHandle::seeding_time() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().seeding_time; return torrent_handle::status().seeding_time;
} }
int QTorrentHandle::num_connections() const { int QTorrentHandle::num_connections() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().num_connections; return torrent_handle::status().num_connections;
} }
int QTorrentHandle::connections_limit() const { int QTorrentHandle::connections_limit() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::status().connections_limit; return torrent_handle::status().connections_limit;
} }
bool QTorrentHandle::priv() const { bool QTorrentHandle::priv() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::get_torrent_info().priv(); return torrent_handle::get_torrent_info().priv();
} }
QString QTorrentHandle::firstFileSavePath() const { QString QTorrentHandle::firstFileSavePath() const {
Q_ASSERT(torrent_handle::is_valid());
Q_ASSERT(has_metadata()); Q_ASSERT(has_metadata());
QString fsave_path = TorrentPersistentData::getSavePath(hash()); QString fsave_path = TorrentPersistentData::getSavePath(hash());
if(fsave_path.isEmpty()) if(fsave_path.isEmpty())
@ -406,17 +355,14 @@ QString QTorrentHandle::firstFileSavePath() const {
} }
bool QTorrentHandle::has_error() const { bool QTorrentHandle::has_error() const {
Q_ASSERT(torrent_handle::is_valid());
return torrent_handle::is_paused() && !torrent_handle::status().error.empty(); return torrent_handle::is_paused() && !torrent_handle::status().error.empty();
} }
QString QTorrentHandle::error() const { QString QTorrentHandle::error() const {
Q_ASSERT(torrent_handle::is_valid());
return misc::toQString(torrent_handle::status().error); return misc::toQString(torrent_handle::status().error);
} }
void QTorrentHandle::downloading_pieces(bitfield &bf) const { void QTorrentHandle::downloading_pieces(bitfield &bf) const {
Q_ASSERT(torrent_handle::is_valid());
std::vector<partial_piece_info> queue; std::vector<partial_piece_info> queue;
torrent_handle::get_download_queue(queue); torrent_handle::get_download_queue(queue);
for(std::vector<partial_piece_info>::iterator it=queue.begin(); it!= queue.end(); it++) { for(std::vector<partial_piece_info>::iterator it=queue.begin(); it!= queue.end(); it++) {
@ -430,14 +376,12 @@ void QTorrentHandle::downloading_pieces(bitfield &bf) const {
// //
void QTorrentHandle::pause() { void QTorrentHandle::pause() {
Q_ASSERT(torrent_handle::is_valid());
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() { void QTorrentHandle::resume() {
Q_ASSERT(torrent_handle::is_valid());
if(has_error()) torrent_handle::clear_error(); if(has_error()) torrent_handle::clear_error();
const QString torrent_hash = hash(); const QString torrent_hash = hash();
bool has_persistant_error = TorrentPersistentData::hasError(torrent_hash); bool has_persistant_error = TorrentPersistentData::hasError(torrent_hash);
@ -460,12 +404,10 @@ void QTorrentHandle::resume() {
} }
void QTorrentHandle::remove_url_seed(QString seed) { void QTorrentHandle::remove_url_seed(QString seed) {
Q_ASSERT(torrent_handle::is_valid());
torrent_handle::remove_url_seed(seed.toStdString()); torrent_handle::remove_url_seed(seed.toStdString());
} }
void QTorrentHandle::add_url_seed(QString seed) { void QTorrentHandle::add_url_seed(QString seed) {
Q_ASSERT(torrent_handle::is_valid());
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);
@ -473,7 +415,6 @@ void QTorrentHandle::add_url_seed(QString seed) {
void QTorrentHandle::prioritize_files(const std::vector<int> &v) { void QTorrentHandle::prioritize_files(const std::vector<int> &v) {
// Does not do anything for seeding torrents // Does not do anything for seeding torrents
Q_ASSERT(torrent_handle::is_valid());
if(v.size() != (unsigned int)torrent_handle::get_torrent_info().num_files()) if(v.size() != (unsigned int)torrent_handle::get_torrent_info().num_files())
return; return;
bool was_seed = is_seed(); bool was_seed = is_seed();
@ -493,7 +434,6 @@ void QTorrentHandle::prioritize_files(const std::vector<int> &v) {
} }
void QTorrentHandle::file_priority(int index, int priority) const { void QTorrentHandle::file_priority(int index, int priority) const {
Q_ASSERT(torrent_handle::is_valid());
bool was_seed = is_seed(); bool was_seed = is_seed();
torrent_handle::file_priority(index, priority); torrent_handle::file_priority(index, priority);
if(was_seed && !is_seed()) { if(was_seed && !is_seed()) {
@ -511,12 +451,10 @@ void QTorrentHandle::file_priority(int index, int priority) const {
} }
void QTorrentHandle::set_tracker_login(QString username, QString password) { void QTorrentHandle::set_tracker_login(QString username, QString password) {
Q_ASSERT(torrent_handle::is_valid());
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(QString new_path) const { void QTorrentHandle::move_storage(QString new_path) const {
Q_ASSERT(torrent_handle::is_valid());
if(QDir(save_path()) == QDir(new_path)) return; if(QDir(save_path()) == QDir(new_path)) return;
TorrentPersistentData::setPreviousSavePath(hash(), save_path()); TorrentPersistentData::setPreviousSavePath(hash(), save_path());
// Create destination directory if necessary // Create destination directory if necessary
@ -544,7 +482,6 @@ bool QTorrentHandle::save_torrent_file(QString path) {
} }
void QTorrentHandle::add_tracker(const announce_entry& url) { void QTorrentHandle::add_tracker(const announce_entry& url) {
Q_ASSERT(torrent_handle::is_valid());
#if LIBTORRENT_VERSION_MINOR > 14 #if LIBTORRENT_VERSION_MINOR > 14
torrent_handle::add_tracker(url); torrent_handle::add_tracker(url);
#else #else
@ -566,7 +503,6 @@ void QTorrentHandle::add_tracker(const announce_entry& url) {
} }
void QTorrentHandle::prioritize_first_last_piece(bool b) { void QTorrentHandle::prioritize_first_last_piece(bool b) {
Q_ASSERT(torrent_handle::is_valid());
// Detect main file // Detect main file
int rank=0; int rank=0;
int main_file_index = 0; int main_file_index = 0;
@ -608,6 +544,6 @@ void QTorrentHandle::rename_file(int index, QString name) {
// //
bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const{ bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const{
QString hash = misc::toQString(torrent_handle::info_hash()); const QString hash = misc::toQString(torrent_handle::info_hash());
return (hash == new_h.hash()); return (hash == new_h.hash());
} }

View File

@ -76,6 +76,7 @@ TorrentModelItem::State TorrentModelItem::state() const
bool TorrentModelItem::setData(int column, const QVariant &value, int role) bool TorrentModelItem::setData(int column, const QVariant &value, int role)
{ {
qDebug() << Q_FUNC_INFO << column << value;
if(role != Qt::DisplayRole) return false; if(role != Qt::DisplayRole) return false;
// Label and Name columns can be edited // Label and Name columns can be edited
switch(column) { switch(column) {
@ -183,6 +184,7 @@ void TorrentModel::populate() {
m_refreshTimer.start(m_refreshInterval); m_refreshTimer.start(m_refreshInterval);
// Listen for torrent changes // Listen for torrent changes
connect(QBtSession::instance(), SIGNAL(addedTorrent(QTorrentHandle)), SLOT(addTorrent(QTorrentHandle))); connect(QBtSession::instance(), SIGNAL(addedTorrent(QTorrentHandle)), SLOT(addTorrent(QTorrentHandle)));
connect(QBtSession::instance(), SIGNAL(torrentAboutToBeRemoved(QTorrentHandle)), SLOT(handleTorrentAboutToBeRemoved(QTorrentHandle)));
connect(QBtSession::instance(), SIGNAL(deletedTorrent(QString)), SLOT(removeTorrent(QString))); connect(QBtSession::instance(), SIGNAL(deletedTorrent(QString)), SLOT(removeTorrent(QString)));
connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle&)), SLOT(handleTorrentUpdate(QTorrentHandle&))); connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle&)), SLOT(handleTorrentUpdate(QTorrentHandle&)));
connect(QBtSession::instance(), SIGNAL(metadataReceived(QTorrentHandle&)), SLOT(handleTorrentUpdate(QTorrentHandle&))); connect(QBtSession::instance(), SIGNAL(metadataReceived(QTorrentHandle&)), SLOT(handleTorrentUpdate(QTorrentHandle&)));
@ -258,7 +260,9 @@ QVariant TorrentModel::data(const QModelIndex &index, int role) const
bool TorrentModel::setData(const QModelIndex &index, const QVariant &value, int role) bool TorrentModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
qDebug() << Q_FUNC_INFO << value;
if(!index.isValid() || role != Qt::DisplayRole) return false; if(!index.isValid() || role != Qt::DisplayRole) return false;
qDebug("Index is valid and role is DisplayRole");
try { try {
if(index.row() >= 0 && index.row() < rowCount() && index.column() >= 0 && index.column() < columnCount()) { if(index.row() >= 0 && index.row() < rowCount() && index.column() >= 0 && index.column() < columnCount()) {
bool change = m_torrents[index.row()]->setData(index.column(), value, role); bool change = m_torrents[index.row()]->setData(index.column(), value, role);
@ -298,8 +302,8 @@ void TorrentModel::addTorrent(const QTorrentHandle &h)
void TorrentModel::removeTorrent(const QString &hash) void TorrentModel::removeTorrent(const QString &hash)
{ {
const int row = torrentRow(hash); const int row = torrentRow(hash);
qDebug() << Q_FUNC_INFO << hash << row;
if(row > 0) { if(row > 0) {
emit torrentAboutToBeRemoved(m_torrents.at(row));
beginRemoveTorrent(row); beginRemoveTorrent(row);
m_torrents.removeAt(row); m_torrents.removeAt(row);
endRemoveTorrent(); endRemoveTorrent();
@ -411,3 +415,11 @@ QString TorrentModel::torrentHash(int row) const
return m_torrents.at(row)->hash(); return m_torrents.at(row)->hash();
return QString(); return QString();
} }
void TorrentModel::handleTorrentAboutToBeRemoved(const QTorrentHandle &h)
{
const int row = torrentRow(h.hash());
if(row >= 0) {
emit torrentAboutToBeRemoved(m_torrents.at(row));
}
}

View File

@ -76,6 +76,7 @@ private slots:
void notifyTorrentChanged(int row); void notifyTorrentChanged(int row);
void forceModelRefresh(); void forceModelRefresh();
void handleTorrentLabelChange(QString previous, QString current); void handleTorrentLabelChange(QString previous, QString current);
void handleTorrentAboutToBeRemoved(const QTorrentHandle & h);
private: private:
void beginInsertTorrent(int row); void beginInsertTorrent(int row);

View File

@ -649,7 +649,7 @@ void TransferListWidget::setSelectionLabel(QString label) {
Q_ASSERT(!hash.isEmpty()); Q_ASSERT(!hash.isEmpty());
const int row = getRowFromHash(hash); const int row = getRowFromHash(hash);
const QString old_label = listModel->data(listModel->index(row, TorrentModelItem::TR_LABEL)).toString(); const QString old_label = listModel->data(listModel->index(row, TorrentModelItem::TR_LABEL)).toString();
listModel->setData(listModel->index(row, TorrentModelItem::TR_LABEL), QVariant(label)); listModel->setData(listModel->index(row, TorrentModelItem::TR_LABEL), QVariant(label), Qt::DisplayRole);
// Update save path if necessary // Update save path if necessary
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
BTSession->changeLabelInTorrentSavePath(h, old_label, label); BTSession->changeLabelInTorrentSavePath(h, old_label, label);