Browse Source

Simplify Session/TorrentHandle classes.

adaptive-webui-19844
Vladimir Golovnev (Glassez) 9 years ago
parent
commit
d40495a4be
  1. 81
      src/core/bittorrent/private/sessionprivate.h
  2. 49
      src/core/bittorrent/private/torrenthandleprivate.h
  3. 10
      src/core/bittorrent/session.cpp
  4. 60
      src/core/bittorrent/session.h
  5. 2
      src/core/bittorrent/torrenthandle.cpp
  6. 21
      src/core/bittorrent/torrenthandle.h
  7. 2
      src/core/core.pri

81
src/core/bittorrent/private/sessionprivate.h

@ -1,81 +0,0 @@ @@ -1,81 +0,0 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#ifndef SESSIONPRIVATE_H
#define SESSIONPRIVATE_H
class QString;
class QUrl;
template<typename T> class QList;
namespace libtorrent
{
class entry;
}
namespace BitTorrent
{
class TorrentHandle;
class TrackerEntry;
}
struct SessionPrivate
{
virtual bool isQueueingEnabled() const = 0;
virtual bool isTempPathEnabled() const = 0;
virtual bool isAppendExtensionEnabled() const = 0;
virtual bool useAppendLabelToSavePath() const = 0;
virtual QString defaultSavePath() const = 0;
virtual QString tempPath() const = 0;
virtual qreal globalMaxRatio() const = 0;
virtual void handleTorrentRatioLimitChanged(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentSavePathChanged(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentLabelChanged(BitTorrent::TorrentHandle *const torrent, const QString &oldLabel) = 0;
virtual void handleTorrentMetadataReceived(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentPaused(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentResumed(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentChecked(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentFinished(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentTrackersAdded(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &newTrackers) = 0;
virtual void handleTorrentTrackersRemoved(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &deletedTrackers) = 0;
virtual void handleTorrentTrackersChanged(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentUrlSeedsAdded(BitTorrent::TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds) = 0;
virtual void handleTorrentUrlSeedsRemoved(BitTorrent::TorrentHandle *const torrent, const QList<QUrl> &urlSeeds) = 0;
virtual void handleTorrentResumeDataReady(BitTorrent::TorrentHandle *const torrent, const libtorrent::entry &data) = 0;
virtual void handleTorrentResumeDataFailed(BitTorrent::TorrentHandle *const torrent) = 0;
virtual void handleTorrentTrackerReply(BitTorrent::TorrentHandle *const torrent, const QString &trackerUrl) = 0;
virtual void handleTorrentTrackerWarning(BitTorrent::TorrentHandle *const torrent, const QString &trackerUrl) = 0;
virtual void handleTorrentTrackerError(BitTorrent::TorrentHandle *const torrent, const QString &trackerUrl) = 0;
virtual void handleTorrentTrackerAuthenticationRequired(BitTorrent::TorrentHandle *const torrent, const QString &trackerUrl) = 0;
protected:
~SessionPrivate() {}
};
#endif // SESSIONPRIVATE_H

49
src/core/bittorrent/private/torrenthandleprivate.h

@ -1,49 +0,0 @@ @@ -1,49 +0,0 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#ifndef TORRENTHANDLEPRIVATE_H
#define TORRENTHANDLEPRIVATE_H
namespace libtorrent
{
class alert;
struct torrent_status;
}
struct TorrentHandlePrivate
{
virtual void handleAlert(libtorrent::alert *) = 0;
virtual void handleStateUpdate(const libtorrent::torrent_status &) = 0;
virtual void handleTempPathChanged() = 0;
virtual void handleAppendExtensionToggled() = 0;
protected:
~TorrentHandlePrivate() {}
};
#endif // TORRENTHANDLEPRIVATE_H

10
src/core/bittorrent/session.cpp

@ -1397,7 +1397,7 @@ void Session::saveResumeData() @@ -1397,7 +1397,7 @@ void Session::saveResumeData()
switch (a->type()) {
case libt::save_resume_data_failed_alert::alert_type:
case libt::save_resume_data_alert::alert_type:
TorrentHandlePrivate *torrent = m_torrents.take(static_cast<libt::torrent_alert *>(a)->handle.info_hash());
TorrentHandle *torrent = m_torrents.take(static_cast<libt::torrent_alert *>(a)->handle.info_hash());
if (torrent)
torrent->handleAlert(a);
break;
@ -1429,7 +1429,7 @@ void Session::setDefaultTempPath(const QString &path) @@ -1429,7 +1429,7 @@ void Session::setDefaultTempPath(const QString &path)
if (m_tempPath != tempPath) {
m_tempPath = tempPath;
foreach (TorrentHandlePrivate *const torrent, m_torrents)
foreach (TorrentHandle *const torrent, m_torrents)
torrent->handleTempPathChanged();
}
}
@ -1460,7 +1460,7 @@ void Session::setAppendExtension(bool append) @@ -1460,7 +1460,7 @@ void Session::setAppendExtension(bool append)
if (m_appendExtension != append) {
m_appendExtension = append;
// append or remove .!qB extension for incomplete files
foreach (TorrentHandlePrivate *const torrent, m_torrents)
foreach (TorrentHandle *const torrent, m_torrents)
torrent->handleAppendExtensionToggled();
}
}
@ -2098,7 +2098,7 @@ void Session::handleAlert(libt::alert *a) @@ -2098,7 +2098,7 @@ void Session::handleAlert(libt::alert *a)
void Session::dispatchTorrentAlert(libt::alert *a)
{
TorrentHandlePrivate *const torrent = m_torrents.value(static_cast<libt::torrent_alert*>(a)->handle.info_hash());
TorrentHandle *const torrent = m_torrents.value(static_cast<libt::torrent_alert*>(a)->handle.info_hash());
if (torrent)
torrent->handleAlert(a);
}
@ -2321,7 +2321,7 @@ void Session::handleStateUpdateAlert(libt::state_update_alert *p) @@ -2321,7 +2321,7 @@ void Session::handleStateUpdateAlert(libt::state_update_alert *p)
foreach (const libt::torrent_status &status, p->status) {
TorrentHandle *const torrent = m_torrents.value(status.info_hash);
if (torrent) {
static_cast<TorrentHandlePrivate *>(torrent)->handleStateUpdate(status);
torrent->handleStateUpdate(status);
emit torrentStatusUpdated(torrent);
}
}

60
src/core/bittorrent/session.h

@ -40,12 +40,12 @@ @@ -40,12 +40,12 @@
#include "core/tristatebool.h"
#include "core/types.h"
#include "private/sessionprivate.h"
#include "torrentinfo.h"
namespace libtorrent
{
class session;
class entry;
struct add_torrent_params;
struct pe_settings;
struct proxy_settings;
@ -85,10 +85,11 @@ namespace libtorrent @@ -85,10 +85,11 @@ namespace libtorrent
struct external_ip_alert;
}
QT_BEGIN_NAMESPACE
class QTimer;
class QStringList;
QT_END_NAMESPACE
class QString;
class QUrl;
template<typename T> class QList;
class FilterParserThread;
class BandwidthScheduler;
@ -136,7 +137,7 @@ namespace BitTorrent @@ -136,7 +137,7 @@ namespace BitTorrent
TorrentStatusReport();
};
class Session : public QObject, public SessionPrivate
class Session : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(Session)
@ -151,6 +152,11 @@ namespace BitTorrent @@ -151,6 +152,11 @@ namespace BitTorrent
bool isPexEnabled() const;
bool isQueueingEnabled() const;
qreal globalMaxRatio() const;
bool isTempPathEnabled() const;
bool isAppendExtensionEnabled() const;
bool useAppendLabelToSavePath() const;
QString defaultSavePath() const;
QString tempPath() const;
TorrentHandle *findTorrent(const InfoHash &hash) const;
QHash<InfoHash, TorrentHandle *> torrents() const;
@ -185,6 +191,27 @@ namespace BitTorrent @@ -185,6 +191,27 @@ namespace BitTorrent
void topTorrentsPriority(const QStringList &hashes);
void bottomTorrentsPriority(const QStringList &hashes);
// TorrentHandle interface
void handleTorrentRatioLimitChanged(TorrentHandle *const torrent);
void handleTorrentSavePathChanged(TorrentHandle *const torrent);
void handleTorrentLabelChanged(TorrentHandle *const torrent, const QString &oldLabel);
void handleTorrentMetadataReceived(TorrentHandle *const torrent);
void handleTorrentPaused(TorrentHandle *const torrent);
void handleTorrentResumed(TorrentHandle *const torrent);
void handleTorrentChecked(TorrentHandle *const torrent);
void handleTorrentFinished(TorrentHandle *const torrent);
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QList<TrackerEntry> &newTrackers);
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QList<TrackerEntry> &deletedTrackers);
void handleTorrentTrackersChanged(TorrentHandle *const torrent);
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds);
void handleTorrentResumeDataReady(TorrentHandle *const torrent, const libtorrent::entry &data);
void handleTorrentResumeDataFailed(TorrentHandle *const torrent);
void handleTorrentTrackerReply(TorrentHandle *const torrent, const QString &trackerUrl);
void handleTorrentTrackerWarning(TorrentHandle *const torrent, const QString &trackerUrl);
void handleTorrentTrackerError(TorrentHandle *const torrent, const QString &trackerUrl);
void handleTorrentTrackerAuthenticationRequired(TorrentHandle *const torrent, const QString &trackerUrl);
signals:
void torrentsUpdated(const BitTorrent::TorrentStatusReport &torrentStatusReport = BitTorrent::TorrentStatusReport());
void addTorrentFailed(const QString &error);
@ -287,31 +314,6 @@ namespace BitTorrent @@ -287,31 +314,6 @@ namespace BitTorrent
void handleListenFailedAlert(libtorrent::listen_failed_alert *p);
void handleExternalIPAlert(libtorrent::external_ip_alert *p);
bool isTempPathEnabled() const;
bool isAppendExtensionEnabled() const;
bool useAppendLabelToSavePath() const;
QString defaultSavePath() const;
QString tempPath() const;
void handleTorrentRatioLimitChanged(TorrentHandle *const torrent);
void handleTorrentSavePathChanged(TorrentHandle *const torrent);
void handleTorrentLabelChanged(TorrentHandle *const torrent, const QString &oldLabel);
void handleTorrentMetadataReceived(TorrentHandle *const torrent);
void handleTorrentPaused(TorrentHandle *const torrent);
void handleTorrentResumed(TorrentHandle *const torrent);
void handleTorrentChecked(TorrentHandle *const torrent);
void handleTorrentFinished(TorrentHandle *const torrent);
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QList<TrackerEntry> &newTrackers);
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QList<TrackerEntry> &deletedTrackers);
void handleTorrentTrackersChanged(TorrentHandle *const torrent);
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds);
void handleTorrentResumeDataReady(TorrentHandle *const torrent, const libtorrent::entry &data);
void handleTorrentResumeDataFailed(TorrentHandle *const torrent);
void handleTorrentTrackerReply(TorrentHandle *const torrent, const QString &trackerUrl);
void handleTorrentTrackerWarning(TorrentHandle *const torrent, const QString &trackerUrl);
void handleTorrentTrackerError(TorrentHandle *const torrent, const QString &trackerUrl);
void handleTorrentTrackerAuthenticationRequired(TorrentHandle *const torrent, const QString &trackerUrl);
void saveResumeData();
bool writeResumeDataFile(TorrentHandle *const torrent, const libtorrent::entry &data);

