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
24 #include <QPluginLoader>
30 // Forward declaration because of co-dependency of classes.
31 class PluginInterface;
33 /** @class PluginHostInterface
34 * @brief Defines interface for plugins to access the host application.
35 * A Host is an application that is extended by implementing Plugins,
36 * that implement the additional functionality
37 * @note Implementing plugin host should inherit QObject.
39 class PluginHostInterface {
42 /// @brief Sets the plugin GUI element to host application
43 /// @note It is up to the host application to decide how to manage
44 /// and show the actual widget.
45 virtual bool setGui(PluginInterface* from, QWidget* widget) = 0;
47 /// @brief Adds additional plugin wigdets to the host application.
48 /// This functio can be called by the plugin recursively, i.e. when GUI events occur
49 /// The host application must handle placing the additional widgets.
50 /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
51 virtual void addPluginWidget(PluginInterface* from, QWidget* widget) = 0;
52 virtual void addToolbar(PluginInterface* from, QWidget* widget) = 0;
53 virtual void addToolItem(PluginInterface* from, QWidget* widget) = 0;
54 virtual void addMenu(PluginInterface* from, QWidget* widget) = 0;
55 virtual void addMenuItem(PluginInterface* from, QWidget* widget) = 0;
63 /** @class PluginHostInterface
64 * @brief Defines interface for plugins to access the host application.
65 * A Host is an application that is extended by implementing Plugins,
66 * that implement the additional functionality
68 class PluginHostInterface : public QObject
73 /// @brief Sets the plugin GUI element to host application
74 /// @note It is up to the host application to decide how to manage
75 /// and show the actual widget.
76 virtual bool setGui(QWidget* widget) = 0;
78 /// @brief Adds additional plugin wigdets to the host application.
79 /// This functio can be called by the plugin recursively, i.e. when GUI events occur
80 /// The host application must handle placing the additional widgets.
81 /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
82 virtual void addPluginWidget(QWidget* widget) = 0;
83 virtual void addToolbar() = 0;
84 virtual void addToolItem() = 0;
85 virtual void addMenu() = 0;
86 virtual void addMenuItem() = 0;
90 /** @class PluginInterface
91 * @brief Defines interface for a plugin instance.
92 * The host application uses PluginInterface interface for calling the plugins
93 * that extend the Host functionality
95 class PluginInterface : public QObject
98 /// @brief Initializes the plugin instance.
99 virtual void initialize(PluginHostInterface* host) = 0;
100 virtual QWidget* getGui() = 0;
103 } //namespace qtrapids
106 // Declare the interfaces for the Qt framework.
107 Q_DECLARE_INTERFACE(qtrapids::PluginInterface,
108 "com.ixonos.qtrapids.PluginInterface/1.0")
109 Q_DECLARE_INTERFACE(qtrapids::PluginHostInterface,
110 "com.ixonos.qtrapids.PluginHostInterface/1.0")
113 //////////////// EXAMPLE PLUGIN DECLARATION /////////////////////////
114 // A simple plugin example using the PluginInterface
115 // For more info, see Qt documentation: "How to Create Qt Plugins"
117 // namespace qtrapids
120 // class MyPlugin : public PluginInterface {
122 // // NOTE: This macro tells Qt which interfaces the plugin implements (i.e. inherits):
123 // Q_INTERFACES(qtrapids::PluginInterface)
127 // virtual void initialize(PluginHostInterface* host);
128 // virtual QWidget* getGui();
130 // // Additional plugin-specific signals and slots.
132 // void searchResult(QWidget* resultwidget);
135 // void on_button_clicked();
136 // void on_result(QWidget* resultWidget);
142 // MyPlugin::MyPlugin(): host_(NULL) {}
144 // void SearchPlugin::initialize(AbstractPluginHost* host)
148 // if (host_ != NULL) {
149 // QWidget *pluginWidget = new QWidget;
150 // QVBoxLayout *vbox = new QVBoxLayout;
151 // QPushButton *searchButton = new QPushButton("Search");
152 // vbox->addWidget(searchButton);
153 // pluginWidget->setLayout(vbox);
155 // connect(searchButton, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
156 // //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
158 // // Call host interface function to set the plugin GUI. Host handles the setup
159 // // to it's own policy
160 // host_->setGui(pluginWidget);
163 // } // namespace qtrapids
165 //// NOTE: Remember to export the actual plugin to be visible for Qt:
166 //// Q_EXPORT_PLUGIN2(myplugin, qtrapids::MyPlugin)
168 ///////////////// END OF EXAMPLE PLUGIN ///////////////////////////////