-Added QTorrentHandle and started torrent adding implementation
[qtrapids] / src / gui / MainWindow.cpp
index 9615959..f5e6036 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "DownloadView.h"
 #include "SeedView.h"
-#include "AlertWaiterThread.h"
 
 #include "MainWindow.h"
 
@@ -42,26 +41,29 @@ const QString ABOUT_TEXT
                "\n\nIxonos Plc, Finland\n"));
 
 
-
+// Consturctor
 MainWindow::MainWindow():
        QMainWindow(), // Superclass
        tabWidget_(NULL),
        dlView_(NULL),
-       seedView_(NULL)
+       seedView_(NULL),
+       btSession_()                                    
 {
-       
        // MENUBAR 
        QMenuBar *menuBar = new QMenuBar();
        QMenu *tempMenu = NULL;
        
        tempMenu = menuBar->addMenu(tr("&File"));
-       tempMenu->addAction(tr("&Open"));
+       QAction *openAction = tempMenu->addAction(tr("&Open"));
+       QAction *quitAction = tempMenu->addAction(tr("&Quit"));
        
        tempMenu = menuBar->addMenu(tr("&Help"));
        QAction *aboutAction = tempMenu->addAction(tr("&About"));
        QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
        
-       setMenuBar(menuBar);
+               setMenuBar(menuBar);
+       connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
+       connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked()));
        connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
        connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
        
@@ -87,9 +89,6 @@ MainWindow::MainWindow():
        addToolBar(Qt::TopToolBarArea, toolBar);
        connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
        
-       alertWaiter_ = new AlertWaiterThread(this);
-       connect(alertWaiter_, SIGNAL(alert()), this, SLOT(on_alert()));
-       alertWaiter_->start();
 }
 
 
@@ -97,12 +96,29 @@ MainWindow::~MainWindow()
 {
 }
 
+// =========================== SLOTS =================================
+void MainWindow::on_openAction_clicked()
+{
+       QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
+       dialog->setFileMode(QFileDialog::ExistingFile);
+       connect(dialog, SIGNAL(fileSelected(const QString&)), this, SLOT(on_torrentFileSelected(const QString&)));
+       dialog->show();
+
+}
+
+
+void MainWindow::on_quitAction_clicked()
+{
+       close();
+}
+
 
 void MainWindow::on_aboutAction_clicked()
 {
        QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT); 
 }
                
+               
 void MainWindow::on_aboutQtAction_clicked()
 {
        QMessageBox::aboutQt (this, tr("About Qt"));
@@ -112,14 +128,26 @@ void MainWindow::on_aboutQtAction_clicked()
 void MainWindow::handleToolBarAction(QAction* action)
 {
        if (action->text() == "Open") {
-               QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
-               dialog->setFileMode(QFileDialog::ExistingFile);
-               dialog->show();
+               on_openAction_clicked();
        } else {
        }
 }
 
-void MainWindow::on_alert()
+void MainWindow::on_torrentFileSelected(const QString& file)
 {
-       qDebug() << "MainWindow: got alert()";
+       qDebug() << " MainWindow::on_torrentFileSelected(): " << file;
+       // Torrent filename empty, do nothing.
+       if (file == "") {
+               return;
+       }
+       
+       // Otherwise add torrent
+       /*      
+       // For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent
+       AddTorrentParams addParams;
+       addParams.ti = torrent_info(boost::filesystem::path const& filename);
+       addParams.save_path = "/home/vaatala/Downloads"; // The only mandatory parameter, rest are optional.
+       //addParams.storage_mode = libtorrent::storage_mode_allocate;
+       btSession_.addTorrent();
+       */
 }