2
src/core/bittorrent/torrenthandle.cpp

@ -1399,7 +1399,7 @@ void TorrentHandle::handleTorrentFinishedAlert(libtorrent::torrent_finished_aler @@ -1399,7 +1399,7 @@ void TorrentHandle::handleTorrentFinishedAlert(libtorrent::torrent_finished_aler
forceRecheck();
if (isMoveInProgress() || m_renameCount > 0)
m_moveFinishedTriggers.append(boost::bind(&SessionPrivate::handleTorrentFinished, m_session, this));
m_moveFinishedTriggers.append(boost::bind(&Session::handleTorrentFinished, m_session, this));
else
m_session->handleTorrentFinished(this);
}

21
src/core/bittorrent/torrenthandle.h

@ -42,7 +42,6 @@ @@ -42,7 +42,6 @@
#include "core/tristatebool.h"
#include "private/speedmonitor.h"
#include "private/torrenthandleprivate.h"
#include "infohash.h"
#include "torrentinfo.h"
@ -70,10 +69,9 @@ namespace libtorrent @@ -70,10 +69,9 @@ namespace libtorrent
struct tracker_reply_alert;
struct tracker_warning_alert;
struct fastresume_rejected_alert;
struct torrent_status;
}
struct SessionPrivate;
namespace BitTorrent
{
struct PeerAddress;
@ -153,7 +151,7 @@ namespace BitTorrent @@ -153,7 +151,7 @@ namespace BitTorrent
int m_value;
};
class TorrentHandle : public QObject, public TorrentHandlePrivate
class TorrentHandle : public QObject
{
Q_DISABLE_COPY(TorrentHandle)
@ -293,10 +291,16 @@ namespace BitTorrent @@ -293,10 +291,16 @@ namespace BitTorrent
QString toMagnetUri() const;
bool needSaveResumeData() const;
void saveResumeData();
// Session interface
libtorrent::torrent_handle nativeHandle() const;
void handleAlert(libtorrent::alert *a);
void handleStateUpdate(const libtorrent::torrent_status &nativeStatus);
void handleTempPathChanged();
void handleAppendExtensionToggled();
void saveResumeData();
private:
typedef boost::function<void ()> EventTrigger;
@ -306,11 +310,6 @@ namespace BitTorrent @@ -306,11 +310,6 @@ namespace BitTorrent
void updateState();
void updateTorrentInfo();
void handleAlert(libtorrent::alert *a);
void handleStateUpdate(const libtorrent::torrent_status &nativeStatus);
void handleTempPathChanged();
void handleAppendExtensionToggled();
void handleStorageMovedAlert(libtorrent::storage_moved_alert *p);
void handleStorageMovedFailedAlert(libtorrent::storage_moved_failed_alert *p);
void handleTrackerReplyAlert(libtorrent::tracker_reply_alert *p);
@ -342,7 +341,7 @@ namespace BitTorrent @@ -342,7 +341,7 @@ namespace BitTorrent
bool addUrlSeed(const QUrl &urlSeed);
bool removeUrlSeed(const QUrl &urlSeed);
SessionPrivate *const m_session;
Session *const m_session;
libtorrent::torrent_handle m_nativeHandle;
libtorrent::torrent_status m_nativeStatus;
TorrentState m_state;

2
src/core/core.pri

@ -32,8 +32,6 @@ HEADERS += \ @@ -32,8 +32,6 @@ HEADERS += \
$$PWD/bittorrent/trackerentry.h \
$$PWD/bittorrent/tracker.h \
$$PWD/bittorrent/torrentcreatorthread.h \
$$PWD/bittorrent/private/sessionprivate.h \
$$PWD/bittorrent/private/torrenthandleprivate.h \
$$PWD/bittorrent/private/speedmonitor.h \
$$PWD/bittorrent/private/bandwidthscheduler.h \
$$PWD/bittorrent/private/filterparserthread.h \

Loading…
Cancel
Save