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
43 /// @brief Sets the plugin GUI element to host application
44 /// @note It is up to the host application to decide how to manage
45 /// and show the actual widget.
46 virtual bool setGui(PluginInterface* from, QWidget* widget) = 0;
48 /// @brief Adds additional plugin wigdets to the host application.
49 /// This functio can be called by the plugin recursively, i.e. when GUI events occur
50 /// The host application must handle placing the additional widgets.
51 /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
52 virtual void addPluginWidget(PluginInterface* from, QWidget* widget) = 0;
53 virtual void addToolbar(PluginInterface* from, QWidget* widget) = 0;
54 virtual void addToolItem(PluginInterface* from, QWidget* widget) = 0;
55 virtual void addMenu(PluginInterface* from, QWidget* widget) = 0;
56 virtual void addMenuItem(PluginInterface* from, QWidget* widget) = 0;
64 /** @class PluginHostInterface
65 * @brief Defines interface for plugins to access the host application.
66 * A Host is an application that is extended by implementing Plugins,
67 * that implement the additional functionality
69 class PluginHostInterface : public QObject
74 /// @brief Sets the plugin GUI element to host application
75 /// @note It is up to the host application to decide how to manage
76 /// and show the actual widget.
77 virtual bool setGui(QWidget* widget) = 0;
79 /// @brief Adds additional plugin wigdets to the host application.
80 /// This functio can be called by the plugin recursively, i.e. when GUI events occur
81 /// The host application must handle placing the additional widgets.
82 /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
83 virtual void addPluginWidget(QWidget* widget) = 0;
84 virtual void addToolbar() = 0;
85 virtual void addToolItem() = 0;
86 virtual void addMenu() = 0;
87 virtual void addMenuItem() = 0;
91 /** @class PluginInterface
92 * @brief Defines interface for a plugin instance.
93 * The host application uses PluginInterface interface for calling the plugins
94 * that extend the Host functionality
96 class PluginInterface : public QObject
99 /// @brief Initializes the plugin instance.
100 virtual void initialize(PluginHostInterface* host) = 0;
101 virtual QWidget* getGui() = 0;
104 } //namespace qtrapids
107 // Declare the interfaces for the Qt framework.
108 Q_DECLARE_INTERFACE(qtrapids::PluginInterface,
109 "com.ixonos.qtrapids.PluginInterface/1.0")
110 Q_DECLARE_INTERFACE(qtrapids::PluginHostInterface,
111 "com.ixonos.qtrapids.PluginHostInterface/1.0")
114 //////////////// EXAMPLE PLUGIN DECLARATION /////////////////////////
115 // A simple plugin example using the PluginInterface
116 // For more info, see Qt documentation: "How to Create Qt Plugins"
118 // namespace qtrapids
121 // class MyPlugin : public PluginInterface {
123 // // NOTE: This macro tells Qt which interfaces the plugin implements (i.e. inherits):
124 // Q_INTERFACES(qtrapids::PluginInterface)
128 // virtual void initialize(PluginHostInterface* host);
129 // virtual QWidget* getGui();
131 // // Additional plugin-specific signals and slots.
133 // void searchResult(QWidget* resultwidget);
136 // void on_button_clicked();
137 // void on_result(QWidget* resultWidget);
143 // MyPlugin::MyPlugin(): host_(NULL) {}
145 // void SearchPlugin::initialize(AbstractPluginHost* host)
149 // if (host_ != NULL) {
150 // QWidget *pluginWidget = new QWidget;
151 // QVBoxLayout *vbox = new QVBoxLayout;
152 // QPushButton *searchButton = new QPushButton("Search");
153 // vbox->addWidget(searchButton);
154 // pluginWidget->setLayout(vbox);
156 // connect(searchButton, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
157 // //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
159 // // Call host interface function to set the plugin GUI. Host handles the setup
160 // // to it's own policy
161 // host_->setGui(pluginWidget);
164 // } // namespace qtrapids
166 //// NOTE: Remember to export the actual plugin to be visible for Qt:
167 //// Q_EXPORT_PLUGIN2(myplugin, qtrapids::MyPlugin)
169 ///////////////// END OF EXAMPLE PLUGIN ///////////////////////////////