- Plugin interface added to MainWindow
[qtrapids] / src / plugins / PluginInterface.h
1 /***************************************************************************
2  *   Copyright (C) 2009 by Lassi Väätämöinen   *
3  *   lassi.vaatamoinen@ixonos.com   *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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
22
23 #include <QObject>
24 #include <QPluginLoader>
25
26 namespace qtrapids
27 {
28 <<<<<<< .mine
29         
30                 // Forward declaration because of co-dependency of classes.
31                 class PluginInterface;
32         
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.
38         */
39         class PluginHostInterface {
40                 public:
41                          
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;
46                         
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;
56         };
57 =======
58 >>>>>>> .r31
59 <<<<<<< .mine
60         
61 =======
62
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
67 */
68 class PluginHostInterface : public QObject
69 {
70 public:
71
72 >>>>>>> .r31
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;
77
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;
87 };
88
89
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
94 */
95 class PluginInterface : public QObject
96 {
97 public:
98     /// @brief Initializes the plugin instance.
99     virtual void initialize(PluginHostInterface* host) = 0;
100     virtual QWidget* getGui() = 0;
101 };
102
103 } //namespace qtrapids
104
105
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")
111
112
113 //////////////// EXAMPLE PLUGIN DECLARATION /////////////////////////
114 // A simple plugin example using the PluginInterface
115 // For more info, see Qt documentation: "How to Create Qt Plugins"
116 //
117 // namespace qtrapids
118 // {
119 //
120 //      class MyPlugin : public PluginInterface {
121 //              Q_OBJECT
122 //              // NOTE: This macro tells Qt which interfaces the plugin implements (i.e. inherits):
123 //              Q_INTERFACES(qtrapids::PluginInterface)
124 //
125 //              public:
126 //                      MyPlugin();
127 //                      virtual void initialize(PluginHostInterface* host);
128 //                      virtual QWidget* getGui();
129 //
130 // // Additional plugin-specific signals and slots.
131 //              signals:
132 //                      void searchResult(QWidget* resultwidget);
133 //
134 //              private slots:
135 //                      void on_button_clicked();
136 //                      void on_result(QWidget* resultWidget);
137 //
138 //              private:
139 //      };
140 //
141 //
142 //      MyPlugin::MyPlugin(): host_(NULL) {}
143 //
144 //              void SearchPlugin::initialize(AbstractPluginHost* host)
145 //              {
146 //                      host_ = host;
147 //
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);
154 //
155 //                              connect(searchButton, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
156 //                              //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
157 //
158 //                              // Call host interface function to set the plugin GUI. Host handles the setup
159 //                              // to it's own policy
160 //                              host_->setGui(pluginWidget);
161 //                      }
162 //              }
163 // } // namespace qtrapids
164 //
165 //// NOTE: Remember to export the actual plugin to be visible for Qt:
166 //// Q_EXPORT_PLUGIN2(myplugin, qtrapids::MyPlugin)
167 //
168 ///////////////// END OF EXAMPLE PLUGIN ///////////////////////////////
169
170 #endif