diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 666f00fdb..4626a1d13 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -590,10 +590,15 @@ void MainWindow::handleDownloadFromUrlFailure(QString url, QString reason) const void MainWindow::on_actionSet_global_upload_limit_triggered() { qDebug("actionSet_global_upload_limit_triggered"); bool ok; - const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), QBtSession::instance()->getSession()->upload_rate_limit()); +#if LIBTORRENT_VERSION_MINOR > 15 + int cur_limit = QBtSession::instance()->getSession()->settings().upload_rate_limit; +#else + int cur_limit = QBtSession::instance()->getSession()->upload_rate_limit(); +#endif + const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), cur_limit); if(ok) { qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); - QBtSession::instance()->getSession()->set_upload_rate_limit(new_limit); + QBtSession::instance()->setUploadRateLimit(new_limit); if(new_limit <= 0) Preferences().setGlobalUploadLimit(-1); else @@ -604,10 +609,15 @@ void MainWindow::on_actionSet_global_upload_limit_triggered() { void MainWindow::on_actionSet_global_download_limit_triggered() { qDebug("actionSet_global_download_limit_triggered"); bool ok; - const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), QBtSession::instance()->getSession()->download_rate_limit()); +#if LIBTORRENT_VERSION_MINOR > 15 + int cur_limit = QBtSession::instance()->getSession()->settings().download_rate_limit; +#else + int cur_limit = QBtSession::instance()->getSession()->download_rate_limit(); +#endif + const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), cur_limit); if(ok) { qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); - QBtSession::instance()->getSession()->set_download_rate_limit(new_limit); + QBtSession::instance()->setDownloadRateLimit(new_limit); if(new_limit <= 0) Preferences().setGlobalDownloadLimit(-1); else diff --git a/src/misc.cpp b/src/misc.cpp index 6592449d4..69c857336 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -356,23 +356,29 @@ QString misc::fixFileNames(QString path) { QString misc::truncateRootFolder(boost::intrusive_ptr t) { if(t->num_files() == 1) { // Single file torrent +#if LIBTORRENT_VERSION_MINOR > 15 + QString path = QString::fromUtf8(t->file_at(0).path.c_str()); +#else QString path = QString::fromUtf8(t->file_at(0).path.string().c_str()); +#endif // Remove possible subfolders path = fixFileNames(fileName(path)); t->rename_file(0, path.toUtf8().data()); return QString(); } QString root_folder; - int i = 0; - for(torrent_info::file_iterator it = t->begin_files(); it < t->end_files(); it++) { - QString path = QString::fromUtf8(it->path.string().c_str()); + for(int i=0; inum_files(); ++i) { +#if LIBTORRENT_VERSION_MINOR > 15 + QString path = QString::fromUtf8(t->file_at(i).path.c_str()); +#else + QString path = QString::fromUtf8(t->file_at(i).path.string().c_str()); +#endif QStringList path_parts = path.split("/", QString::SkipEmptyParts); if(path_parts.size() > 1) { root_folder = path_parts.takeFirst(); } path = fixFileNames(path_parts.join("/")); t->rename_file(i, path.toUtf8().data()); - ++i; } return root_folder; } @@ -382,22 +388,28 @@ QString misc::truncateRootFolder(libtorrent::torrent_handle h) { if(t.num_files() == 1) { // Single file torrent // Remove possible subfolders +#if LIBTORRENT_VERSION_MINOR > 15 + QString path = QString::fromUtf8(t.file_at(0).path.c_str()); +#else QString path = QString::fromUtf8(t.file_at(0).path.string().c_str()); +#endif path = fixFileNames(fileName(path)); t.rename_file(0, path.toUtf8().data()); return QString(); } QString root_folder; - int i = 0; - for(torrent_info::file_iterator it = t.begin_files(); it < t.end_files(); it++) { - QString path = QString::fromUtf8(it->path.string().c_str()); + for(int i=0; i 15 + QString path = QString::fromUtf8(t.file_at(i).path.c_str()); +#else + QString path = QString::fromUtf8(t.file_at(i).path.string().c_str()); +#endif QStringList path_parts = path.split("/", QString::SkipEmptyParts); if(path_parts.size() > 1) { root_folder = path_parts.takeFirst(); } path = fixFileNames(path_parts.join("/")); h.rename_file(i, path.toUtf8().data()); - ++i; } return root_folder; } diff --git a/src/misc.h b/src/misc.h index 72927bcae..09184b698 100644 --- a/src/misc.h +++ b/src/misc.h @@ -31,6 +31,9 @@ #ifndef MISC_H #define MISC_H +#include +#include +#include #include #include #include @@ -45,9 +48,6 @@ #include #endif -#include -#include - const qlonglong MAX_ETA = 8640000; /* Miscellaneaous functions that can be useful */ @@ -104,8 +104,9 @@ public: static inline QString file_extension(const QString &filename) { QString extension; - if(filename.contains(".")) { - extension = filename.mid(filename.lastIndexOf(".")+1); + int point_index = filename.lastIndexOf("."); + if(point_index >= 0) { + extension = filename.mid(point_index+1); } return extension; } diff --git a/src/previewselect.cpp b/src/previewselect.cpp index 2e42774ab..d5f3ddd68 100644 --- a/src/previewselect.cpp +++ b/src/previewselect.cpp @@ -102,7 +102,7 @@ void PreviewSelect::on_previewButton_clicked(){ #endif QString path; foreach(index, selectedIndexes){ - path = h.files_path().at(indexes.at(index.row())); + path = h.absolute_files_path().at(indexes.at(index.row())); // File if(QFile::exists(path)){ emit readyToPreviewFile(path); diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index c2ec88851..aaca8ab81 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -474,7 +474,11 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&){ myFilesLlistMenu.addSeparator(); } QMenu subMenu; +#if LIBTORRENT_VERSION_MINOR > 15 + if(!h.status(0x0).is_seeding) { +#else if(!static_cast(h).is_seed()) { +#endif subMenu.setTitle(tr("Priority")); subMenu.addAction(actionNot_downloaded); subMenu.addAction(actionNormal); diff --git a/src/properties/proplistdelegate.h b/src/properties/proplistdelegate.h index 0c740bd7d..6169e1505 100644 --- a/src/properties/proplistdelegate.h +++ b/src/properties/proplistdelegate.h @@ -74,51 +74,51 @@ public: QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); break; case PROGRESS:{ - QStyleOptionProgressBarV2 newopt; - qreal progress = index.data().toDouble()*100.; - newopt.rect = opt.rect; - // We don't want to display 100% unless - // the torrent is really complete - if(progress > 99.94 && progress < 100.) - progress = 99.9; - newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%"); - newopt.progress = (int)progress; - newopt.maximum = 100; - newopt.minimum = 0; - newopt.state |= QStyle::State_Enabled; - newopt.textVisible = true; + QStyleOptionProgressBarV2 newopt; + qreal progress = index.data().toDouble()*100.; + newopt.rect = opt.rect; + // We don't want to display 100% unless + // the torrent is really complete + if(progress > 99.94 && progress < 100.) + progress = 99.9; + newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%"); + newopt.progress = (int)progress; + newopt.maximum = 100; + newopt.minimum = 0; + newopt.state |= QStyle::State_Enabled; + newopt.textVisible = true; #ifndef Q_WS_WIN - QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); + QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); #else - // XXX: To avoid having the progress text on the right of the bar - QPlastiqueStyle st; - st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); + // XXX: To avoid having the progress text on the right of the bar + QPlastiqueStyle st; + st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); #endif - break; - } + break; + } case PRIORITY: { - QItemDelegate::drawBackground(painter, opt, index); - QString text = ""; - switch(index.data().toInt()) { - case -1: - text = tr("Mixed", "Mixed (priorities"); - break; - case 0: - text = tr("Not downloaded"); - break; - case 2: - text = tr("High", "High (priority)"); - break; - case 7: - text = tr("Maximum", "Maximum (priority)"); - break; - default: - text = tr("Normal", "Normal (priority)"); - break; - } - QItemDelegate::drawDisplay(painter, opt, option.rect, text); + QItemDelegate::drawBackground(painter, opt, index); + QString text = ""; + switch(index.data().toInt()) { + case -1: + text = tr("Mixed", "Mixed (priorities"); + break; + case 0: + text = tr("Not downloaded"); + break; + case 2: + text = tr("High", "High (priority)"); + break; + case 7: + text = tr("Maximum", "Maximum (priority)"); + break; + default: + text = tr("Normal", "Normal (priority)"); break; } + QItemDelegate::drawDisplay(painter, opt, option.rect, text); + break; + } default: QItemDelegate::paint(painter, option, index); break; @@ -156,7 +156,11 @@ public: if(index.column() != PRIORITY) return 0; if(properties) { QTorrentHandle h = properties->getCurrentTorrent(); - if(!h.is_valid() || static_cast(h).is_seed() || !h.has_metadata()) return 0; +#if LIBTORRENT_VERSION_MINOR > 15 + if(!h.is_valid() || !h.has_metadata() || h.status(0x0).is_seeding) return 0; +#else + if(!h.is_valid() || !h.has_metadata() || static_cast(h).is_seed()) return 0; +#endif } if(index.data().toInt() <= 0) { // IGNORED or MIXED diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index ccb8cb1b9..383019ac0 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -65,6 +65,7 @@ //#include #include #include +#include #include #include #include @@ -376,7 +377,7 @@ void QBtSession::configureSession() { addConsoleMessage(tr("UPnP / NAT-PMP support [OFF]"), QString::fromUtf8("blue")); } // * Session settings - session_settings sessionSettings; + session_settings sessionSettings = s->settings(); sessionSettings.user_agent = "qBittorrent "VERSION; std::cout << "HTTP user agent is " << sessionSettings.user_agent << std::endl; addConsoleMessage(tr("HTTP user agent is %1").arg(misc::toQString(sessionSettings.user_agent))); @@ -734,7 +735,7 @@ void QBtSession::deleteTorrent(const QString &hash, bool delete_local_files) { } else { QStringList uneeded_files; if(h.has_metadata()) - uneeded_files = h.uneeded_files_path(); + uneeded_files = h.absolute_files_path_uneeded(); s->remove_torrent(h); // Remove unneeded and incomplete files foreach(const QString &uneeded_file, uneeded_files) { @@ -1217,7 +1218,7 @@ void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool m bool force_recheck = false; if(files_path.size() == h.num_files()) { for(int i=0; i 15 + std::vector new_urlseeds = t->web_seeds(); + std::vector::iterator it; + for(it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) { + const QString new_url = misc::toQString(it->url.c_str()); + if(!old_urlseeds.contains(new_url)) { + urlseeds_added = true; + h_ex.add_url_seed(new_url); + } + } +#else std::vector new_urlseeds = t->url_seeds(); - for(std::vector::iterator it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) { + std::vector::iterator it; + for(it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) { const QString new_url = misc::toQString(it->c_str()); if(!old_urlseeds.contains(new_url)) { urlseeds_added = true; h_ex.add_url_seed(new_url); } } +#endif if(urlseeds_added) { addConsoleMessage(tr("Note: new URL seeds were added to the existing torrent.")); } @@ -1325,8 +1339,13 @@ void QBtSession::exportTorrentFiles(QString path) { // Set the maximum number of opened connections void QBtSession::setMaxConnections(int maxConnec) { +#if LIBTORRENT_VERSION_MINOR > 15 + Q_UNUSED(maxConnec); + Q_ASSERT(0); // Should not be used +#else qDebug() << Q_FUNC_INFO << maxConnec; s->set_max_connections(maxConnec); +#endif } void QBtSession::setMaxConnectionsPerTorrent(int max) { @@ -1416,8 +1435,15 @@ void QBtSession::loadSessionState() { state_file.read(&in[0], content_size); // bdecode lazy_entry e; - if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) +#if LIBTORRENT_VERSION_MINOR > 15 + error_code ec; + lazy_bdecode(&in[0], &in[0] + in.size(), e, ec); + if(!ec) { +#else + if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) { +#endif s->load_state(e); + } #else boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData() , std::ios_base::binary); @@ -1785,9 +1811,16 @@ void QBtSession::setAppendqBExtension(bool append) { void QBtSession::setListeningPort(int port) { Preferences pref; std::pair ports(port, port); +#if LIBTORRENT_VERSION_MINOR > 15 + error_code ec; +#endif const QString iface_name = pref.getNetworkInterface(); if(iface_name.isEmpty()) { +#if LIBTORRENT_VERSION_MINOR > 15 + s->listen_on(ports, ec); +#else s->listen_on(ports); +#endif return; } // Attempt to listen on provided interface @@ -1796,14 +1829,23 @@ void QBtSession::setListeningPort(int port) { qDebug("Invalid network interface: %s", qPrintable(iface_name)); addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red"); addConsoleMessage(tr("Trying any other network interface available instead.")); +#if LIBTORRENT_VERSION_MINOR > 15 + s->listen_on(ports, ec); +#else s->listen_on(ports); +#endif return; } QString ip; qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size()); foreach(const QNetworkAddressEntry &entry, network_iface.addressEntries()) { qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name)); +#if LIBTORRENT_VERSION_MINOR > 15 + s->listen_on(ports, ec, entry.ip().toString().toAscii().constData()); + if(!ec) { +#else if(s->listen_on(ports, entry.ip().toString().toAscii().constData())) { +#endif ip = entry.ip().toString(); break; } @@ -1821,7 +1863,13 @@ void QBtSession::setListeningPort(int port) { void QBtSession::setDownloadRateLimit(long rate) { qDebug() << Q_FUNC_INFO << rate; Q_ASSERT(rate == -1 || rate >= 0); +#if LIBTORRENT_VERSION_MINOR > 15 + session_settings settings = s->settings(); + settings.download_rate_limit = rate; + s->set_settings(settings); +#else s->set_download_rate_limit(rate); +#endif } // Set upload rate limit @@ -1829,7 +1877,13 @@ void QBtSession::setDownloadRateLimit(long rate) { void QBtSession::setUploadRateLimit(long rate) { qDebug() << Q_FUNC_INFO << rate; Q_ASSERT(rate == -1 || rate >= 0); +#if LIBTORRENT_VERSION_MINOR > 15 + session_settings settings = s->settings(); + settings.upload_rate_limit = rate; + s->set_settings(settings); +#else s->set_upload_rate_limit(rate); +#endif } // Torrents will a ratio superior to the given value will @@ -1985,9 +2039,8 @@ void QBtSession::setProxySettings(const proxy_settings &proxySettings) { void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) { try { - torrent_info::file_iterator it; - for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) { - const QString torrent_relpath = h.filepath(*it); + for(int i=0; i= 16 +#if LIBTORRENT_VERSION_MINOR > 15 boost::optional t = torrent_handle::get_torrent_info().creation_date(); return misc::time_tToQString(t); #else @@ -81,35 +81,56 @@ QString QTorrentHandle::creation_date() const { } QString QTorrentHandle::next_announce() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return misc::userFriendlyDuration(torrent_handle::status(0x0).next_announce.total_seconds()); +#else return misc::userFriendlyDuration(torrent_handle::status().next_announce.total_seconds()); +#endif } qlonglong QTorrentHandle::next_announce_s() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).next_announce.total_seconds(); +#else return torrent_handle::status().next_announce.total_seconds(); +#endif } qreal QTorrentHandle::progress() const { - if(!torrent_handle::status().total_wanted) +#if LIBTORRENT_VERSION_MINOR > 15 + torrent_status st = torrent_handle::status(query_accurate_download_counters); +#else + torrent_status st = torrent_handle::status(); +#endif + if(!st.total_wanted) return 0.; - if (torrent_handle::status().total_wanted_done == torrent_handle::status().total_wanted) + if (st.total_wanted_done == st.total_wanted) return 1.; - qreal progress = (float)torrent_handle::status().total_wanted_done/(float)torrent_handle::status().total_wanted; + qreal progress = (float)st.total_wanted_done/(float)st.total_wanted; Q_ASSERT(progress >= 0. && progress <= 1.); return progress; } bitfield QTorrentHandle::pieces() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).pieces; +#else return torrent_handle::status().pieces; +#endif } QString QTorrentHandle::current_tracker() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return misc::toQString(torrent_handle::status(0x0).current_tracker); +#else return misc::toQString(torrent_handle::status().current_tracker); +#endif } bool QTorrentHandle::is_paused() const { #if LIBTORRENT_VERSION_MINOR > 15 - torrent_status status = torrent_handle::status(0x0); - return status.paused && !status.auto_managed; + torrent_status st = torrent_handle::status(0x0); + return st.paused && !st.auto_managed; #else return torrent_handle::is_paused() && !torrent_handle::is_auto_managed(); #endif @@ -117,8 +138,8 @@ bool QTorrentHandle::is_paused() const { bool QTorrentHandle::is_queued() const { #if LIBTORRENT_VERSION_MINOR > 15 - torrent_status status = torrent_handle::status(0x0); - return status.paused && status.auto_managed; + torrent_status st = torrent_handle::status(0x0); + return st.paused && st.auto_managed; #else return torrent_handle::is_paused() && torrent_handle::is_auto_managed(); #endif @@ -138,10 +159,14 @@ int QTorrentHandle::num_pieces() const { bool QTorrentHandle::first_last_piece_first() const { // Detect first media file - torrent_info::file_iterator it; int index = 0; - for(it = get_torrent_info().begin_files(); it != get_torrent_info().end_files(); it++) { - const QString ext = misc::toQStringU(it->path.string()).split(".").last(); + for(index = 0; index < num_files(); ++index) { +#if LIBTORRENT_VERSION_MINOR > 15 + QString path = misc::toQStringU(get_torrent_info().file_at(index).path); +#else + QString path = misc::toQStringU(get_torrent_info().file_at(index).path.string()); +#endif + const QString ext = misc::file_extension(path); if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) { break; } @@ -162,35 +187,67 @@ bool QTorrentHandle::first_last_piece_first() const { } size_type QTorrentHandle::total_wanted_done() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(query_accurate_download_counters).total_wanted_done; +#else return torrent_handle::status().total_wanted_done; +#endif } size_type QTorrentHandle::total_wanted() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).total_wanted; +#else return torrent_handle::status().total_wanted; +#endif } qreal QTorrentHandle::download_payload_rate() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).download_payload_rate; +#else return torrent_handle::status().download_payload_rate; +#endif } qreal QTorrentHandle::upload_payload_rate() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).upload_payload_rate; +#else return torrent_handle::status().upload_payload_rate; +#endif } int QTorrentHandle::num_peers() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).num_peers; +#else return torrent_handle::status().num_peers; +#endif } int QTorrentHandle::num_seeds() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).num_seeds; +#else return torrent_handle::status().num_seeds; +#endif } int QTorrentHandle::num_complete() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).num_complete; +#else return torrent_handle::status().num_complete; +#endif } int QTorrentHandle::num_incomplete() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).num_incomplete; +#else return torrent_handle::status().num_incomplete; +#endif } QString QTorrentHandle::save_path() const { @@ -217,8 +274,12 @@ 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 { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(query_accurate_download_counters).total_wanted; +#else return torrent_handle::status().total_wanted; +#endif } bool QTorrentHandle::has_filtered_pieces() const { @@ -247,19 +308,9 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const { return torrent_handle::get_torrent_info().file_at(index).size; } -QString QTorrentHandle::filepath(const libtorrent::file_entry &fe) const { -#if LIBTORRENT_VERSION_MINOR > 15 - file_storage fs = torrent_handle::get_torrent_info().files(); - return misc::toQStringU(fs.file_path(fe)); -#else - return misc::toQStringU(fe.path.string()); -#endif -} - QString QTorrentHandle::filepath_at(unsigned int index) const { #if LIBTORRENT_VERSION_MINOR > 15 - file_storage fs = torrent_handle::get_torrent_info().files(); - return misc::toQStringU(fs.file_path(fs.at(index))); + return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path); #else return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.string()); #endif @@ -267,15 +318,18 @@ QString QTorrentHandle::filepath_at(unsigned int index) const { QString QTorrentHandle::orig_filepath_at(unsigned int index) const { #if LIBTORRENT_VERSION_MINOR > 15 - file_storage fs = torrent_handle::get_torrent_info().orig_files(); - return misc::toQStringU(fs.file_path(fs.at(index))); + return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().at(index).path); #else return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().at(index).path.string()); #endif } torrent_status::state_t QTorrentHandle::state() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).state; +#else return torrent_handle::status().state; +#endif } QString QTorrentHandle::creator() const { @@ -287,70 +341,98 @@ QString QTorrentHandle::comment() const { } size_type QTorrentHandle::total_failed_bytes() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).total_failed_bytes; +#else return torrent_handle::status().total_failed_bytes; +#endif } size_type QTorrentHandle::total_redundant_bytes() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).total_redundant_bytes; +#else return torrent_handle::status().total_redundant_bytes; +#endif } bool QTorrentHandle::is_checking() const { - return torrent_handle::status().state == torrent_status::checking_files || torrent_handle::status().state == torrent_status::checking_resume_data; +#if LIBTORRENT_VERSION_MINOR > 15 + torrent_status st = torrent_handle::status(0x0); +#else + torrent_status st = torrent_handle::status(); +#endif + return st.state == torrent_status::checking_files || st.state == torrent_status::checking_resume_data; } size_type QTorrentHandle::total_done() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).total_done; +#else return torrent_handle::status().total_done; +#endif } size_type QTorrentHandle::all_time_download() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).all_time_download; +#else return torrent_handle::status().all_time_download; +#endif } size_type QTorrentHandle::all_time_upload() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).all_time_upload; +#else return torrent_handle::status().all_time_upload; +#endif } size_type QTorrentHandle::total_payload_download() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).total_payload_download; +#else return torrent_handle::status().total_payload_download; +#endif } size_type QTorrentHandle::total_payload_upload() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).total_payload_upload; +#else return torrent_handle::status().total_payload_upload; +#endif } // Return a list of absolute paths corresponding // to all files in a torrent -QStringList QTorrentHandle::files_path() const { +QStringList QTorrentHandle::absolute_files_path() const { QDir saveDir(save_path()); QStringList res; - torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files(); - while(fi != torrent_handle::get_torrent_info().end_files()) { - res << QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi))); - fi++; + for(int i = 0; i fp = torrent_handle::file_priorities(); torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files(); - int i = 0; - while(fi != torrent_handle::get_torrent_info().end_files()) { + for(int i = 0; i < num_files(); ++i) { if(fp[i] == 0) { - const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi))); + const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i))); if(file_path.contains(".unwanted")) res << file_path; } - fi++; - ++i; } return res; } bool QTorrentHandle::has_missing_files() const { - const QStringList paths = files_path(); + const QStringList paths = absolute_files_path(); foreach(const QString &path, paths) { if(!QFile::exists(path)) return true; } @@ -364,7 +446,11 @@ int QTorrentHandle::queue_position() const { } int QTorrentHandle::num_uploads() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).num_uploads; +#else return torrent_handle::status().num_uploads; +#endif } bool QTorrentHandle::is_seed() const { @@ -377,23 +463,44 @@ bool QTorrentHandle::is_seed() const { } bool QTorrentHandle::is_auto_managed() const { +#if LIBTORRENT_VERSION_MINOR > 15 + torrent_status status = torrent_handle::status(0x0); + return status.auto_managed; +#else return torrent_handle::is_auto_managed(); +#endif } qlonglong QTorrentHandle::active_time() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).active_time; +#else return torrent_handle::status().active_time; +#endif } qlonglong QTorrentHandle::seeding_time() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).seeding_time; +#else return torrent_handle::status().seeding_time; +#endif } int QTorrentHandle::num_connections() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).num_connections; +#else return torrent_handle::status().num_connections; +#endif } int QTorrentHandle::connections_limit() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return torrent_handle::status(0x0).connections_limit; +#else return torrent_handle::status().connections_limit; +#endif } bool QTorrentHandle::priv() const { @@ -416,11 +523,20 @@ QString QTorrentHandle::firstFileSavePath() const { } bool QTorrentHandle::has_error() const { +#if LIBTORRENT_VERSION_MINOR > 15 + torrent_status st = torrent_handle::status(0x0); + return st.paused && !st.error.empty(); +#else return torrent_handle::is_paused() && !torrent_handle::status().error.empty(); +#endif } QString QTorrentHandle::error() const { +#if LIBTORRENT_VERSION_MINOR > 15 + return misc::toQString(torrent_handle::status(0x0).error); +#else return misc::toQString(torrent_handle::status().error); +#endif } void QTorrentHandle::downloading_pieces(bitfield &bf) const { @@ -498,7 +614,7 @@ void QTorrentHandle::move_storage(QString new_path) const { } bool QTorrentHandle::save_torrent_file(QString path) const { - if(!torrent_handle::has_metadata()) return false; + if(!has_metadata()) return false; QFile met_file(path); if(met_file.open(QIODevice::WriteOnly)) { entry meta = bdecode(torrent_handle::get_torrent_info().metadata().get(), torrent_handle::get_torrent_info().metadata().get()+torrent_handle::get_torrent_info().metadata_size()); @@ -632,18 +748,16 @@ void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const { } void QTorrentHandle::prioritize_first_last_piece(bool b) const { - if(!torrent_handle::has_metadata()) return; + if(!has_metadata()) return; // Download first and last pieces first for all media files in the torrent - torrent_info::file_iterator it; int index = 0; - torrent_info t = get_torrent_info(); - for(it = t.begin_files(); it != t.end_files(); it++) { - const QString ext = misc::toQStringU(it->path.string()).split(".").last(); + for(index = 0; index < num_files(); ++index) { + const QString path = filepath_at(index); + const QString ext = misc::file_extension(path); if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) { - qDebug() << "File" << it->path.string().c_str() << "is previewable, toggle downloading of first/last pieces first"; + qDebug() << "File" << path << "is previewable, toggle downloading of first/last pieces first"; prioritize_first_last_piece(index, b); } - ++index; } } diff --git a/src/qtlibtorrent/qtorrenthandle.h b/src/qtlibtorrent/qtorrenthandle.h index 33bd79876..10d9f3ef3 100644 --- a/src/qtlibtorrent/qtorrenthandle.h +++ b/src/qtlibtorrent/qtorrenthandle.h @@ -87,7 +87,6 @@ public: libtorrent::size_type filesize_at(unsigned int index) const; QString filepath_at(unsigned int index) const; QString orig_filepath_at(unsigned int index) const; - QString filepath(const libtorrent::file_entry &f) const; libtorrent::torrent_status::state_t state() const; QString creator() const; QString comment() const; @@ -98,8 +97,8 @@ public: libtorrent::size_type all_time_upload() const; libtorrent::size_type all_time_download() const; libtorrent::size_type total_done() const; - QStringList files_path() const; - QStringList uneeded_files_path() const; + QStringList absolute_files_path() const; + QStringList absolute_files_path_uneeded() const; bool has_missing_files() const; int num_uploads() const; bool is_seed() const; diff --git a/src/qtlibtorrent/torrentspeedmonitor.cpp b/src/qtlibtorrent/torrentspeedmonitor.cpp index b7946f931..eff73d954 100644 --- a/src/qtlibtorrent/torrentspeedmonitor.cpp +++ b/src/qtlibtorrent/torrentspeedmonitor.cpp @@ -125,8 +125,14 @@ void TorrentSpeedMonitor::getSamples() std::vector::const_iterator it; for(it = torrents.begin(); it != torrents.end(); it++) { try { +#if LIBTORRENT_VERSION_MINOR > 15 + torrent_status st = it->status(0x0); + if(!st.paused) + m_samples[misc::toQString(it->info_hash())].addSample(st.download_payload_rate); +#else if(!it->is_paused()) m_samples[misc::toQString(it->info_hash())].addSample(it->status().download_payload_rate); +#endif } catch(invalid_handle&){} } } diff --git a/src/statusbar.h b/src/statusbar.h index 0b22e99f4..183110f0e 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -212,36 +212,50 @@ public slots: void capDownloadSpeed() { bool ok = false; - long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), QBtSession::instance()->getSession()->download_rate_limit()); +#if LIBTORRENT_VERSION_MINOR > 15 + int cur_limit = QBtSession::instance()->getSession()->settings().download_rate_limit; +#else + int cur_limit = QBtSession::instance()->getSession()->download_rate_limit(); +#endif + long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), cur_limit); if(ok) { Preferences pref; bool alt = pref.isAltBandwidthEnabled(); if(new_limit <= 0) { qDebug("Setting global download rate limit to Unlimited"); + QBtSession::instance()->setDownloadRateLimit(-1); if(!alt) - QBtSession::instance()->getSession()->set_download_rate_limit(-1); - pref.setGlobalDownloadLimit(-1); + pref.setGlobalDownloadLimit(-1); } else { qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); + QBtSession::instance()->setDownloadRateLimit(new_limit); if(!alt) - QBtSession::instance()->getSession()->set_download_rate_limit(new_limit); - pref.setGlobalDownloadLimit(new_limit/1024.); + pref.setGlobalDownloadLimit(new_limit/1024.); } } } void capUploadSpeed() { bool ok = false; - long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), QBtSession::instance()->getSession()->upload_rate_limit()); +#if LIBTORRENT_VERSION_MINOR > 15 + int cur_limit = QBtSession::instance()->getSession()->settings().upload_rate_limit; +#else + int cur_limit = QBtSession::instance()->getSession()->upload_rate_limit(); +#endif + long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), cur_limit); if(ok) { + Preferences pref; + bool alt = pref.isAltBandwidthEnabled(); if(new_limit <= 0) { qDebug("Setting global upload rate limit to Unlimited"); - QBtSession::instance()->getSession()->set_upload_rate_limit(-1); - Preferences().setGlobalUploadLimit(-1); + QBtSession::instance()->setUploadRateLimit(-1); + if(!alt) + Preferences().setGlobalUploadLimit(-1); } else { qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); - Preferences().setGlobalUploadLimit(new_limit/1024.); - QBtSession::instance()->getSession()->set_upload_rate_limit(new_limit); + QBtSession::instance()->setUploadRateLimit(new_limit); + if(!alt) + Preferences().setGlobalUploadLimit(new_limit/1024.); } } } diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index ff184da7d..3318887cb 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -558,14 +558,13 @@ public: TorrentFileItem *current_parent; // Iterate over files - int i = 0; - libtorrent::torrent_info::file_iterator fi = t.begin_files(); - while(fi != t.end_files()) { + for(int i=0; i= 16 - QString path = QDir::cleanPath(misc::toQStringU(t.files().file_path(*fi))).replace("\\", "/"); + QString path = QDir::cleanPath(misc::toQStringU(fentry.path)).replace("\\", "/"); #else - QString path = QDir::cleanPath(misc::toQStringU(fi->path.string())).replace("\\", "/"); + QString path = QDir::cleanPath(misc::toQStringU(fentry.path.string())).replace("\\", "/"); #endif // Iterate of parts of the path to create necessary folders QStringList pathFolders = path.split("/"); @@ -579,10 +578,8 @@ public: current_parent = new_parent; } // Actually create the file - TorrentFileItem *f = new TorrentFileItem(t, *fi, current_parent, i); + TorrentFileItem *f = new TorrentFileItem(t, fentry, current_parent, i); files_index[i] = f; - fi++; - ++i; } emit layoutChanged(); } diff --git a/src/torrentimportdlg.cpp b/src/torrentimportdlg.cpp index ebc6a08e9..f6b7a02f4 100644 --- a/src/torrentimportdlg.cpp +++ b/src/torrentimportdlg.cpp @@ -81,7 +81,11 @@ void TorrentImportDlg::on_browseContentBtn_clicked() const QString default_dir = settings.value(QString::fromUtf8("TorrentImport/LastContentDir"), QDir::homePath()).toString(); if(t->num_files() == 1) { // Single file torrent +#if LIBTORRENT_VERSION_MINOR > 15 + const QString file_name = misc::fileName(misc::toQStringU(t->file_at(0).path)); +#else const QString file_name = misc::toQStringU(t->file_at(0).path.filename()); +#endif qDebug("Torrent has only one file: %s", qPrintable(file_name)); QString extension = misc::file_extension(file_name); qDebug("File extension is : %s", qPrintable(extension)); @@ -145,14 +149,17 @@ void TorrentImportDlg::on_browseContentBtn_clicked() bool size_mismatch = false; QDir content_dir(m_contentPath); // Check file sizes - torrent_info::file_iterator it; t->begin_files(); - for(it = t->begin_files(); it != t->end_files(); it++) { - const QString rel_path = misc::toQStringU(it->path.string()); - if(QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size() != it->size) { + for(int i=0; inum_files(); ++i) { +#if LIBTORRENT_VERSION_MINOR > 15 + const QString rel_path = misc::toQStringU(t->file_at(i).path); +#else + const QString rel_path = misc::toQStringU(t->file_at(i)->path.string()); +#endif + if(QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size() != t->file_at(i).size) { qDebug("%s is %lld", qPrintable(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))), (long long int) QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size()); qDebug("%s is %lld", - qPrintable(rel_path), (long long int)it->size); + qPrintable(rel_path), (long long int)t->file_at(i).size); size_mismatch = true; break; } @@ -254,7 +261,11 @@ void TorrentImportDlg::initializeFilesPath() m_filesPath.clear(); // Loads files path in the torrent for(int i=0; inum_files(); ++i) { +#if LIBTORRENT_VERSION_MINOR > 15 + m_filesPath << misc::toQStringU(t->file_at(i).path).replace("\\", "/"); +#else m_filesPath << misc::toQStringU(t->file_at(i).path.string()).replace("\\", "/"); +#endif } } diff --git a/src/webui/eventmanager.cpp b/src/webui/eventmanager.cpp index d3cb5e6ca..f06caa7c6 100644 --- a/src/webui/eventmanager.cpp +++ b/src/webui/eventmanager.cpp @@ -103,24 +103,19 @@ QList EventManager::getPropFilesInfo(QString hash) const { std::vector priorities = h.file_priorities(); std::vector fp; h.file_progress(fp); - torrent_info t = h.get_torrent_info(); - torrent_info::file_iterator fi; - int i=0; - for(fi=t.begin_files(); fi != t.end_files(); fi++) { + for(int i=0; isize); - if(fi->size > 0) - file["progress"] = fp[i]/(double)fi->size; + file["name"] = h.filename_at(i); + libtorrent::size_type size = h.filesize_at(i); + file["size"] = misc::friendlyUnit((double)size); + if(size > 0) + file["progress"] = fp[i]/(double)size; else file["progress"] = 1.; // Empty file... file["priority"] = priorities[i]; if(i == 0) file["is_seed"] = h.is_seed(); files << file; - ++i; } return files; } diff --git a/src/webui/httpconnection.cpp b/src/webui/httpconnection.cpp index 0f9b28a96..b3f7ee572 100644 --- a/src/webui/httpconnection.cpp +++ b/src/webui/httpconnection.cpp @@ -451,13 +451,21 @@ void HttpConnection::respondCommand(QString command) if(command == "getGlobalUpLimit") { generator.setStatusLine(200, "OK"); generator.setContentTypeByExt("html"); +#if LIBTORRENT_VERSION_MINOR > 15 + generator.setMessage(QString::number(QBtSession::instance()->getSession()->settings().upload_rate_limit)); +#else generator.setMessage(QString::number(QBtSession::instance()->getSession()->upload_rate_limit())); +#endif write(); } if(command == "getGlobalDlLimit") { generator.setStatusLine(200, "OK"); generator.setContentTypeByExt("html"); +#if LIBTORRENT_VERSION_MINOR > 15 + generator.setMessage(QString::number(QBtSession::instance()->getSession()->settings().download_rate_limit)); +#else generator.setMessage(QString::number(QBtSession::instance()->getSession()->download_rate_limit())); +#endif write(); } if(command == "getTorrentUpLimit") { @@ -501,13 +509,13 @@ void HttpConnection::respondCommand(QString command) if(command == "setGlobalUpLimit") { qlonglong limit = parser.post("limit").toLongLong(); if(limit == 0) limit = -1; - QBtSession::instance()->getSession()->set_upload_rate_limit(limit); + QBtSession::instance()->setUploadRateLimit(limit); Preferences().setGlobalUploadLimit(limit/1024.); } if(command == "setGlobalDlLimit") { qlonglong limit = parser.post("limit").toLongLong(); if(limit == 0) limit = -1; - QBtSession::instance()->getSession()->set_download_rate_limit(limit); + QBtSession::instance()->setDownloadRateLimit(limit); Preferences().setGlobalDownloadLimit(limit/1024.); } if(command == "pause") {