#include "AlertWaiterThread.h"
#include "QBittorrentSession.h"
-
+namespace qtrapids {
+
QBittorrentSession::QBittorrentSession(QObject *parent):
QObject(parent),
btSession_(),
}
-QTorrentHandle
+qtrapids::QTorrentHandle
QBittorrentSession::addTorrent(AddTorrentParams const& params)
{
// Delegate to Libtorrent and return QTorrentHandle.
//std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
- QTorrentHandle handle = QTorrentHandle(btSession_.add_torrent(params));
+ qtrapids::QTorrentHandle handle = qtrapids::QTorrentHandle(btSession_.add_torrent(params));
return handle;
}
-void QBittorrentSession::removeTorrent(QTorrentHandle const& handle)
+void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle)
{
btSession_.remove_torrent(handle.getHandle());
}
emit alert(alertPtr);
}
-
-
+} //namespace qtrapids
typedef libtorrent::sha1_hash Sha1Hash;
+namespace qtrapids {
+
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
*/
~QBittorrentSession();
/// @brief Add torrent to session.
- QTorrentHandle addTorrent(AddTorrentParams const& params);
- void removeTorrent(QTorrentHandle const& handle);
+ qtrapids::QTorrentHandle addTorrent(AddTorrentParams const& params);
+ void removeTorrent(qtrapids::QTorrentHandle const& handle);
signals:
void alert(std::auto_ptr<Alert> al);
};
+} //namespace qtrapids
#endif
#include "QTorrentHandle.h"
+namespace qtrapids {
+
+
QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) :
torrentHandle_(handle)
{
return torrentHandle_ < h.torrentHandle_;
}
-
-
-
+} // namespace qtrapids
\ No newline at end of file
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
*/
-class QTorrentHandle
-{
- public:
-
- enum State {
- QUEUED_FOR_CHECKING = TorrentStatus::queued_for_checking,
- CHECKING_FILES,
- DOWNLOADING_METADATA,
- DOWNLOADING,
- FINISHED,
- SEEDING,
- ALLOCATING,
- UNSPECIFIED
- };
-
- QTorrentHandle(libtorrent::torrent_handle handle);
- ~QTorrentHandle();
-
-
- TorrentInfo const& getTorrentInfo() const;
-
- bool isValid() const;
+namespace qtrapids {
+
+ class QTorrentHandle
+ {
+ public:
+
+ enum State {
+ QUEUED_FOR_CHECKING = TorrentStatus::queued_for_checking,
+ CHECKING_FILES,
+ DOWNLOADING_METADATA,
+ DOWNLOADING,
+ FINISHED,
+ SEEDING,
+ ALLOCATING,
+ UNSPECIFIED
+ };
+
+ QTorrentHandle(libtorrent::torrent_handle handle);
+ ~QTorrentHandle();
+
- QString name() const;
- size_t getTotalSize() const;
- QTorrentHandle::State state() const;
- float progress() const;
- float uploadRate() const;
- float downloadRate() const;
- qint32 numSeeds() const;
- qint32 numLeeches() const;
- qint32 ratio() const;
-
- TorrentHandle getHandle() const;
-
- bool operator==(QTorrentHandle const& h) const;
- bool operator<(QTorrentHandle const& h) const;
+
+ TorrentInfo const& getTorrentInfo() const;
+
+ bool isValid() const;
+
+ QString name() const;
+ size_t getTotalSize() const;
+ QTorrentHandle::State state() const;
+ float progress() const;
+ float uploadRate() const;
+ float downloadRate() const;
+ qint32 numSeeds() const;
+ qint32 numLeeches() const;
+ qint32 ratio() const;
+
+ TorrentHandle getHandle() const;
+
+ bool operator==(QTorrentHandle const& h) const;
+ bool operator<(QTorrentHandle const& h) const;
+
+ private:
+ QTorrentHandle(); // Prevent default construct.
+ TorrentHandle torrentHandle_;
- private:
- QTorrentHandle(); // Prevent default construct.
- TorrentHandle torrentHandle_;
-
- TorrentStatus status() const;
+ TorrentStatus status() const;
-};
+ };
+} // namespace qtrapids
#endif
}
-void DownloadView::newItem(QTorrentHandle handle)
+void DownloadView::newItem(qtrapids::QTorrentHandle handle)
{
#ifdef QTRAPIDS_DEBUG
qDebug() << "DownloadView::newItem() " << items_.count(handle);
}
-void DownloadView::updateItem(QTorrentHandle handle)
+void DownloadView::updateItem(qtrapids::QTorrentHandle handle)
{
//qDebug() << "DownloadView::updateItem() " << items_.count(handle);
}
-QTorrentHandle DownloadView::removeSelected()
+qtrapids::QTorrentHandle DownloadView::removeSelected()
{
#ifdef QTRAPIDS_DEBUG
qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
- std::map<QTorrentHandle, DownloadViewItem*>::iterator listIter
+ std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listIter
= items_.begin();
- std::map<QTorrentHandle, DownloadViewItem*>::iterator listEnd
+ std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listEnd
= items_.end();
while (listIter != listEnd) {
++listIter;
}
- QTorrentHandle handle = listIter->first;
+ qtrapids::QTorrentHandle handle = listIter->first;
items_.erase(listIter);
}
-void DownloadView::removeItem(QTorrentHandle handle)
+void DownloadView::removeItem(qtrapids::QTorrentHandle handle)
{
}
-QString DownloadView::GetStatusString(QTorrentHandle::State const& status) const
+QString DownloadView::GetStatusString(qtrapids::QTorrentHandle::State const& status) const
{
switch (status) {
- case QTorrentHandle::QUEUED_FOR_CHECKING :
+ case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING :
return tr("Queued");
- case QTorrentHandle::CHECKING_FILES :
+ case qtrapids::QTorrentHandle::CHECKING_FILES :
return tr("Checking");
- case QTorrentHandle::DOWNLOADING_METADATA :
+ case qtrapids::QTorrentHandle::DOWNLOADING_METADATA :
return tr("DL meta");
- case QTorrentHandle::DOWNLOADING :
+ case qtrapids::QTorrentHandle::DOWNLOADING :
return tr("Downloading");
- case QTorrentHandle::FINISHED :
+ case qtrapids::QTorrentHandle::FINISHED :
return tr("Finished");
- case QTorrentHandle::SEEDING :
+ case qtrapids::QTorrentHandle::SEEDING :
return tr("Seeding");
- case QTorrentHandle::ALLOCATING :
+ case qtrapids::QTorrentHandle::ALLOCATING :
return tr("Allocating");
default:
return tr("N/A");
}
-QColor DownloadView::GetStatusColor(QTorrentHandle::State const& status) const
+QColor DownloadView::GetStatusColor(qtrapids::QTorrentHandle::State const& status) const
{
QColor green(40,205,40);
QColor yellow(255,174,0);
switch (status) {
- case QTorrentHandle::QUEUED_FOR_CHECKING :
- case QTorrentHandle::CHECKING_FILES :
- case QTorrentHandle::DOWNLOADING_METADATA :
- case QTorrentHandle::ALLOCATING :
+ case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING :
+ case qtrapids::QTorrentHandle::CHECKING_FILES :
+ case qtrapids::QTorrentHandle::DOWNLOADING_METADATA :
+ case qtrapids::QTorrentHandle::ALLOCATING :
return yellow;
- case QTorrentHandle::DOWNLOADING :
- case QTorrentHandle::FINISHED :
- case QTorrentHandle::SEEDING :
+ case qtrapids::QTorrentHandle::DOWNLOADING :
+ case qtrapids::QTorrentHandle::FINISHED :
+ case qtrapids::QTorrentHandle::SEEDING :
return green;
default:
return QColor();
{
DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
- std::map<QTorrentHandle, DownloadViewItem*>::iterator listIter
+ std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listIter
= items_.begin();
- std::map<QTorrentHandle, DownloadViewItem*>::iterator listEnd
+ std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listEnd
= items_.end();
while (listIter != listEnd) {
~DownloadView();
- void newItem(QTorrentHandle handle);
- void updateItem(QTorrentHandle handle);
- QTorrentHandle removeSelected();
- void removeItem(QTorrentHandle handle);
+ void newItem(qtrapids::QTorrentHandle handle);
+ void updateItem(qtrapids::QTorrentHandle handle);
+ qtrapids::QTorrentHandle removeSelected();
+ void removeItem(qtrapids::QTorrentHandle handle);
void setRefreshInterval(int msec);
private slots:
private:
// Maps torrent to downloadview item.
// Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
- std::map<QTorrentHandle, DownloadViewItem*> items_;
+ std::map<qtrapids::QTorrentHandle, DownloadViewItem*> items_;
QTimer *timer_;
// Private functions.
- QString GetStatusString(QTorrentHandle::State const& status) const;
- QColor GetStatusColor(QTorrentHandle::State const& status) const;
+ QString GetStatusString(qtrapids::QTorrentHandle::State const& status) const;
+ QColor GetStatusColor(qtrapids::QTorrentHandle::State const& status) const;
void UpdateView();
void MainWindow::on_removeAction_clicked()
{
- QTorrentHandle handle = dlView_->removeSelected();
+ qtrapids::QTorrentHandle handle = dlView_->removeSelected();
btSession_.removeTorrent(handle);
}
// save_path is the only mandatory parameter, rest are optional.
addParams.save_path = boost::filesystem::path(settings_.value("download/directory").toString().toStdString());
//addParams.storage_mode = libtorrent::storage_mode_allocate;
- QTorrentHandle handle = btSession_.addTorrent(addParams);
+ qtrapids::QTorrentHandle handle = btSession_.addTorrent(addParams);
dlView_->newItem(handle);
// torrentHandles_.push_back(handlePtr);
#ifdef QTRAPIDS_DEBUG
= dynamic_cast<TorrentAlert*> (al.get());
if (torrentAlert) {
- QTorrentHandle torrentHandle = QTorrentHandle(torrentAlert->handle);
- dlView_->updateItem(QTorrentHandle(torrentAlert->handle));
+ qtrapids::QTorrentHandle torrentHandle = qtrapids::QTorrentHandle(torrentAlert->handle);
+ dlView_->updateItem(qtrapids::QTorrentHandle(torrentAlert->handle));
}
}
}
/*
-bool MainWindow::IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr)
+bool MainWindow::IsNewTorrent(std::auto_ptr<qtrapids::QTorrentHandle> handlePtr)
{
for (unsigned i = 0; i < torrentHandles_.size(); ++i) {
if (torrentHandles_.at(i).get() == handlePtr.get()) {
//std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
- QBittorrentSession btSession_;
+ qtrapids::QBittorrentSession btSession_;
//bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
~SeedView();
- void newItem(QTorrentHandle const* handle);
- void updateItem(QTorrentHandle const* handle);
+ void newItem(qtrapids::QTorrentHandle const* handle);
+ void updateItem(qtrapids::QTorrentHandle const* handle);
private slots:
void on_itemPressed(QTreeWidgetItem *item, int column);