- Added PreferencesDialog with settings saving and reading.
[qtrapids] / src / gui / MainWindow.cpp
index f5e6036..972e89a 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "DownloadView.h"
 #include "SeedView.h"
+#include "PreferencesDialog.h"
 
 #include "MainWindow.h"
 
@@ -47,6 +48,8 @@ MainWindow::MainWindow():
        tabWidget_(NULL),
        dlView_(NULL),
        seedView_(NULL),
+       preferencesDialog_(NULL),
+       settings_(),                                                                     
        btSession_()                                    
 {
        // MENUBAR 
@@ -57,6 +60,9 @@ MainWindow::MainWindow():
        QAction *openAction = tempMenu->addAction(tr("&Open"));
        QAction *quitAction = tempMenu->addAction(tr("&Quit"));
        
+       tempMenu = menuBar->addMenu(tr("&Settings"));
+       QAction *preferencesAction = tempMenu->addAction(tr("&Preferences"));
+       
        tempMenu = menuBar->addMenu(tr("&Help"));
        QAction *aboutAction = tempMenu->addAction(tr("&About"));
        QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
@@ -64,10 +70,10 @@ MainWindow::MainWindow():
                setMenuBar(menuBar);
        connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
        connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked()));
+       connect(preferencesAction, SIGNAL(triggered()), this, SLOT(on_preferencesAction_clicked()));
        connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
        connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
        
-       
        // TABWIDGET (central widget)
        tabWidget_ = new QTabWidget();
        
@@ -112,6 +118,15 @@ void MainWindow::on_quitAction_clicked()
        close();
 }
 
+void MainWindow::on_preferencesAction_clicked()
+{
+       if (!preferencesDialog_) {
+               preferencesDialog_ = new PreferencesDialog(this);
+       }
+       preferencesDialog_->show();
+       preferencesDialog_->raise();
+       preferencesDialog_->activateWindow();
+}
 
 void MainWindow::on_aboutAction_clicked()
 {
@@ -142,12 +157,12 @@ void MainWindow::on_torrentFileSelected(const QString& file)
        }
        
        // 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.
+       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.
        //addParams.storage_mode = libtorrent::storage_mode_allocate;
-       btSession_.addTorrent();
-       */
+       btSession_.addTorrent(addParams);
 }