#include <QAction>
#include <QFileDialog>
#include <QMessageBox>
+#include <QApplication>
+
#include "DownloadView.h"
#include "SeedView.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 Zalievsky, denis.zalewsky@ixonos.com"
- "\n\nIxonos Plc, Finland\n"));
-
+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():
// 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();
-
- /// @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>)));
+ // 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();
}
{
}
+// ===================== Implements PluginInterface =========================
+bool MainWindow::setGui(qtrapids::PluginInterface* from, QWidget* widget)
+{
+#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(qtrapids::PluginInterface* from, QWidget* widget)
+{
+#ifdef QTRAPIDS_DEBUG
+ qDebug() << "MainWindow::addPluginWidget():" << dlView_->currentItem();
+#endif
+
+ int index = tabWidget_->addTab(widget, tr("Test"));
+ tabWidget_->setCurrentIndex(index);
+ //layout_->addWidget(widget);
+}
+
+void MainWindow::addToolbar(qtrapids::PluginInterface* from, QWidget* widget)
+{
+}
+
+void MainWindow::addToolItem(qtrapids::PluginInterface* from, QWidget* widget)
+{
+}
+
+void MainWindow::addMenu(qtrapids::PluginInterface* from, QWidget* widget)
+{
+}
+
+void MainWindow::addMenuItem(qtrapids::PluginInterface* from, QWidget* widget)
+{
+}
+
+//=========================== PRIVATE ================================
+
+void MainWindow::LoadPlugins()
+{
+ /// @todo get plugin directory from settings or go through multiple diectories
+ /// 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;
+ }
+
+// QObject *plugin = pluginLoader.instance();
+// if (plugin) {
+// populateMenus(plugin);
+// pluginFileNames += fileName;
+// }
+
+ }
+
+ //pluginLoader_.setFileName("../libsearchplugin.so");
+
+
+
+
+}
+
// =========================== SLOTS =================================
void MainWindow::on_openAction_clicked()
{
#include <QMainWindow>
#include <QSettings>
+#include <QDir>
+#include <QStringList>
+#include "PluginInterface.h"
#include "QBittorrentSession.h"
class QTabWidget;
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
*/
-class MainWindow : public QMainWindow
+class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface
{
- Q_OBJECT
+ Q_OBJECT
+
+ public:
+ MainWindow();
-public:
- MainWindow();
-
- ~MainWindow();
-
-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:
- QTabWidget *tabWidget_;
- DownloadView *dlView_;
- SeedView *seedView_;
- PreferencesDialog *preferencesDialog_;
- QSettings settings_;
-
- //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
-
- qtrapids::QBittorrentSession btSession_;
-
-
- //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
+ virtual ~MainWindow();
+
+ // Implemented from PluginHostInterface
+ virtual bool setGui(qtrapids::PluginInterface* from, QWidget* widget);
+ virtual void addPluginWidget(qtrapids::PluginInterface* from, QWidget* widget);
+ virtual void addToolbar(qtrapids::PluginInterface* from, QWidget* widget);
+ virtual void addToolItem(qtrapids::PluginInterface* from, QWidget* widget);
+ virtual void addMenu(qtrapids::PluginInterface* from, QWidget* widget);
+ virtual void addMenuItem(qtrapids::PluginInterface* from, QWidget* widget);
+
+ 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_;
+
+ qtrapids::QBittorrentSession btSession_;
+
};
#endif
+/***************************************************************************
+ * 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 <QtCore/qplugin.h>
#include <QVBoxLayout>
namespace qtrapids
{
+<<<<<<< .mine
+ SearchPlugin::SearchPlugin() :
+ comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL)
+ {
+ // TODO: Parse engine descriptions.
+ // -Add engines to model
+ // -Show model in comboBox
+
+ }
+
+ void SearchPlugin::initialize(PluginHostInterface* host)
+ {
+ host_ = host;
+
+ if (host_ != NULL) {
+
+ QWidget *pluginWidget = new QWidget;
+ QVBoxLayout *vbox = new QVBoxLayout;
+ QHBoxLayout *hbox = new QHBoxLayout;
+ comboBox_ = new QComboBox;
+ searchLine_ = new QLineEdit;
+ searchButton_ = new QPushButton("Search");
+
+ hbox->addWidget(searchLine_);
+ hbox->addWidget(searchButton_);
+ vbox->addWidget(comboBox_);
+ vbox->addLayout(hbox);
+ pluginWidget->setLayout(vbox);
+
+ connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
+ //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
+
+ host_->setGui(this, pluginWidget);
+ }
+ }
+
+ QWidget* SearchPlugin::getGui()
+ {
+ return NULL;
+ }
+
+ void SearchPlugin::on_searchButton_clicked()
+ {
+ QUrl searchUrl(QString("http://www.google.fi/search?q="
+ + searchLine_->text()));
+ qDebug() << searchUrl;
+ QWebView *result = new QWebView;
+ result->load(searchUrl);
+
+ on_searchResult((QWidget*)result);
+ }
+
+ void SearchPlugin::on_searchResult(QWidget* resultWidget)
+ {
+ qDebug() << "on_searchResult()";
+ if (host_) {
+ host_->addPluginWidget(this, resultWidget);
+ }
+ }
+=======
SearchPlugin::SearchPlugin() :
comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL)
{
// TODO: Parse engine descriptions.
// -Add engines to model
// -Show model in comboBox
+>>>>>>> .r31
}