Added build script of Debian
[qtrapids] / src / client / MainWindow.cpp
index 8b89ae8..551197a 100644 (file)
@@ -1,11 +1,9 @@
 /***************************************************************************
- *   Copyright (C) 2009 by Lassi Väätämöinen   *
- *   lassi.vaatamoinen@ixonos.com   *
+ *   Copyright (C) 2010 by Ixonos Plc   *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
+ *   the Free Software Foundation; version 2 of the License.               *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 #include <QAction>
 #include <QFileDialog>
 #include <QMessageBox>
+//#include <QTreeWidgetItem>
 #include <QApplication>
 #include <QPluginLoader>
 
 #include "DownloadView.h"
 #include "SeedView.h"
 #include "PreferencesDialog.h"
+#include "ColumnSelectorDialog.h"
 
 #include "MainWindow.h"
 
@@ -44,7 +44,7 @@ const QString ABOUT_TEXT
                           "\nQt and Libtorrent."
                           "\n\nURL: http://qtrapids.garage.maemo.org/"
                           "\n\nAuthors:\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com"
-                          "\nDenis Zalevskiy, denis.zalewsky@ixonos.com"
+                          "\nDenis Zalevskiy, denis.zalewsky@gmail.com"
                           "\n\nIxonos Plc, Finland\n"));
 
 const QString PLUGINS_DIR = "plugins";
@@ -56,6 +56,8 @@ MainWindow::MainWindow() :
                dlView_(NULL),
                seedView_(NULL),
                searchWidget_(NULL),
+               startDaemonAction_(NULL),
+               stopDaemonAction_(NULL),
                preferencesDialog_(NULL),
                settings_(QCoreApplication::organizationName()
                          , QCoreApplication::applicationName()),
@@ -64,6 +66,9 @@ MainWindow::MainWindow() :
                        , "/qtrapids", QDBusConnection::sessionBus())
                //      torrentHandles_(),
 {
+       
+       setWindowTitle("QtRapids");
+       
        // MENUBAR
        QMenuBar *menuBar = new QMenuBar();
        QMenu *tempMenu = NULL;
@@ -72,8 +77,16 @@ MainWindow::MainWindow() :
        QAction *openAction = tempMenu->addAction(tr("&Open"));
        QAction *removeAction = tempMenu->addAction(tr("&Remove"));
        removeAction->setEnabled(false);
+       
+       startDaemonAction_ = tempMenu->addAction(tr("S&tart daemon"));
+       stopDaemonAction_ = tempMenu->addAction(tr("Sto&p daemon"));
+       startDaemonAction_->setEnabled(false);
+       
        QAction *quitAction = tempMenu->addAction(tr("&Quit"));
 
+       tempMenu = menuBar->addMenu(tr("&View"));
+       QAction *columnsAction = tempMenu->addAction(tr("&Columns"));
+       
        tempMenu = menuBar->addMenu(tr("&Settings"));
        QAction *preferencesAction = tempMenu->addAction(tr("&Preferences"));
 
@@ -86,6 +99,9 @@ MainWindow::MainWindow() :
        connect(removeAction, SIGNAL(triggered()), this, SLOT(on_removeAction_clicked()));
        connect(this, SIGNAL(itemSelected(bool)), removeAction, SLOT(setEnabled(bool)));
        connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked()));
+       connect(startDaemonAction_, SIGNAL(triggered()), this, SLOT(on_startDaemonAction_clicked()));
+       connect(stopDaemonAction_, SIGNAL(triggered()), this, SLOT(on_stopDaemonAction_clicked()));
+       connect(columnsAction, SIGNAL(triggered()), this, SLOT(on_columnsAction_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()));
@@ -96,14 +112,14 @@ MainWindow::MainWindow() :
 
        /// @todo Exception handling
        dlView_ = new DownloadView(this);
-       seedView_ = new SeedView(this);
+       //seedView_ = new SeedView(this);
        tabWidget_->addTab(dlView_, tr("Downloads"));
-       tabWidget_->addTab(seedView_, tr("Seeds"));
+       //tabWidget_->addTab(seedView_, tr("Seeds"));
        connect(dlView_, SIGNAL(itemSelectionChanged()), this,
                SLOT(on_downloadItemSelectionChanged()));
 
-       connect(seedView_, SIGNAL(itemSelectionChanged()), this,
-               SLOT(on_seedItemSelectionChanged()));
+       //connect(seedView_, SIGNAL(itemSelectionChanged()), this,
+       //        SLOT(on_seedItemSelectionChanged()));
 
        // Tab widget as central widget.
        setCentralWidget(tabWidget_);
@@ -113,7 +129,7 @@ MainWindow::MainWindow() :
        toolBar->addAction(tr("Open"));
        removeAction = toolBar->addAction(tr("Remove"));
        removeAction->setEnabled(false);
-       addToolBar(Qt::TopToolBarArea, toolBar);
+       addToolBar(Qt::BottomToolBarArea, toolBar);
 
        connect(this, SIGNAL(itemSelected(bool)), removeAction,
                SLOT(setEnabled(bool)));
@@ -123,7 +139,9 @@ MainWindow::MainWindow() :
 
        connect(&server_, SIGNAL(alert(qtrapids::TorrentState, qtrapids::ParamsMap_t)), 
                                        this, SLOT(on_alert(qtrapids::TorrentState, qtrapids::ParamsMap_t)));
-                                       
+       
+       connect(&server_, SIGNAL(sessionTerminated()), this, SLOT(on_serverTerminated()));
+       
 //     connect(&btSession_, SIGNAL(alert(std::auto_ptr<Alert>)),
 //             this, SLOT(on_alert(std::auto_ptr<Alert>)));
 
@@ -290,6 +308,9 @@ void MainWindow::RestoreSettings()
                restoreGeometry(geometry.toByteArray());
        }
        
+       // Restore DownloadView columns:
+       dlView_->restoreView();
+       
        // Restore torrent session settings to server:
        qtrapids::ParamsMap_t options;
        options["net/downloadRate"] = settings_.value("net/downloadRate").toString();
@@ -307,11 +328,14 @@ void MainWindow::StartTorrentFromBufferData(char const* data, int size)
 // =========================== PRIVATE SLOTS =================================
 void MainWindow::on_openAction_clicked()
 {
+       QString filename = QFileDialog::getOpenFileName( this, tr("Open torrent file"), QString(), tr("Torrent files (*.torrent)") );
+       on_torrentFileSelected(filename);
+       /*
        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_removeAction_clicked()
@@ -320,7 +344,7 @@ void MainWindow::on_removeAction_clicked()
        try {
                server_.removeTorrent(hash);
        } catch (...) {
-               qDebug() << "Exception removing torrent";
+               qDebug() << "Exception while removing torrent";
        }
 }
 
@@ -331,6 +355,44 @@ void MainWindow::on_quitAction_clicked()
 }
 
 
+void MainWindow::on_startDaemonAction_clicked()
+{
+       server_.getState();
+       /// @todo create signal that signals server startup and 
+       /// enable controls in the handler slot
+       stopDaemonAction_->setEnabled(true);
+       startDaemonAction_->setEnabled(false);
+}
+
+
+void MainWindow::on_stopDaemonAction_clicked()
+{
+       server_.terminateSession();
+}
+
+
+void MainWindow::on_serverTerminated()
+{
+       stopDaemonAction_->setEnabled(false);
+       startDaemonAction_->setEnabled(true);
+}
+
+void MainWindow::on_columnsAction_clicked()
+{      
+       ColumnSelectorDialog *dialog = new ColumnSelectorDialog(dlView_);
+       dialog->show();
+       dialog->exec();
+//     dialog->raise();
+//     dialog->activateWindow();
+       qDebug() << "dialog exit";
+
+       if (dialog->result() == QDialog::Accepted) {
+       qDebug() << "saved";
+               dlView_->saveView();
+       }
+}
+
+
 void MainWindow::on_preferencesAction_clicked()
 {
        if (!preferencesDialog_) {
@@ -407,7 +469,7 @@ void MainWindow::handleToolBarAction(QAction* action)
 }
 
 
-void MainWindow::on_torrentFileSelected(const QString& file)
+void MainWindow::on_torrentFileSelected(QString file)
 {
 #ifdef QTRAPIDS_DEBUG
        qDebug() << " MainWindow::on_torrentFileSelected(): " << file;