- Added PluginInterface and SearchPlugin
authorlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Tue, 17 Nov 2009 14:06:23 +0000 (14:06 +0000)
committerlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Tue, 17 Nov 2009 14:06:23 +0000 (14:06 +0000)
- TODO: Implement PluginLoader in gui/MainWindow

git-svn-id: file:///svnroot/qtrapids/trunk@28 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda

src/gui/gui.pro
src/plugins/PluginInterface.h [new file with mode: 0644]
src/plugins/plugins.pro [new file with mode: 0644]
src/plugins/searchplugin/SearchPlugin.cpp [new file with mode: 0644]
src/plugins/searchplugin/SearchPlugin.h [new file with mode: 0644]
src/plugins/searchplugin/searchplugin.pro [new file with mode: 0644]

index 63dc4d2..668b387 100644 (file)
@@ -10,6 +10,7 @@ HEADERS += DownloadView.h \
 MainWindow.h \
 SeedView.h \
  PreferencesDialog.h
 MainWindow.h \
 SeedView.h \
  PreferencesDialog.h
+
 TEMPLATE = app
 
 TARGET = qtrapids
 TEMPLATE = app
 
 TARGET = qtrapids
diff --git a/src/plugins/PluginInterface.h b/src/plugins/PluginInterface.h
new file mode 100644 (file)
index 0000000..5abf940
--- /dev/null
@@ -0,0 +1,133 @@
+/***************************************************************************
+ *   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 PLUGININTERFACE_H
+#define PLUGININTERFACE_H
+
+#include <QObject>
+#include <QPluginLoader>
+
+namespace qtrapids
+{
+       
+       /** @class PluginHostInterface
+               * @brief Defines interface for plugins to access the host application. 
+               * A Host is an application that is extended by implementing Plugins, 
+               * that implement the additional functionality
+       */
+       class PluginHostInterface : public QObject {
+               public:
+                        
+                       /// @brief Sets the plugin GUI element to host application
+                       /// @note It is up to the host application to decide how to manage
+                       /// and show the actual widget.
+                       virtual bool setGui(QWidget* widget) = 0;
+                       
+                       /// @brief Adds additional plugin wigdets to the host application.
+                       /// This functio can be called by the plugin recursively, i.e. when GUI events occur
+                       /// The host application must handle placing the additional widgets.
+                       /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
+                       virtual void addPluginWidget(QWidget* widget) = 0;
+                       virtual void addToolbar() = 0;
+                       virtual void addToolItem() = 0;
+                       virtual void addMenu() = 0;
+                       virtual void addMenuItem() = 0;
+       };
+
+
+       /** @class PluginInterface 
+               * @brief Defines interface for a plugin instance.
+               * The host application uses PluginInterface interface for calling the plugins
+               * that extend the Host functionality
+       */
+       class PluginInterface : public QObject {
+               public:
+                       /// @brief Initializes the plugin instance.
+                       virtual void initialize(PluginHostInterface* host) = 0;
+                       virtual QWidget* getGui() = 0;
+       };
+
+} //namespace qtrapids
+
+
+// Declare the interfaces for the Qt framework.
+Q_DECLARE_INTERFACE(qtrapids::PluginInterface,
+                    "com.ixonos.qtrapids.PluginInterface/1.0")
+Q_DECLARE_INTERFACE(qtrapids::PluginHostInterface,
+                    "com.ixonos.qtrapids.PluginHostInterface/1.0")
+                                                                               
+                                                                               
+//////////////// EXAMPLE PLUGIN DECLARATION /////////////////////////
+// A simple plugin example using the PluginInterface
+// For more info, see Qt documentation: "How to Create Qt Plugins"
+//
+// namespace qtrapids
+// {
+// 
+//     class MyPlugin : public PluginInterface {
+//             Q_OBJECT
+//             // NOTE: This macro tells Qt which interfaces the plugin implements (i.e. inherits):
+//             Q_INTERFACES(qtrapids::PluginInterface)
+//             
+//             public:
+//                     MyPlugin();
+//                     virtual void initialize(PluginHostInterface* host);
+//                     virtual QWidget* getGui();
+//             
+// // Additional plugin-specific signals and slots.
+//             signals: 
+//                     void searchResult(QWidget* resultwidget);
+//                     
+//             private slots: 
+//                     void on_button_clicked();
+//                     void on_result(QWidget* resultWidget);
+//                     
+//             private:
+//     };
+// 
+//
+//     MyPlugin::MyPlugin(): host_(NULL) {}
+// 
+//             void SearchPlugin::initialize(AbstractPluginHost* host)
+//             {
+//                     host_ = host;
+//                     
+//                     if (host_ != NULL) {
+//                             QWidget *pluginWidget = new QWidget;
+//                             QVBoxLayout *vbox = new QVBoxLayout;
+//                             QPushButton *searchButton = new QPushButton("Search");
+//                             vbox->addWidget(searchButton);
+//                             pluginWidget->setLayout(vbox);
+//             
+//                             connect(searchButton, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
+//                             //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
+//                             
+//                             // Call host interface function to set the plugin GUI. Host handles the setup 
+//                             // to it's own policy
+//                             host_->setGui(pluginWidget);
+//                     }
+//             }
+// } // namespace qtrapids 
+//
+//// NOTE: Remember to export the actual plugin to be visible for Qt:
+//// Q_EXPORT_PLUGIN2(myplugin, qtrapids::MyPlugin)
+//
+///////////////// END OF EXAMPLE PLUGIN ///////////////////////////////
+
+#endif
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
new file mode 100644 (file)
index 0000000..7ea49a6
--- /dev/null
@@ -0,0 +1,9 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Tue Nov 17 15:41:04 2009
+######################################################################
+SUBDIRS += searchplugin
+TEMPLATE = subdirs
+TARGET = 
+CONFIG += qt
+
+
diff --git a/src/plugins/searchplugin/SearchPlugin.cpp b/src/plugins/searchplugin/SearchPlugin.cpp
new file mode 100644 (file)
index 0000000..656b5f9
--- /dev/null
@@ -0,0 +1,77 @@
+#include <QDebug>
+#include <QtCore/qplugin.h>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QComboBox>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QUrl>
+#include <QWebView>
+
+
+#include "SearchPlugin.h"
+
+namespace qtrapids
+{
+       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(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(resultWidget);
+               }
+       }
+
+} // namespace qtrapids
+
+Q_EXPORT_PLUGIN2(searchplugin, qtrapids::SearchPlugin)
diff --git a/src/plugins/searchplugin/SearchPlugin.h b/src/plugins/searchplugin/SearchPlugin.h
new file mode 100644 (file)
index 0000000..328131e
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef SEARCHPLUGIN_H
+#define SEARCHPLUGIN_H
+
+
+#include <QObject>
+
+#include "PluginInterface.h"
+
+class QWidget;
+class QComboBox;
+class QPushButton;
+class QLineEdit;
+
+namespace qtrapids
+{
+
+       class SearchPlugin : public PluginInterface {
+               Q_OBJECT
+               Q_INTERFACES(qtrapids::PluginInterface)
+               
+               public:
+                       SearchPlugin();
+                       virtual void initialize(PluginHostInterface* host);
+                       virtual QWidget* getGui();
+               
+               signals: 
+                       void searchResult(QWidget* resultwidget);
+                       
+               private slots: 
+                       void on_searchButton_clicked();
+                       void on_searchResult(QWidget* resultWidget);
+                       
+               private:
+                       QComboBox *comboBox_;
+                       QLineEdit *searchLine_;
+                       QPushButton *searchButton_;
+                       PluginHostInterface* host_;
+                       
+       };
+
+} // namespace qtrapids 
+
+#endif
\ No newline at end of file
diff --git a/src/plugins/searchplugin/searchplugin.pro b/src/plugins/searchplugin/searchplugin.pro
new file mode 100644 (file)
index 0000000..327648d
--- /dev/null
@@ -0,0 +1,20 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Tue Nov 17 15:43:08 2009
+######################################################################
+QT += webkit
+
+TEMPLATE = lib
+
+CONFIG += dll
+
+TARGET = 
+
+DESTDIR = ../../../bin/
+
+TARGET = searchplugin 
+DEPENDPATH += . ..
+INCLUDEPATH += . ..
+
+# Input
+HEADERS += SearchPlugin.h
+SOURCES += SearchPlugin.cpp