- Torrent can be now opened and download starts
[qtrapids] / src / gui / MainWindow.cpp
index 972e89a..1f1db3a 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "MainWindow.h"
 
-
 const QString ABOUT_TEXT 
        = QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
                "\nQt and Libtorrent."
@@ -87,7 +86,6 @@ MainWindow::MainWindow():
        // Tab widget as central widget.
        setCentralWidget(tabWidget_);
        
-       
        // TOOLBAR
        QToolBar *toolBar = new QToolBar();
        toolBar->addAction(tr("Open"));
@@ -95,6 +93,9 @@ MainWindow::MainWindow():
        addToolBar(Qt::TopToolBarArea, toolBar);
        connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
        
+       
+       connect(&btSession_, SIGNAL(alert(std::auto_ptr<TorrentAlert>)),
+                                        this, SLOT(on_torrentAlert(std::auto_ptr<TorrentAlert>)));
 }
 
 
@@ -162,7 +163,16 @@ void MainWindow::on_torrentFileSelected(const QString& file)
        boost::intrusive_ptr<libtorrent::torrent_info> tiTmp = 
                        new libtorrent::torrent_info(boost::filesystem::path(file.toStdString()));
        addParams.ti = tiTmp;
-       addParams.save_path = boost::filesystem::path(settings_.value("download/directory").toString().toStdString()); // The only mandatory parameter, rest are optional.
+       // 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;
-       btSession_.addTorrent(addParams);
+       std::auto_ptr<QTorrentHandle> handlePtr = btSession_.addTorrent(addParams);
+       dlView_->newItem(handlePtr.get());
+       qDebug() << "Is valid: " << handlePtr->isValid();
 }
+
+void MainWindow::on_torrentAlert(std::auto_ptr<TorrentAlert> al)
+{
+       if (al.get() != NULL)
+               qDebug() << "MainWindow::on_torrentAlert(): " << QString::fromStdString(al->message());
+}
\ No newline at end of file