- Namespaced QBittorrentSession and QTorrentHandle to avoid possible future conflicts
authorlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Fri, 6 Nov 2009 12:35:57 +0000 (12:35 +0000)
committerlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Fri, 6 Nov 2009 12:35:57 +0000 (12:35 +0000)
git-svn-id: file:///svnroot/qtrapids/trunk@20 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda

src/engine/QBittorrentSession.cpp
src/engine/QBittorrentSession.h
src/engine/QTorrentHandle.cpp
src/engine/QTorrentHandle.h
src/gui/DownloadView.cpp
src/gui/DownloadView.h
src/gui/MainWindow.cpp
src/gui/MainWindow.h
src/gui/SeedView.h

index 7d88e26..2ab40ed 100644 (file)
@@ -23,7 +23,8 @@
 #include "AlertWaiterThread.h"
 #include "QBittorrentSession.h"
 
 #include "AlertWaiterThread.h"
 #include "QBittorrentSession.h"
 
-
+namespace qtrapids {
+       
 QBittorrentSession::QBittorrentSession(QObject *parent):
                QObject(parent),
                btSession_(),
 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<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
 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;
 }
 
 
        return handle;
 }
 
 
-void QBittorrentSession::removeTorrent(QTorrentHandle const& handle) 
+void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle) 
 {
        btSession_.remove_torrent(handle.getHandle());
 }
 {
        btSession_.remove_torrent(handle.getHandle());
 }
@@ -73,5 +74,4 @@ void QBittorrentSession::on_alert(Alert const *al)
        emit alert(alertPtr);
 }
 
        emit alert(alertPtr);
 }
 
-
-
+} //namespace qtrapids
index 9cf5381..7d2ea43 100644 (file)
@@ -40,6 +40,8 @@ typedef       libtorrent::torrent_alert TorrentAlert;
 typedef libtorrent::sha1_hash Sha1Hash;
 
 
 typedef libtorrent::sha1_hash Sha1Hash;
 
 
+namespace qtrapids {
+
 /**
        @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
 */
 /**
        @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
 */
@@ -52,8 +54,8 @@ class QBittorrentSession : public QObject {
     ~QBittorrentSession();
                
                /// @brief Add torrent to session.
     ~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);
                
        signals:
                void alert(std::auto_ptr<Alert> al);
@@ -67,4 +69,5 @@ class QBittorrentSession : public QObject {
                
 };
 
                
 };
 
+} //namespace qtrapids
 #endif
 #endif
index d2470c7..b1f426a 100644 (file)
@@ -21,6 +21,9 @@
 
 #include "QTorrentHandle.h"
 
 
 #include "QTorrentHandle.h"
 
+namespace qtrapids {
+
+       
 QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) : 
                torrentHandle_(handle)
 {
 QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) : 
                torrentHandle_(handle)
 {
@@ -153,9 +156,7 @@ bool QTorrentHandle::operator<(QTorrentHandle const& h) const
        return torrentHandle_ < h.torrentHandle_;
 }
 
        return torrentHandle_ < h.torrentHandle_;
 }
 
-
-
-
+} // namespace qtrapids
 
 
                                
\ No newline at end of file
 
 
                                
