Browse Source

- fixed some bugs introduced recently

- improved debug output
adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
829c358f10
  1. 28
      src/bittorrent.cpp
  2. 3
      src/previewSelect.h
  3. 116
      src/qtorrenthandle.cpp
  4. 3
      src/qtorrenthandle.h
  5. 3
      src/trackerLogin.h

28
src/bittorrent.cpp

@ -367,9 +367,11 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { @@ -367,9 +367,11 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
entry e = bdecode(std::istream_iterator<char>(in), std::istream_iterator<char>());
// Getting torrent file informations
torrent_info t(e);
std::cout << t.info_hash() << "\n";
QString hash = QString::fromUtf8(misc::toString(t.info_hash()).c_str());
qDebug(" -> Hash: %s", misc::toString(t.info_hash()).c_str());
qDebug(" -> Name: %s", t.name().c_str());
QString hash = misc::toQString(t.info_hash());
if(s->find_torrent(t.info_hash()).is_valid()) {
qDebug("/!\\ Torrent is already in download list");
// Update info Bar
if(!fromScanDir) {
if(file.startsWith(torrentBackup.path())){
@ -377,7 +379,8 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { @@ -377,7 +379,8 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
// XXX: Why does this happen sometimes?
QFileInfo fi(file);
QString old_hash = fi.baseName();
qDebug("Strange, hash changed to %s", old_hash.toUtf8().data());
qDebug("Strange, hash changed from %s to %s", old_hash.toUtf8().data(), hash.toUtf8().data());
Q_ASSERT(old_hash != hash);
QStringList filters;
filters << old_hash+".*";
QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
@ -421,10 +424,10 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { @@ -421,10 +424,10 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
if(index == -1) {
fullAllocationModeList << hash;
}
qDebug("Full allocation mode");
qDebug(" -> Full allocation mode");
}else{
h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, true, true);
qDebug("Compact allocation mode");
qDebug(" -> Compact allocation mode");
}
if(!h.is_valid()) {
// No need to keep on, it failed.
@ -436,7 +439,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { @@ -436,7 +439,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
// Is this really useful and appropriate ?
//h.set_max_connections(60);
h.set_max_uploads(-1);
qDebug("Torrent hash is " + hash.toUtf8());
// Load filtered files
loadFilesPriorities(h);
// Load custom url seeds
@ -605,7 +607,7 @@ void bittorrent::saveTorrentSpeedLimits(QString hash) { @@ -605,7 +607,7 @@ void bittorrent::saveTorrentSpeedLimits(QString hash) {
}
void bittorrent::loadTorrentSpeedLimits(QString hash) {
qDebug("Loading speedLimits file for %s", hash.toUtf8().data());
// qDebug("Loading speedLimits file for %s", hash.toUtf8().data());
QTorrentHandle h = getTorrentHandle(hash);
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits");
if(!speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -633,12 +635,11 @@ void bittorrent::loadFilesPriorities(QTorrentHandle &h) { @@ -633,12 +635,11 @@ void bittorrent::loadFilesPriorities(QTorrentHandle &h) {
QString hash = h.hash();
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".priorities");
if(!pieces_file.exists()){
qDebug("Info: priorities file does not exist for %s", hash.toUtf8().data());
return;
}
// Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug("* Error: Couldn't open priorities file: %s");
qDebug("* Error: Couldn't open priorities file: %s", hash.toUtf8().data());
return;
}
QByteArray pieces_priorities = pieces_file.readAll();
@ -667,9 +668,9 @@ void bittorrent::loadDownloadUploadForTorrent(QString hash) { @@ -667,9 +668,9 @@ void bittorrent::loadDownloadUploadForTorrent(QString hash) {
if(! torrentBackup.exists()) {
torrentBackup.mkpath(torrentBackup.path());
}
qDebug("Loading ratio data for %s", hash.toUtf8().data());
// qDebug("Loading ratio data for %s", hash.toUtf8().data());
QFile ratio_file(torrentBackup.path()+QDir::separator()+ hash + ".ratio");
if(!ratio_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
if(!ratio_file.exists() || !ratio_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return;
}
QByteArray data = ratio_file.readAll();
@ -1105,7 +1106,6 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) { @@ -1105,7 +1106,6 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) {
fullAllocationModeList << hash;
}
qDebug("Reloading torrent: %s", fileName.toUtf8().data());
QTorrentHandle new_h;
entry resumeData;
// Checking if torrentBackup Dir exists
// create it if it is not
@ -1128,7 +1128,7 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) { @@ -1128,7 +1128,7 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) {
SleeperThread::msleep(1000);
++timeout;
}
new_h = s->add_torrent(t, saveDir, resumeData, false);
QTorrentHandle new_h = s->add_torrent(t, saveDir, resumeData, false);
qDebug("Using full allocation mode");
new_h.set_max_uploads(-1);
@ -1174,7 +1174,7 @@ QString bittorrent::getSavePath(QString hash) { @@ -1174,7 +1174,7 @@ QString bittorrent::getSavePath(QString hash) {
if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
line = savepath_file.readAll();
savepath_file.close();
qDebug("Save path: %s", line.data());
qDebug(" -> Save path: %s", line.data());
savePath = QString::fromUtf8(line.data());
}else{
// use default save path

3
src/previewSelect.h

@ -91,7 +91,7 @@ class previewSelect: public QDialog, private Ui::preview { @@ -91,7 +91,7 @@ class previewSelect: public QDialog, private Ui::preview {
}
public:
previewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent){
previewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent), h(h){
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
// Preview list
@ -105,7 +105,6 @@ class previewSelect: public QDialog, private Ui::preview { @@ -105,7 +105,6 @@ class previewSelect: public QDialog, private Ui::preview {
supported_preview_extensions << QString::fromUtf8("AVI") << QString::fromUtf8("DIVX") << QString::fromUtf8("MPG") << QString::fromUtf8("MPEG") << QString::fromUtf8("MPE") << QString::fromUtf8("MP3") << QString::fromUtf8("OGG") << QString::fromUtf8("WMV") << QString::fromUtf8("WMA") << QString::fromUtf8("RMV") << QString::fromUtf8("RMVB") << QString::fromUtf8("ASF") << QString::fromUtf8("MOV") << QString::fromUtf8("WAV") << QString::fromUtf8("MP2") << QString::fromUtf8("SWF") << QString::fromUtf8("AC3") << QString::fromUtf8("OGM") << QString::fromUtf8("MP4") << QString::fromUtf8("FLV") << QString::fromUtf8("VOB") << QString::fromUtf8("QT") << QString::fromUtf8("MKV") << QString::fromUtf8("AIF") << QString::fromUtf8("AIFF") << QString::fromUtf8("AIFC") << QString::fromUtf8("MID") << QString::fromUtf8("MPG") << QString::fromUtf8("RA") << QString::fromUtf8("RAM") << QString::fromUtf8("AU") << QString::fromUtf8("M4A") << QString::fromUtf8("FLAC") << QString::fromUtf8("M4P") << QString::fromUtf8("3GP") << QString::fromUtf8("AAC") << QString::fromUtf8("RM") << QString::fromUtf8("SWA") << QString::fromUtf8("MPC") << QString::fromUtf8("MPP");
previewList->header()->resizeSection(0, 200);
// Fill list in
this->h = h;
std::vector<float> fp;
h.file_progress(fp);
unsigned int nbFiles = h.num_files();

116
src/qtorrenthandle.cpp

@ -27,82 +27,96 @@ @@ -27,82 +27,96 @@
#include "misc.h"
#include "qtorrenthandle.h"
QTorrentHandle::QTorrentHandle(torrent_handle h) : h(h) {
t = h.get_torrent_info();
s = h.status();
}
QTorrentHandle::QTorrentHandle(torrent_handle h): h(h) {}
//
// Getters
//
torrent_handle QTorrentHandle::get_torrent_handle() const {
Q_ASSERT(h.is_valid());
return h;
}
torrent_info QTorrentHandle::get_torrent_info() const {
return t;
Q_ASSERT(h.is_valid());
return h.get_torrent_info();
}
QString QTorrentHandle::hash() const {
return misc::toQString(t.info_hash());
Q_ASSERT(h.is_valid());
return misc::toQString(h.get_torrent_info().info_hash());
}
QString QTorrentHandle::name() const {
Q_ASSERT(h.is_valid());
return misc::toQString(h.name());
}
float QTorrentHandle::progress() const {
return s.progress;
Q_ASSERT(h.is_valid());
return h.status().progress;
}
QString QTorrentHandle::current_tracker() const {
return misc::toQString(s.current_tracker);
Q_ASSERT(h.is_valid());
return misc::toQString(h.status().current_tracker);
}
bool QTorrentHandle::is_valid() const {
Q_ASSERT(h.is_valid());
return h.is_valid();
}
bool QTorrentHandle::is_paused() const {
Q_ASSERT(h.is_valid());
return h.is_paused();
}
size_type QTorrentHandle::total_size() const {
return t.total_size();
Q_ASSERT(h.is_valid());
return h.get_torrent_info().total_size();
}
size_type QTorrentHandle::total_done() const {
return s.total_done;
Q_ASSERT(h.is_valid());
return h.status().total_done;
}
float QTorrentHandle::download_payload_rate() const {
return s.download_payload_rate;
Q_ASSERT(h.is_valid());
return h.status().download_payload_rate;
}
float QTorrentHandle::upload_payload_rate() const {
return s.upload_payload_rate;
Q_ASSERT(h.is_valid());
return h.status().upload_payload_rate;
}
int QTorrentHandle::num_peers() const {
return s.num_peers;
Q_ASSERT(h.is_valid());
return h.status().num_peers;
}
int QTorrentHandle::num_seeds() const {
return s.num_seeds;
Q_ASSERT(h.is_valid());
return h.status().num_seeds;
}
QString QTorrentHandle::save_path() const {
Q_ASSERT(h.is_valid());
return misc::toQString(h.save_path().string());
}
fs::path QTorrentHandle::save_path_boost() const {
Q_ASSERT(h.is_valid());
return h.save_path();
}
QStringList QTorrentHandle::url_seeds() const {
Q_ASSERT(h.is_valid());
QStringList res;
std::vector<std::string> existing_seeds = t.url_seeds();
std::vector<std::string> existing_seeds = h.get_torrent_info().url_seeds();
unsigned int nbSeeds = existing_seeds.size();
QString existing_seed;
for(unsigned int i=0; i<nbSeeds; ++i){
@ -113,24 +127,24 @@ QStringList QTorrentHandle::url_seeds() const { @@ -113,24 +127,24 @@ QStringList QTorrentHandle::url_seeds() const {
// get the size of the torrent without the filtered files
size_type QTorrentHandle::actual_size() const{
unsigned int nbFiles = t.num_files();
Q_ASSERT(h.is_valid());
unsigned int nbFiles = h.get_torrent_info().num_files();
if(!h.is_valid()){
qDebug("/!\\ Error: Invalid handle");
return t.total_size();
return h.get_torrent_info().total_size();
}
QString hash = misc::toQString(t.info_hash());
QString hash = misc::toQString(h.get_torrent_info().info_hash());
QFile pieces_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".priorities"));
// Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug("* Error: Couldn't open priorities file");
return t.total_size();
return h.get_torrent_info().total_size();
}
QByteArray pieces_priorities = pieces_file.readAll();
pieces_file.close();
QList<QByteArray> pieces_priorities_list = pieces_priorities.split('\n');
if((unsigned int)pieces_priorities_list.size() != nbFiles+1){
std::cerr << "* Error: Corrupted priorities file\n";
return t.total_size();
return h.get_torrent_info().total_size();
}
size_type effective_size = 0;
for(unsigned int i=0; i<nbFiles; ++i){
@ -139,78 +153,94 @@ size_type QTorrentHandle::actual_size() const{ @@ -139,78 +153,94 @@ size_type QTorrentHandle::actual_size() const{
priority = 1;
}
if(priority)
effective_size += t.file_at(i).size;
effective_size += h.get_torrent_info().file_at(i).size;
}
return effective_size;
}
int QTorrentHandle::download_limit() const {
Q_ASSERT(h.is_valid());
return h.download_limit();
}
int QTorrentHandle::upload_limit() const {
Q_ASSERT(h.is_valid());
return h.upload_limit();
}
int QTorrentHandle::num_files() const {
return t.num_files();
Q_ASSERT(h.is_valid());
return h.get_torrent_info().num_files();
}
bool QTorrentHandle::has_metadata() const {
Q_ASSERT(h.is_valid());
return h.has_metadata();
}
entry QTorrentHandle::write_resume_data() const {
Q_ASSERT(h.is_valid());
return h.write_resume_data();
}
QString QTorrentHandle::file_at(int index) const {
return misc::toQString(t.file_at(index).path.leaf());
Q_ASSERT(h.is_valid());
return misc::toQString(h.get_torrent_info().file_at(index).path.leaf());
}
size_type QTorrentHandle::filesize_at(int index) const {
return t.file_at(index).size;
Q_ASSERT(h.is_valid());
return h.get_torrent_info().file_at(index).size;
}
std::vector<announce_entry> const& QTorrentHandle::trackers() const {
Q_ASSERT(h.is_valid());
return h.trackers();
}
torrent_status::state_t QTorrentHandle::state() const {
return s.state;
Q_ASSERT(h.is_valid());
return h.status().state;
}
QString QTorrentHandle::creator() const {
return misc::toQString(t.creator());
Q_ASSERT(h.is_valid());
return misc::toQString(h.get_torrent_info().creator());
}
QString QTorrentHandle::comment() const {
return misc::toQString(t.comment());
Q_ASSERT(h.is_valid());
return misc::toQString(h.get_torrent_info().comment());
}
size_type QTorrentHandle::total_failed_bytes() const {
return s.total_failed_bytes;
Q_ASSERT(h.is_valid());
return h.status().total_failed_bytes;
}
void QTorrentHandle::file_progress(std::vector<float>& fp) {
Q_ASSERT(h.is_valid());
return h.file_progress(fp);
}
size_type QTorrentHandle::total_payload_download() {
return s.total_payload_download;
Q_ASSERT(h.is_valid());
return h.status().total_payload_download;
}
size_type QTorrentHandle::total_payload_upload() {
return s.total_payload_upload;
Q_ASSERT(h.is_valid());
return h.status().total_payload_upload;
}
// Return a list of absolute paths corresponding
// to all files in a torrent
QStringList QTorrentHandle::files_path() const {
Q_ASSERT(h.is_valid());
QString saveDir = misc::toQString(h.save_path().string()) + QDir::separator();
QStringList res;
torrent_info::file_iterator fi = t.begin_files();
while(fi != t.end_files()) {
torrent_info::file_iterator fi = h.get_torrent_info().begin_files();
while(fi != h.get_torrent_info().end_files()) {
res << QDir::cleanPath(saveDir + misc::toQString(fi->path.string()));
fi++;
}
@ -218,7 +248,8 @@ QStringList QTorrentHandle::files_path() const { @@ -218,7 +248,8 @@ QStringList QTorrentHandle::files_path() const {
}
int QTorrentHandle::num_uploads() const {
return s.num_uploads;
Q_ASSERT(h.is_valid());
return h.status().num_uploads;
}
//
@ -226,54 +257,67 @@ int QTorrentHandle::num_uploads() const { @@ -226,54 +257,67 @@ int QTorrentHandle::num_uploads() const {
//
void QTorrentHandle::set_download_limit(int limit) {
Q_ASSERT(h.is_valid());
h.set_download_limit(limit);
}
void QTorrentHandle::set_upload_limit(int limit) {
Q_ASSERT(h.is_valid());
h.set_upload_limit(limit);
}
void QTorrentHandle::pause() {
Q_ASSERT(h.is_valid());
h.pause();
}
void QTorrentHandle::resume() {
Q_ASSERT(h.is_valid());
h.resume();
}
void QTorrentHandle::remove_url_seed(QString seed) {
Q_ASSERT(h.is_valid());
h.remove_url_seed(misc::toString((const char*)seed.toUtf8()));
}
void QTorrentHandle::add_url_seed(QString seed) {
Q_ASSERT(h.is_valid());
h.add_url_seed(misc::toString((const char*)seed.toUtf8()));
}
void QTorrentHandle::set_max_uploads(int val){
Q_ASSERT(h.is_valid());
h.set_max_uploads(val);
}
void QTorrentHandle::prioritize_files(std::vector<int> v) {
Q_ASSERT(h.is_valid());
h.prioritize_files(v);
}
void QTorrentHandle::set_ratio(float ratio) const {
Q_ASSERT(h.is_valid());
h.set_ratio(ratio);
}
void QTorrentHandle::replace_trackers(std::vector<announce_entry> const& v) const {
Q_ASSERT(h.is_valid());
h.replace_trackers(v);
}
void QTorrentHandle::force_reannounce() {
Q_ASSERT(h.is_valid());
h.force_reannounce();
}
void QTorrentHandle::set_sequenced_download_threshold(int val) {
Q_ASSERT(h.is_valid());
h.set_sequenced_download_threshold(val);
}
void QTorrentHandle::set_tracker_login(QString username, QString password){
Q_ASSERT(h.is_valid());
h.set_tracker_login(std::string(username.toUtf8().data()), std::string(password.toUtf8().data()));
}
@ -283,12 +327,10 @@ void QTorrentHandle::set_tracker_login(QString username, QString password){ @@ -283,12 +327,10 @@ void QTorrentHandle::set_tracker_login(QString username, QString password){
QTorrentHandle& QTorrentHandle::operator =(const torrent_handle& new_h) {
h = new_h;
t = h.get_torrent_info();
s = h.status();
return *this;
}
bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const{
QString hash = misc::toQString(t.info_hash());
QString hash = misc::toQString(h.get_torrent_info().info_hash());
return (hash == new_h.hash());
}

3
src/qtorrenthandle.h

@ -34,8 +34,6 @@ class QStringList; @@ -34,8 +34,6 @@ class QStringList;
class QTorrentHandle {
private:
torrent_handle h;
torrent_info t;
torrent_status s;
public:
@ -107,7 +105,6 @@ class QTorrentHandle { @@ -107,7 +105,6 @@ class QTorrentHandle {
//
// Operators
//
QTorrentHandle& operator =(const torrent_handle& new_h);
bool operator ==(const QTorrentHandle& new_h) const;
};

3
src/trackerLogin.h

@ -37,11 +37,10 @@ class trackerLogin : public QDialog, private Ui::authentication{ @@ -37,11 +37,10 @@ class trackerLogin : public QDialog, private Ui::authentication{
QTorrentHandle h;
public:
trackerLogin(QWidget *parent, QTorrentHandle h): QDialog(parent){
trackerLogin(QWidget *parent, QTorrentHandle h): QDialog(parent), h(h){
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
login_logo->setPixmap(QPixmap(QString::fromUtf8(":/Icons/encrypted.png")));
this->h = h;
tracker_url->setText(h.current_tracker());
connect(this, SIGNAL(trackerLoginCancelled(QPair<QTorrentHandle,QString>)), parent, SLOT(addUnauthenticatedTracker(QPair<QTorrentHandle,QString>)));
show();

Loading…
Cancel
Save