From d3d85653bf84dadcf6c2890cc2ddf9f629ee7619 Mon Sep 17 00:00:00 2001 From: lvaatamoinen Date: Fri, 6 Nov 2009 12:35:57 +0000 Subject: [PATCH] - Namespaced QBittorrentSession and QTorrentHandle to avoid possible future conflicts git-svn-id: file:///svnroot/qtrapids/trunk@20 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda --- src/engine/QBittorrentSession.cpp | 12 ++--- src/engine/QBittorrentSession.h | 7 ++- src/engine/QTorrentHandle.cpp | 7 +-- src/engine/QTorrentHandle.h | 88 +++++++++++++++++++------------------ src/gui/DownloadView.cpp | 50 ++++++++++----------- src/gui/DownloadView.h | 14 +++--- src/gui/MainWindow.cpp | 10 ++--- src/gui/MainWindow.h | 2 +- src/gui/SeedView.h | 4 +- 9 files changed, 101 insertions(+), 93 deletions(-) diff --git a/src/engine/QBittorrentSession.cpp b/src/engine/QBittorrentSession.cpp index 7d88e26..2ab40ed 100644 --- a/src/engine/QBittorrentSession.cpp +++ b/src/engine/QBittorrentSession.cpp @@ -23,7 +23,8 @@ #include "AlertWaiterThread.h" #include "QBittorrentSession.h" - +namespace qtrapids { + QBittorrentSession::QBittorrentSession(QObject *parent): QObject(parent), btSession_(), @@ -41,17 +42,17 @@ QBittorrentSession::~QBittorrentSession() } -QTorrentHandle +qtrapids::QTorrentHandle QBittorrentSession::addTorrent(AddTorrentParams const& params) { // Delegate to Libtorrent and return QTorrentHandle. //std::auto_ptr 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()); } @@ -73,5 +74,4 @@ void QBittorrentSession::on_alert(Alert const *al) emit alert(alertPtr); } - - +} //namespace qtrapids diff --git a/src/engine/QBittorrentSession.h b/src/engine/QBittorrentSession.h index 9cf5381..7d2ea43 100644 --- a/src/engine/QBittorrentSession.h +++ b/src/engine/QBittorrentSession.h @@ -40,6 +40,8 @@ typedef libtorrent::torrent_alert TorrentAlert; typedef libtorrent::sha1_hash Sha1Hash; +namespace qtrapids { + /** @author Lassi Väätämöinen */ @@ -52,8 +54,8 @@ class QBittorrentSession : public QObject { ~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 al); @@ -67,4 +69,5 @@ class QBittorrentSession : public QObject { }; +} //namespace qtrapids #endif diff --git a/src/engine/QTorrentHandle.cpp b/src/engine/QTorrentHandle.cpp index d2470c7..b1f426a 100644 --- a/src/engine/QTorrentHandle.cpp +++ b/src/engine/QTorrentHandle.cpp @@ -21,6 +21,9 @@ #include "QTorrentHandle.h" +namespace qtrapids { + + QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) : torrentHandle_(handle) { @@ -153,9 +156,7 @@ bool QTorrentHandle::operator<(QTorrentHandle const& h) const return torrentHandle_ < h.torrentHandle_; } - - - +} // namespace qtrapids \ No newline at end of file diff --git a/src/engine/QTorrentHandle.h b/src/engine/QTorrentHandle.h index 0d8d4a5..855f0ca 100644 --- a/src/engine/QTorrentHandle.h +++ b/src/engine/QTorrentHandle.h @@ -33,51 +33,55 @@ typedef libtorrent::torrent_handle TorrentHandle; /** @author Lassi Väätämöinen */ -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 diff --git a/src/gui/DownloadView.cpp b/src/gui/DownloadView.cpp index ede3b66..d6c9183 100644 --- a/src/gui/DownloadView.cpp +++ b/src/gui/DownloadView.cpp @@ -47,7 +47,7 @@ DownloadView::~DownloadView() } -void DownloadView::newItem(QTorrentHandle handle) +void DownloadView::newItem(qtrapids::QTorrentHandle handle) { #ifdef QTRAPIDS_DEBUG qDebug() << "DownloadView::newItem() " << items_.count(handle); @@ -74,7 +74,7 @@ void DownloadView::newItem(QTorrentHandle handle) } -void DownloadView::updateItem(QTorrentHandle handle) +void DownloadView::updateItem(qtrapids::QTorrentHandle handle) { //qDebug() << "DownloadView::updateItem() " << items_.count(handle); @@ -114,7 +114,7 @@ void DownloadView::updateItem(QTorrentHandle handle) } -QTorrentHandle DownloadView::removeSelected() +qtrapids::QTorrentHandle DownloadView::removeSelected() { #ifdef QTRAPIDS_DEBUG qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; @@ -122,9 +122,9 @@ QTorrentHandle DownloadView::removeSelected() DownloadViewItem *item = dynamic_cast (currentItem()); - std::map::iterator listIter + std::map::iterator listIter = items_.begin(); - std::map::iterator listEnd + std::map::iterator listEnd = items_.end(); while (listIter != listEnd) { @@ -134,7 +134,7 @@ QTorrentHandle DownloadView::removeSelected() ++listIter; } - QTorrentHandle handle = listIter->first; + qtrapids::QTorrentHandle handle = listIter->first; items_.erase(listIter); @@ -151,7 +151,7 @@ QTorrentHandle DownloadView::removeSelected() } -void DownloadView::removeItem(QTorrentHandle handle) +void DownloadView::removeItem(qtrapids::QTorrentHandle handle) { } @@ -183,22 +183,22 @@ void DownloadView::on_timeout() { -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"); @@ -206,20 +206,20 @@ QString DownloadView::GetStatusString(QTorrentHandle::State const& status) const } -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(); @@ -230,9 +230,9 @@ void DownloadView::UpdateView() { DownloadViewItem *item = dynamic_cast (currentItem()); - std::map::iterator listIter + std::map::iterator listIter = items_.begin(); - std::map::iterator listEnd + std::map::iterator listEnd = items_.end(); while (listIter != listEnd) { diff --git a/src/gui/DownloadView.h b/src/gui/DownloadView.h index 6fadb92..cb300ba 100644 --- a/src/gui/DownloadView.h +++ b/src/gui/DownloadView.h @@ -43,10 +43,10 @@ Q_OBJECT ~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: @@ -56,12 +56,12 @@ Q_OBJECT private: // Maps torrent to downloadview item. // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent. - std::map items_; + std::map 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(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index a3262e1..4ccddd9 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -129,7 +129,7 @@ void MainWindow::on_openAction_clicked() void MainWindow::on_removeAction_clicked() { - QTorrentHandle handle = dlView_->removeSelected(); + qtrapids::QTorrentHandle handle = dlView_->removeSelected(); btSession_.removeTorrent(handle); } @@ -212,7 +212,7 @@ void MainWindow::on_torrentFileSelected(const QString& file) // 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 @@ -234,8 +234,8 @@ void MainWindow::on_alert(std::auto_ptr al) = dynamic_cast (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)); } } @@ -245,7 +245,7 @@ void MainWindow::on_alert(std::auto_ptr al) } /* -bool MainWindow::IsNewTorrent(std::auto_ptr handlePtr) +bool MainWindow::IsNewTorrent(std::auto_ptr handlePtr) { for (unsigned i = 0; i < torrentHandles_.size(); ++i) { if (torrentHandles_.at(i).get() == handlePtr.get()) { diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 275e1dd..3f546bb 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -67,7 +67,7 @@ class MainWindow : public QMainWindow { //std::vector< std::auto_ptr const > torrentHandles_; - QBittorrentSession btSession_; + qtrapids::QBittorrentSession btSession_; //bool IsNewTorrent(std::auto_ptr handlePtr); diff --git a/src/gui/SeedView.h b/src/gui/SeedView.h index 9b05e99..666a4c7 100644 --- a/src/gui/SeedView.h +++ b/src/gui/SeedView.h @@ -37,8 +37,8 @@ Q_OBJECT ~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); -- 1.7.9.5