updating files
authorapte <abhijit.apte@nokia.com>
Thu, 19 Nov 2009 19:06:46 +0000 (19:06 +0000)
committerapte <abhijit.apte@nokia.com>
Thu, 19 Nov 2009 19:06:46 +0000 (19:06 +0000)
git-svn-id: file:///svnroot/qtrapids/branches/draftharmattan@43 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda

src/client/MainWindow.cpp [deleted file]
src/client/MainWindow.h [deleted file]
src/client/MainWindowPage.cpp [new file with mode: 0644]
src/client/MainWindowPage.h [new file with mode: 0644]
src/gui/MainWindow.cpp [deleted file]
src/gui/MainWindow.h [deleted file]

diff --git a/src/client/MainWindow.cpp b/src/client/MainWindow.cpp
deleted file mode 100644 (file)
index 5549bb9..0000000
+++ /dev/null
@@ -1,234 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2009 by Lassi Väätämöinen   *
- *   lassi.vaatamoinen@ixonos.com   *
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
- ***************************************************************************/
-
-
-#include <qtrapids/dbus.hpp>
-
-#include <QDebug>
-#include <QtGui/QMenuBar>
-#include <QtGui/QToolBar>
-#include <QAction>
-#include <QtGui/QFileDialog>
-#include <QtGui/QMessageBox>
-#include <QtGui/QTabWidget>
-
-#include "DownloadView.h"
-#include "SeedView.h"
-#include "PreferencesDialog.h"
-
-#include "MainWindow.h"
-
-namespace qtrapids
-{
-
-const QString ABOUT_TEXT
-= QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
-                          "\nQt and Libtorrent."
-                          "\n\nURL: http://qtrapids.garage.maemo.org/"
-                          "\n\nAuthor(s):\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com"
-                          "\nDenis Zalevskiy, denis.zalewsky@ixonos.com"
-                          "\n\nIxonos Plc, Finland\n"));
-
-
-// Consturctor
-MainWindow::MainWindow() :
-               QMainWindow(), // Superclass
-               tabWidget_(NULL),
-               dlView_(NULL),
-               seedView_(NULL),
-               preferencesDialog_(NULL),
-               settings_(QCoreApplication::organizationName()
-                         , QCoreApplication::applicationName()),
-               server_(QtRapidsServer::staticInterfaceName()
-                       , "/qtrapids", QDBusConnection::sessionBus())
-               //      torrentHandles_(),
-{
-       // MENUBAR
-       QMenuBar *menuBar = new QMenuBar();
-       QMenu *tempMenu = NULL;
-
-       tempMenu = menuBar->addMenu(tr("&File"));
-       QAction *openAction = tempMenu->addAction(tr("&Open"));
-       QAction *removeAction = tempMenu->addAction(tr("&Remove"));
-       removeAction->setEnabled(false);
-       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"));
-
-       setMenuBar(menuBar);
-       connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
-       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(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();
-
-       /// @todo Exception handling
-       dlView_ = new DownloadView(this);
-       seedView_ = new SeedView(this);
-       tabWidget_->addTab(dlView_, tr("Downloads"));
-       tabWidget_->addTab(seedView_, tr("Seeds"));
-       connect(dlView_, SIGNAL(itemSelectionChanged()), this,
-               SLOT(on_downloadItemSelectionChanged()));
-
-       connect(seedView_, SIGNAL(itemSelectionChanged()), this,
-               SLOT(on_seedItemSelectionChanged()));
-
-       // Tab widget as central widget.
-       setCentralWidget(tabWidget_);
-
-       // TOOLBAR
-       QToolBar *toolBar = new QToolBar();
-       toolBar->addAction(tr("Open"));
-       removeAction = toolBar->addAction(tr("Remove"));
-       removeAction->setEnabled(false);
-       addToolBar(Qt::TopToolBarArea, toolBar);
-
-       connect(this, SIGNAL(itemSelected(bool)), removeAction,
-               SLOT(setEnabled(bool)));
-       connect(toolBar, SIGNAL(actionTriggered(QAction*)), this,
-               SLOT(handleToolBarAction(QAction*)));
-
-       QVariant geometry(settings_.value("geometry"));
-       if (!geometry.isNull()) {
-               qDebug() << "restoring geometry";
-               restoreGeometry(geometry.toByteArray());
-       }
-}
-
-
-MainWindow::~MainWindow()
-{
-       settings_.setValue("geometry", saveGeometry());
-}
-
-// =========================== 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_removeAction_clicked()
-{
-       QString hash = dlView_->prepareRemoveSelected();
-       try {
-               server_.removeTorrent(hash);
-       } catch (...) {
-               qDebug() << "Exception removing torrent";
-       }
-}
-
-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()
-{
-       QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT);
-}
-
-
-void MainWindow::on_aboutQtAction_clicked()
-{
-       QMessageBox::aboutQt (this, tr("About Qt"));
-}
-
-
-void MainWindow::on_downloadItemSelectionChanged()
-{
-       qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem();
-       if (dlView_->currentItem() != NULL) {
-               emit(itemSelected(true));
-       } else {
-               emit(itemSelected(false));
-       }
-}
-
-void MainWindow::on_seedItemSelectionChanged()
-{
-       qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem();
-       if (seedView_->currentItem() != NULL) {
-               emit(itemSelected(true));
-       } else {
-               emit(itemSelected(false));
-       }
-}
-
-void MainWindow::handleToolBarAction(QAction* action)
-{
-       if (action->text() == "Open") {
-               on_openAction_clicked();
-       } else if (action->text() == "Remove") {
-               on_removeAction_clicked();
-       }
-}
-
-void MainWindow::on_torrentFileSelected(const QString& file)
-{
-       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
-       // save_path is the only mandatory parameter, rest are optional.
-       //addParams.storage_mode = libtorrent::storage_mode_allocate;
-       try {
-               server_.addTorrent(file, settings_.value("download/directory").toString()
-                                  , ParamsMap_t());
-       } catch (...) {
-               qDebug() << "Exception adding torrent";
-       }
-}
-
-
-void MainWindow::alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info)
-{
-       std::cerr << "got alert" << std::endl;
-       dlView_->updateItem(info, other_info);
-}
-
-} // namespace qtrapids
diff --git a/src/client/MainWindow.h b/src/client/MainWindow.h
deleted file mode 100644 (file)
index 9b55d5b..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2009 by Lassi Väätämöinen   *
- *   lassi.vaatamoinen@ixonos.com   *
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
- ***************************************************************************/
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QSettings>
-
-#include "proxy.h"
-
-class QTabWidget;
-class DownloadView;
-class PreferencesDialog;
-
-namespace qtrapids
-{
-
-class SeedView;
-
-/**
-   @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
-*/
-class MainWindow : public QMainWindow
-{
-       Q_OBJECT;
-
-public:
-
-       MainWindow();
-       ~MainWindow();
-
-       void connectToServer() {
-               qDBusRegisterMetaType<qtrapids::TorrentState>();
-               qDBusRegisterMetaType<qtrapids::ParamsMap_t>();
-
-               connect(&server_
-                       , SIGNAL(alert(qtrapids::TorrentState
-                                      , qtrapids::ParamsMap_t))
-                       , this
-                       , SLOT(alert(qtrapids::TorrentState
-                                    , qtrapids::ParamsMap_t)));
-               server_.getState();
-       }
-
-signals:
-       void itemSelected(bool enabled);
-
-public slots:
-private slots:
-       void on_openAction_clicked();
-       void on_removeAction_clicked();
-       void on_quitAction_clicked();
-       void on_preferencesAction_clicked();
-       void on_aboutAction_clicked();
-       void on_aboutQtAction_clicked();
-       void on_downloadItemSelectionChanged();
-       void on_seedItemSelectionChanged();
-       void handleToolBarAction(QAction* action);
-       void on_torrentFileSelected(const QString& file);
-       void alert(qtrapids::TorrentState, qtrapids::ParamsMap_t);
-
-private:
-       QTabWidget *tabWidget_;
-       DownloadView *dlView_;
-       SeedView *seedView_;
-       PreferencesDialog *preferencesDialog_;
-       QSettings settings_;
-
-       //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
-
-       QtRapidsServer server_;
-
-
-       //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
-};
-
-} // namespace qtrapids
-
-#endif
diff --git a/src/client/MainWindowPage.cpp b/src/client/MainWindowPage.cpp
new file mode 100644 (file)
index 0000000..edb2b35
--- /dev/null
@@ -0,0 +1,275 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Lassi Väätämöinen   *
+ *   lassi.vaatamoinen@ixonos.com   *
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+
+#include <qtrapids/dbus.hpp>
+
+#include <QDebug>
+#include <QtGui/QMenuBar>
+#include <QtGui/QToolBar>
+#include <QAction>
+#include <QtGui/QFileDialog>
+#include <QtGui/QMessageBox>
+#include <QtGui/QTabWidget>
+
+#include "DownloadView.h"
+#include "SeedView.h"
+#include "PreferencesDialog.h"
+
+#include "MainWindowPage.h"
+
+namespace qtrapids
+{
+
+const QString ABOUT_TEXT
+= QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
+                          "\nQt and Libtorrent."
+                          "\n\nURL: http://qtrapids.garage.maemo.org/"
+                          "\n\nAuthor(s):\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com"
+                          "\nDenis Zalevskiy, denis.zalewsky@ixonos.com"
+                          "\n\nIxonos Plc, Finland\n"));
+
+
+// Consturctor
+MainWindowPage::MainWindowPage() :
+               DuiApplicationPage()
+               //QMainWindowPage(), // Superclass
+               tabWidget_(NULL),
+               dlView_(NULL),
+               seedView_(NULL),
+               preferencesDialog_(NULL),
+               settings_(QCoreApplication::organizationName()
+                         , QCoreApplication::applicationName()),
+               server_(QtRapidsServer::staticInterfaceName()
+                       , "/qtrapids", QDBusConnection::sessionBus())
+               //      torrentHandles_(),
+{}
+
+
+void MainWindowPage::createContent()
+{
+       // MENUBAR
+#if 0
+       QMenuBar *menuBar = new QMenuBar();
+       QMenu *tempMenu = NULL;
+
+       tempMenu = menuBar->addMenu(tr("&File"));
+       QAction *openAction = tempMenu->addAction(tr("&Open"));
+       QAction *removeAction = tempMenu->addAction(tr("&Remove"));
+       removeAction->setEnabled(false);
+       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"));
+
+       setMenuBar(menuBar);
+#endif
+       
+       DuiAction* action;
+       DuiWidget* panel = centralWidget();
+       DuiLayout* layout = new DuiLayout( panel );
+       panel->setLayout( layout );
+       DuiLinearLayoutPolicy* policy = new DuiLinearLayoutPolicy( layout, Qt::Vertical );
+       policy->setContentMargins( 12, 12, 12, 12 );
+
+       action = new DuiAction( NULL, "Open", panel );
+       action->setLocation( DuiAction::ViewMenu );
+       this->addAction( action );
+       connect(action, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
+
+       action = new DuiAction( NULL, "Remove", panel );
+       action->setLocation( DuiAction::ViewMenu );
+       this->addAction( action );
+       connect(action, SIGNAL(triggered()), this, SLOT(on_removeAction_clicked()));
+
+       //connect(this, SIGNAL(itemSelected(bool)), removeAction, SLOT(setEnabled(bool)));
+       
+       action = new DuiAction( NULL, "Quit", panel );
+       action->setLocation( DuiAction::ViewMenu );
+       this->addAction( action );
+       connect(action, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked()));
+
+       action = new DuiAction( NULL, "Preferences", panel );
+       action->setLocation( DuiAction::ViewMenu );
+       this->addAction( action );
+       connect(action, SIGNAL(triggered()), this, SLOT(on_preferencesAction_clicked()));
+       
+       action = new DuiAction( NULL, "About", panel );
+       action->setLocation( DuiAction::ViewMenu );
+       this->addAction( action );
+       connect(action, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
+
+       action = new DuiAction( NULL, "About Qt", panel );
+       connect(action, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
+
+#if 0
+       // TABWIDGET (central widget)
+       tabWidget_ = new QTabWidget();
+#endif
+
+       /// @todo Exception handling
+       dlView_ = new DownloadView(this);
+       seedView_ = new SeedView(this);
+       tabWidget_->addTab(dlView_, tr("Downloads"));
+       tabWidget_->addTab(seedView_, tr("Seeds"));
+       connect(dlView_, SIGNAL(itemSelectionChanged()), this,
+               SLOT(on_downloadItemSelectionChanged()));
+
+       connect(seedView_, SIGNAL(itemSelectionChanged()), this,
+               SLOT(on_seedItemSelectionChanged()));
+
+#if 0
+       // Tab widget as central widget.
+       setCentralWidget(tabWidget_);
+
+       // TOOLBAR
+       QToolBar *toolBar = new QToolBar();
+       toolBar->addAction(tr("Open"));
+       removeAction = toolBar->addAction(tr("Remove"));
+       removeAction->setEnabled(false);
+       addToolBar(Qt::TopToolBarArea, toolBar);
+
+       connect(this, SIGNAL(itemSelected(bool)), removeAction,
+               SLOT(setEnabled(bool)));
+       connect(toolBar, SIGNAL(actionTriggered(QAction*)), this,
+               SLOT(handleToolBarAction(QAction*)));
+
+       QVariant geometry(settings_.value("geometry"));
+       if (!geometry.isNull()) {
+               qDebug() << "restoring geometry";
+               restoreGeometry(geometry.toByteArray());
+       }
+#endif
+}
+
+
+MainWindowPage::~MainWindowPage()
+{
+       settings_.setValue("geometry", saveGeometry());
+}
+
+// =========================== SLOTS =================================
+void MainWindowPage::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 MainWindowPage::on_removeAction_clicked()
+{
+       QString hash = dlView_->prepareRemoveSelected();
+       try {
+               server_.removeTorrent(hash);
+       } catch (...) {
+               qDebug() << "Exception removing torrent";
+       }
+}
+
+void MainWindowPage::on_quitAction_clicked()
+{
+       close();
+}
+
+void MainWindowPage::on_preferencesAction_clicked()
+{
+       if (!preferencesDialog_) {
+               preferencesDialog_ = new PreferencesDialog(this);
+       }
+       preferencesDialog_->show();
+       preferencesDialog_->raise();
+       preferencesDialog_->activateWindow();
+}
+
+void MainWindowPage::on_aboutAction_clicked()
+{
+       QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT);
+}
+
+
+void MainWindowPage::on_aboutQtAction_clicked()
+{
+       QMessageBox::aboutQt (this, tr("About Qt"));
+}
+
+
+void MainWindowPage::on_downloadItemSelectionChanged()
+{
+       qDebug() << "MainWindowPage::on_seedItemSelectionChanged():" << dlView_->currentItem();
+       if (dlView_->currentItem() != NULL) {
+               emit(itemSelected(true));
+       } else {
+               emit(itemSelected(false));
+       }
+}
+
+void MainWindowPage::on_seedItemSelectionChanged()
+{
+       qDebug() << "MainWindowPage::on_seedItemSelectionChanged():" << seedView_->currentItem();
+       if (seedView_->currentItem() != NULL) {
+               emit(itemSelected(true));
+       } else {
+               emit(itemSelected(false));
+       }
+}
+
+void MainWindowPage::handleToolBarAction(QAction* action)
+{
+       if (action->text() == "Open") {
+               on_openAction_clicked();
+       } else if (action->text() == "Remove") {
+               on_removeAction_clicked();
+       }
+}
+
+void MainWindowPage::on_torrentFileSelected(const QString& file)
+{
+       qDebug() << " MainWindowPage::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
+       // save_path is the only mandatory parameter, rest are optional.
+       //addParams.storage_mode = libtorrent::storage_mode_allocate;
+       try {
+               server_.addTorrent(file, settings_.value("download/directory").toString()
+                                  , ParamsMap_t());
+       } catch (...) {
+               qDebug() << "Exception adding torrent";
+       }
+}
+
+
+void MainWindowPage::alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info)
+{
+       std::cerr << "got alert" << std::endl;
+       dlView_->updateItem(info, other_info);
+}
+
+} // namespace qtrapids
diff --git a/src/client/MainWindowPage.h b/src/client/MainWindowPage.h
new file mode 100644 (file)
index 0000000..72b423e
--- /dev/null
@@ -0,0 +1,96 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Lassi Väätämöinen   *
+ *   lassi.vaatamoinen@ixonos.com   *
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <DuiApplicationPage>
+#include <QSettings>
+
+#include "proxy.h"
+
+class QTabWidget;
+class DownloadView;
+class PreferencesDialog;
+
+namespace qtrapids
+{
+
+class SeedView;
+
+/**
+   @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
+*/
+class MainWindowPage : public DuiApplicationPage //QMainWindowPage
+{
+       Q_OBJECT;
+
+public:
+
+       MainWindowPage();
+       ~MainWindowPage();
+
+       void connectToServer() {
+               qDBusRegisterMetaType<qtrapids::TorrentState>();
+               qDBusRegisterMetaType<qtrapids::ParamsMap_t>();
+
+               connect(&server_
+                       , SIGNAL(alert(qtrapids::TorrentState
+                                      , qtrapids::ParamsMap_t))
+                       , this
+                       , SLOT(alert(qtrapids::TorrentState
+                                    , qtrapids::ParamsMap_t)));
+               server_.getState();
+       }
+
+signals:
+       void itemSelected(bool enabled);
+
+public slots:
+private slots:
+       void on_openAction_clicked();
+       void on_removeAction_clicked();
+       void on_quitAction_clicked();
+       void on_preferencesAction_clicked();
+       void on_aboutAction_clicked();
+       void on_aboutQtAction_clicked();
+       void on_downloadItemSelectionChanged();
+       void on_seedItemSelectionChanged();
+       void handleToolBarAction(QAction* action);
+       void on_torrentFileSelected(const QString& file);
+       void alert(qtrapids::TorrentState, qtrapids::ParamsMap_t);
+
+private:
+       QTabWidget *tabWidget_;
+       DownloadView *dlView_;
+       SeedView *seedView_;
+       PreferencesDialog *preferencesDialog_;
+       QSettings settings_;
+
+       //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
+
+       QtRapidsServer server_;
+
+
+       //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
+};
+
+} // namespace qtrapids
+
+#endif
diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp
deleted file mode 100644 (file)
index 884ced0..0000000
+++ /dev/null
@@ -1,362 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2009 by Lassi Väätämöinen   *
- *   lassi.vaatamoinen@ixonos.com   *
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
- ***************************************************************************/
-
-
-#include <QDebug>
-
-#include <QMenuBar>
-#include <QToolBar>
-#include <QAction>
-#include <QFileDialog>
-#include <QMessageBox>
-#include <QApplication>
-#include <QPluginLoader>
-
-#include "DownloadView.h"
-#include "SeedView.h"
-#include "PreferencesDialog.h"
-
-#include "MainWindow.h"
-
-const QString ABOUT_TEXT
-= QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
-                          "\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"
-                          "\n\nIxonos Plc, Finland\n"));
-
-// Consturctor
-MainWindow::MainWindow():
-               QMainWindow(), // Superclass
-               tabWidget_(NULL),
-               dlView_(NULL),
-               seedView_(NULL),
-               preferencesDialog_(NULL),
-               settings_(),
-//     torrentHandles_(),
-               btSession_()
-{
-       // MENUBAR
-       QMenuBar *menuBar = new QMenuBar();
-       QMenu *tempMenu = NULL;
-
-       tempMenu = menuBar->addMenu(tr("&File"));
-       QAction *openAction = tempMenu->addAction(tr("&Open"));
-       QAction *removeAction = tempMenu->addAction(tr("&Remove"));
-       removeAction->setEnabled(false);
-       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"));
-
-       setMenuBar(menuBar);
-       connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
-       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(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();
-       tabWidget_->setTabsClosable(true);
-
-       /// @todo Exception handling
-       dlView_ = new DownloadView(this);
-       seedView_ = new SeedView(this);
-       tabWidget_->addTab(dlView_, tr("Downloads"));
-       tabWidget_->addTab(seedView_, tr("Seeds"));
-       connect(dlView_, SIGNAL(itemSelectionChanged()), this,
-               SLOT(on_downloadItemSelectionChanged()));
-       connect(seedView_, SIGNAL(itemSelectionChanged()), this,
-               SLOT(on_seedItemSelectionChanged()));
-
-
-       // Tab widget as central widget.
-       setCentralWidget(tabWidget_);
-
-       // TOOLBAR
-       QToolBar *toolBar = new QToolBar();
-       toolBar->addAction(tr("Open"));
-       removeAction = toolBar->addAction(tr("Remove"));
-       removeAction->setEnabled(false);
-       addToolBar(Qt::TopToolBarArea, toolBar);
-
-       connect(this, SIGNAL(itemSelected(bool)), removeAction,
-               SLOT(setEnabled(bool)));
-       connect(toolBar, SIGNAL(actionTriggered(QAction*)), this,
-               SLOT(handleToolBarAction(QAction*)));
-
-       connect(&btSession_, SIGNAL(alert(std::auto_ptr<Alert>)),
-               this, SLOT(on_alert(std::auto_ptr<Alert>)));
-
-       LoadPlugins();
-}
-
-
-MainWindow::~MainWindow()
-{
-}
-
-// ===================== Implements PluginInterface =========================
-bool MainWindow::setGui(QWidget* widget, PluginWidgetType type)
-{
-#ifdef QTRAPIDS_DEBUG
-       qDebug() << "MainWindow::setGui():" << dlView_->currentItem();
-#endif
-       tabWidget_->addTab(widget, tr("Search"));
-       return true;
-}
-
-/// @todo Add PluginInterface parameter check which plugin gives the widget to handle appropriately
-void MainWindow::addPluginWidget(QWidget* widget, PluginWidgetType type)
-{
-#ifdef QTRAPIDS_DEBUG
-       qDebug() << "MainWindow::addPluginWidget():" << dlView_->currentItem();
-#endif
-
-       if (type == qtrapids::PluginHostInterface::TAB_PAGE) {
-               int index = tabWidget_->addTab(widget, tr("Test"));
-               tabWidget_->setCurrentIndex(index);
-               //layout_->addWidget(widget);
-       }
-}
-void MainWindow::addToolbar(QWidget* widget, PluginWidgetType type)
-{
-}
-
-void MainWindow::addToolItem(QWidget* widget, PluginWidgetType type)
-{
-}
-
-void MainWindow::addMenu(QWidget* widget, PluginWidgetType type)
-{
-}
-
-void MainWindow::addMenuItem(QWidget* widget, PluginWidgetType type)
-{
-}
-
-bool MainWindow::eventRequest(QVariant param, PluginRequest req)
-{
-       if (req == qtrapids::PluginHostInterface::OPEN_FILE) {
-                       QString sourceFile = param.toString();
-                       
-               // Get the source files name from the full path:
-               QFileInfo fInfo(sourceFile);
-               QString targetFile = fInfo.fileName();
-               targetFile = settings_.value("download/directory").toString() + targetFile;
-               
-               // Copy temoporary file to Downloads directory...
-               if (!QFile::copy(sourceFile, targetFile)) {
-                       qDebug() << "File copying failed";
-                       return false;
-               } else {
-                       // If copying was successful, remove the original temporary file.
-                       QFile::remove(sourceFile);
-               }
-                       
-               // ...and start the torrent:
-               on_torrentFileSelected(targetFile);
-       }
-       
-       return true;
-}
-
-
-//=========================== PRIVATE ================================
-
-void MainWindow::LoadPlugins()
-{
-       /// @todo get plugin directory from settings or go through multiple directories
-       /// Now we only check the application directory
-       pluginsDir_ = QDir(qApp->applicationDirPath());
-       pluginsDir_.cd("plugins");
-       QStringList nameFilters;
-       nameFilters << "*.so";
-
-       foreach (QString fileName, pluginsDir_.entryList(nameFilters, QDir::Files)) {
-               QPluginLoader pluginLoader(pluginsDir_.absoluteFilePath(fileName));
-
-               if (!QLibrary::isLibrary(fileName)) {
-                       qDebug() << fileName << " not a library";
-               }
-
-               if (pluginLoader.load()) {
-                       qDebug() << "Plugin loaded: "  << fileName;
-               } else {
-                       qDebug() << "Plugin load failed: " << pluginLoader.errorString();
-               }
-
-               QObject *baseInstance = pluginLoader.instance();
-               if (!baseInstance) {
-                       qDebug() << "Base instance = NULL.";
-               }
-
-               qtrapids::PluginInterface *plugin = qobject_cast<qtrapids::PluginInterface*>(baseInstance);
-
-               if (!plugin) {
-                       qDebug() << "Cast failed.";
-               } else {
-                       plugin->initialize(this);
-                       pluginFileNames_ += fileName;
-               }
-       }
-}
-
-// =========================== 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_removeAction_clicked()
-{
-       qtrapids::QTorrentHandle handle = dlView_->removeSelected();
-       btSession_.removeTorrent(handle);
-}
-
-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()
-{
-       QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT);
-}
-
-
-void MainWindow::on_aboutQtAction_clicked()
-{
-       QMessageBox::aboutQt (this, tr("About Qt"));
-}
-
-
-void MainWindow::on_downloadItemSelectionChanged()
-{
-#ifdef QTRAPIDS_DEBUG
-       qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem();
-#endif
-       if (dlView_->currentItem() != NULL) {
-               emit(itemSelected(true));
-       } else {
-               emit(itemSelected(false));
-       }
-}
-
-void MainWindow::on_seedItemSelectionChanged()
-{
-#ifdef QTRAPIDS_DEBUG
-       qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem();
-#endif
-       if (seedView_->currentItem() != NULL) {
-               emit(itemSelected(true));
-       } else {
-               emit(itemSelected(false));
-       }
-}
-
-void MainWindow::handleToolBarAction(QAction* action)
-{
-       if (action->text() == "Open") {
-               on_openAction_clicked();
-       } else if (action->text() == "Remove") {
-               on_removeAction_clicked();
-       }
-}
-
-void MainWindow::on_torrentFileSelected(const QString& file)
-{
-#ifdef QTRAPIDS_DEBUG
-       qDebug() << " MainWindow::on_torrentFileSelected(): " << file;
-#endif
-       // 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;
-       boost::intrusive_ptr<libtorrent::torrent_info> tiTmp =
-           new libtorrent::torrent_info(boost::filesystem::path(file.toStdString()));
-       addParams.ti = tiTmp;
-       // 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;
-       qtrapids::QTorrentHandle handle = btSession_.addTorrent(addParams);
-       dlView_->newItem(handle);
-//     torrentHandles_.push_back(handlePtr);
-#ifdef QTRAPIDS_DEBUG
-       qDebug() << "Is valid: " << handle.isValid();
-#endif
-}
-
-
-void MainWindow::on_alert(std::auto_ptr<Alert> al)
-{
-       if (al.get() != NULL) {
-//             qDebug()
-//                             << "MainWindow::on_torrentAlert(): "
-//                             << QString::fromStdString(al->message());
-
-               TorrentAlert *torrentAlert
-               = dynamic_cast<TorrentAlert*> (al.get());
-
-               if (torrentAlert) {
-                       qtrapids::QTorrentHandle torrentHandle = qtrapids::QTorrentHandle(torrentAlert->handle);
-                       dlView_->updateItem(qtrapids::QTorrentHandle(torrentAlert->handle));
-               }
-
-       }
-}
-
-/*
-bool MainWindow::IsNewTorrent(std::auto_ptr<qtrapids::QTorrentHandle> handlePtr)
-{
-       for (unsigned i = 0; i < torrentHandles_.size(); ++i) {
-    if (torrentHandles_.at(i).get() == handlePtr.get()) {
-                       return false;
-               } else {
-                       return true;
-               }
-       }
-}
-*/
diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h
deleted file mode 100644 (file)
index 4094a50..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2009 by Lassi Väätämöinen   *
- *   lassi.vaatamoinen@ixonos.com   *
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
- ***************************************************************************/
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QSettings>
-#include <QDir>
-#include <QStringList>
-
-#include "PluginInterface.h"
-#include "QBittorrentSession.h"
-
-class QTabWidget;
-class DownloadView;
-class SeedView;
-class PreferencesDialog;
-
-/**
-       @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
-*/
-class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface {
-       Q_OBJECT
-                       
-       public:
-    MainWindow();
-
-    virtual ~MainWindow();
-               
-               // Implemented from PluginHostInterface
-               virtual bool setGui(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
-               virtual void addPluginWidget(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
-               virtual void addToolbar(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
-               virtual void addToolItem(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
-               virtual void addMenu(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
-               virtual void addMenuItem(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
-               virtual bool eventRequest(QVariant param, PluginRequest req = UNKNOWN_REQUEST);
-               
-       signals:
-               void itemSelected(bool enabled);
-               
-       public slots:
-       private slots:
-               void on_openAction_clicked();
-               void on_removeAction_clicked();
-               void on_quitAction_clicked();
-               void on_preferencesAction_clicked();
-               void on_aboutAction_clicked();
-               void on_aboutQtAction_clicked();
-               void on_downloadItemSelectionChanged();
-               void on_seedItemSelectionChanged();
-               void handleToolBarAction(QAction* action);
-               void on_torrentFileSelected(const QString& file);
-               void on_alert(std::auto_ptr<Alert> al);
-       
-       private:
-               void LoadPlugins();
-               
-       private:
-               QTabWidget *tabWidget_;
-               DownloadView *dlView_;
-               SeedView *seedView_;
-               PreferencesDialog *preferencesDialog_;
-               QSettings settings_;
-               QDir pluginsDir_;
-               QStringList pluginFileNames_;
-               //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
-               
-               qtrapids::QBittorrentSession btSession_;
-               
-
-               //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
-};
-
-#endif