From de4559659d504b9a6113ea511898f4c2e9cb6c3f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 16 Feb 2012 21:04:02 +0200 Subject: [PATCH] Code clean up --- src/misc.h | 8 -------- src/qtlibtorrent/qbtsession.cpp | 11 ++++++++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/misc.h b/src/misc.h index 9b5278168..6bf26ac29 100644 --- a/src/misc.h +++ b/src/misc.h @@ -92,14 +92,6 @@ public: return tmp.join("/"); } - static inline libtorrent::sha1_hash QStringToSha1(const QString& s) { - std::string str(s.toLocal8Bit().data()); - std::istringstream i(str); - libtorrent::sha1_hash x; - i>>x; - return x; - } - static inline QString file_extension(const QString &filename) { QString extension; int point_index = filename.lastIndexOf("."); diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 2c2df9ff9..ab8e9bf50 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -90,6 +90,15 @@ const qreal QBtSession::MAX_RATIO = 9999.; const int MAX_TRACKER_ERRORS = 2; +/* Converts a QString hash into a libtorrent sha1_hash */ +static libtorrent::sha1_hash QStringToSha1(const QString& s) { + QByteArray raw = s.toAscii(); + Q_ASSERT(raw.size() == 40); + libtorrent::sha1_hash ret; + from_hex(raw.constData(), 40, (char*)&ret[0]); + return ret; +} + // Main constructor QBtSession::QBtSession() : m_scanFolders(ScanFoldersModel::instance(this)), @@ -718,7 +727,7 @@ void QBtSession::useAlternativeSpeedsLimit(bool alternative) { // Return the torrent handle, given its hash QTorrentHandle QBtSession::getTorrentHandle(const QString &hash) const{ - return QTorrentHandle(s->find_torrent(misc::QStringToSha1(hash))); + return QTorrentHandle(s->find_torrent(QStringToSha1(hash))); } bool QBtSession::hasActiveTorrents() const {