1 /***************************************************************************
2 * Copyright (C) 2009 by Lassi Väätämöinen *
3 * lassi.vaatamoinen@ixonos.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifndef PLUGININTERFACE_H
21 #define PLUGININTERFACE_H
25 //#include <QPluginLoader>
30 // Forward declaration because of co-dependency of classes.
31 class PluginInterface;
34 /** @class PluginHostInterface
35 * @brief Defines interface for plugins to access the host application.
36 * A Host is an application that is extended by implementing Plugins,
37 * that implement the additional functionality
38 * @note Implementing plugin host should inherit QObject.
40 class PluginHostInterface {
42 /// @enum PluginWidgetType Allows plugin host to differentiate actions
43 /// when passed as parameter to addWidget(). E.g. Popup a dialog or append tab etc.
44 /// @todo add new types
45 enum PluginWidgetType {
51 /// @enum PluginRequest for requesting host application functionality
52 /// E.g. open torrent file etc.
53 /// @todo Additional functionality request constants.
59 /// @brief Sets the plugin GUI element to host application
60 /// @note It is up to the host application to decide how to manage
61 /// and show the actual widget.
62 virtual bool setGui(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE) = 0;
64 /// @brief Adds additional plugin wigdets to the host application.
65 /// This functio can be called by the plugin recursively, i.e. when GUI events occur
66 /// The host application must handle placing the additional widgets.
67 /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
68 virtual void addPluginWidget(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE) = 0;
69 virtual void addToolbar(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE) = 0;
70 virtual void addToolItem(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE) = 0;
71 virtual void addMenu(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE) = 0;
72 virtual void addMenuItem(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE) = 0;
74 /// @brief Plugin can request to host application functionality.
75 /// Host application defines the service policy for plugin requests.
76 /// @todo Sending events would benefit from Qt signal, how to define
77 /// signal in an abstract interface?
78 virtual bool eventRequest(QVariant param, PluginRequest req = UNKNOWN_REQUEST) = 0;
83 /** @class PluginInterface
84 * @brief Defines interface for a plugin instance.
85 * The host application uses PluginInterface interface for calling the plugins
86 * that extend the Host functionality
88 class PluginInterface : public QObject {
90 /// @brief Initializes the plugin instance.
91 virtual void initialize(PluginHostInterface* host) = 0;
92 virtual QWidget* getGui() = 0;
95 } //namespace qtrapids
98 // Declare the interfaces for the Qt framework.
99 Q_DECLARE_INTERFACE(qtrapids::PluginInterface,
100 "com.ixonos.qtrapids.PluginInterface/1.0")
101 Q_DECLARE_INTERFACE(qtrapids::PluginHostInterface,
102 "com.ixonos.qtrapids.PluginHostInterface/1.0")
105 //////////////// EXAMPLE PLUGIN DECLARATION /////////////////////////
106 // A simple plugin example using the PluginInterface
107 // For more info, see Qt documentation: "How to Create Qt Plugins"
109 // namespace qtrapids
112 // class MyPlugin : public PluginInterface {
114 // // NOTE: This macro tells Qt which interfaces the plugin implements (i.e. inherits):
115 // Q_INTERFACES(qtrapids::PluginInterface)
119 // virtual void initialize(PluginHostInterface* host);
120 // virtual QWidget* getGui();
122 // // Additional plugin-specific signals and slots.
124 // void searchResult(QWidget* resultwidget);
127 // void on_button_clicked();
128 // void on_result(QWidget* resultWidget);
134 // MyPlugin::MyPlugin(): host_(NULL) {}
136 // void SearchPlugin::initialize(AbstractPluginHost* host)
140 // if (host_ != NULL) {
141 // QWidget *pluginWidget = new QWidget;
142 // QVBoxLayout *vbox = new QVBoxLayout;
143 // QPushButton *searchButton = new QPushButton("Search");
144 // vbox->addWidget(searchButton);
145 // pluginWidget->setLayout(vbox);
147 // connect(searchButton, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
148 // //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
150 // // Call host interface function to set the plugin GUI. Host handles the setup
151 // // to it's own policy
152 // host_->setGui(pluginWidget);
155 // } // namespace qtrapids
157 //// NOTE: Remember to export the actual plugin to be visible for Qt:
158 //// Q_EXPORT_PLUGIN2(myplugin, qtrapids::MyPlugin)
160 ///////////////// END OF EXAMPLE PLUGIN ///////////////////////////////