\ No newline at end of file
index 0d8d4a5..855f0ca 100644 (file)
@@ -33,51 +33,55 @@ typedef libtorrent::torrent_handle TorrentHandle;
 /**
        @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
 */
 /**
        @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
 #endif
index ede3b66..d6c9183 100644 (file)
@@ -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);
 {
 #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);
                
 {
        //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() ;
 {
 #ifdef QTRAPIDS_DEBUG
        qDebug() << "DownloadView::removeSelected() " <<  topLevelItemCount() ;
@@ -122,9 +122,9 @@ QTorrentHandle DownloadView::removeSelected()
 
        DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
        
 
        DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
        
-       std::map<QTorrentHandle, DownloadViewItem*>::iterator listIter
+       std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listIter
                        = items_.begin();
                        = items_.begin();
-       std::map<QTorrentHandle, DownloadViewItem*>::iterator listEnd
+       std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listEnd
                        = items_.end();
        
        while (listIter != listEnd) {
                        = items_.end();
        
        while (listIter != listEnd) {
@@ -134,7 +134,7 @@ QTorrentHandle DownloadView::removeSelected()
                ++listIter;
        }
        
                ++listIter;
        }
        
-       QTorrentHandle handle = listIter->first;
+       qtrapids::QTorrentHandle handle = listIter->first;
        items_.erase(listIter);
 
        
        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) {
 {
        switch (status) {
-               case QTorrentHandle::QUEUED_FOR_CHECKING :
+               case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING :
                        return tr("Queued");
                        return tr("Queued");
-               case QTorrentHandle::CHECKING_FILES :
+               case qtrapids::QTorrentHandle::CHECKING_FILES :
                        return tr("Checking");
                        return tr("Checking");
-               case QTorrentHandle::DOWNLOADING_METADATA :
+               case qtrapids::QTorrentHandle::DOWNLOADING_METADATA :
                        return tr("DL meta");
                        return tr("DL meta");
-               case QTorrentHandle::DOWNLOADING :
+               case qtrapids::QTorrentHandle::DOWNLOADING :
                        return tr("Downloading");
                        return tr("Downloading");
-               case QTorrentHandle::FINISHED :
+               case qtrapids::QTorrentHandle::FINISHED :
                        return tr("Finished");
                        return tr("Finished");
-               case QTorrentHandle::SEEDING :
+               case qtrapids::QTorrentHandle::SEEDING :
                        return tr("Seeding"); 
                        return tr("Seeding"); 
-               case QTorrentHandle::ALLOCATING :
+               case qtrapids::QTorrentHandle::ALLOCATING :
                        return tr("Allocating");
                default:
                        return tr("N/A");
                        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) {
 {
        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;
                        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();
                                return green;
                default:
                        return QColor();
@@ -230,9 +230,9 @@ void DownloadView::UpdateView()
 {
        DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
        
 {
        DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
        
-       std::map<QTorrentHandle, DownloadViewItem*>::iterator listIter
+       std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listIter
                        = items_.begin();
                        = items_.begin();
-       std::map<QTorrentHandle, DownloadViewItem*>::iterator listEnd
+       std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listEnd
                        = items_.end();
        
        while (listIter != listEnd) {
                        = items_.end();
        
        while (listIter != listEnd) {
index 6fadb92..cb300ba 100644 (file)
@@ -43,10 +43,10 @@ Q_OBJECT
 
     ~DownloadView();
 
 
     ~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:
                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.
        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.
                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 UpdateView();
 
                
index a3262e1..4ccddd9 100644 (file)
@@ -129,7 +129,7 @@ void MainWindow::on_openAction_clicked()
 
 void MainWindow::on_removeAction_clicked()
 {
 
 void MainWindow::on_removeAction_clicked()
 {
-       QTorrentHandle handle = dlView_->removeSelected();
+       qtrapids::QTorrentHandle handle = dlView_->removeSelected();
        btSession_.removeTorrent(handle);
 }
 
        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;
        // 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
        dlView_->newItem(handle);
 //     torrentHandles_.push_back(handlePtr);
 #ifdef QTRAPIDS_DEBUG
@@ -234,8 +234,8 @@ void MainWindow::on_alert(std::auto_ptr<Alert> al)
                                = dynamic_cast<TorrentAlert*> (al.get());
 
                if (torrentAlert) {
                                = 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));
                }
        
        }
                }
        
        }
@@ -245,7 +245,7 @@ void MainWindow::on_alert(std::auto_ptr<Alert> al)
 }
 
 /*
 }
 
 /*
-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()) {
 {
        for (unsigned i = 0; i < torrentHandles_.size(); ++i) {
                if (torrentHandles_.at(i).get() == handlePtr.get()) {
index 275e1dd..3f546bb 100644 (file)
@@ -67,7 +67,7 @@ class MainWindow : public QMainWindow {
                
                //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
                
                
                //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
                
-               QBittorrentSession btSession_;
+               qtrapids::QBittorrentSession btSession_;
                
 
                //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
                
 
                //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
index 9b05e99..666a4c7 100644 (file)
@@ -37,8 +37,8 @@ Q_OBJECT
 
     ~SeedView();
                
 
     ~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);
 
        private slots:
                void on_itemPressed(QTreeWidgetItem *item, int column);