GOFIGURE2
0.9.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
Main
QGoPluginManager.cxx
Go to the documentation of this file.
1
/*=========================================================================
2
Authors: The GoFigure Dev. Team.
3
at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4
5
Copyright (c) 2009-11, President and Fellows of Harvard College.
6
All rights reserved.
7
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
10
11
Redistributions of source code must retain the above copyright notice,
12
this list of conditions and the following disclaimer.
13
Redistributions in binary form must reproduce the above copyright notice,
14
this list of conditions and the following disclaimer in the documentation
15
and/or other materials provided with the distribution.
16
Neither the name of the President and Fellows of Harvard College
17
nor the names of its contributors may be used to endorse or promote
18
products derived from this software without specific prior written
19
permission.
20
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33
=========================================================================*/
34
35
#include "
QGoPluginManager.h
"
36
37
#include <iostream>
38
39
#include <QApplication>
40
#include <QDir>
41
#include <QMap>
42
#include <QPluginLoader>
43
#include <QAction>
44
#include <QDockWidget>
45
#include <QMainWindow>
46
#include <QToolBar>
47
48
#include "
QGoPlugin.h
"
49
#include "
QGoPluginHelper.h
"
50
// #include "QGoMainWindow.h"
51
52
// class QGoPluginManager::Interior
53
// {
54
// public:
55
// Interior() {}
56
// ~Interior() {}
57
//
58
// /** \todo check later on if it is already loaded. */
59
// bool AddPlugin( QGoPlugin* plugin )
60
// {
61
// if( plugin )
62
// {
63
// m_Plugins.push_back( plugin );
64
// return true;
65
// }
66
// else
67
// {
68
// return false;
69
// }
70
// }
71
//
72
// std::list< QGoPlugin* > m_Plugins;
73
// };
74
75
QGoPluginManager::QGoPluginManager
() :
QObject
()
76
{
77
// m_InternalManager = new Interior();
78
}
79
80
QGoPluginManager::~QGoPluginManager
()
81
{
82
// delete m_InternalManager;
83
}
84
85
//--------------------------------------------------------------------------
86
// Tab events to be handled by plugins
87
//--------------------------------------------------------------------------
88
void
QGoPluginManager::NotifyTabActivated
(
const
int
& iId)
89
{
90
for
( std::list< QGoPlugin * >::iterator
91
it =
m_PluginList
.begin();
92
it !=
m_PluginList
.end();
93
++it )
94
{
95
if
( ( *it ) )
96
{
97
( *it )->OnTabActivated(iId);
98
}
99
}
100
}
101
102
void
QGoPluginManager::NotifyTabClosed
(
const
int
& iId)
103
{
104
for
( std::list< QGoPlugin * >::iterator
105
it =
m_PluginList
.begin();
106
it !=
m_PluginList
.end();
107
++it )
108
{
109
if
( ( *it ) )
110
{
111
( *it )->OnTabClosed(iId);
112
}
113
}
114
}
115
116
void
QGoPluginManager::NotifyTabMoved
(
const
int
& from,
const
int
& to)
117
{
118
for
( std::list< QGoPlugin * >::iterator
119
it =
m_PluginList
.begin();
120
it !=
m_PluginList
.end();
121
++it )
122
{
123
if
( ( *it ) )
124
{
125
( *it )->OnTabMoved(from, to);
126
}
127
}
128
}
129
130
//--------------------------------------------------------------------------
131
132
bool
QGoPluginManager::IsPluginAlreadyLoaded
(
const
QString
& iName)
133
{
134
for
( std::list< QGoPlugin * >::iterator
135
it =
m_PluginList
.begin();
136
it !=
m_PluginList
.end();
137
++it )
138
{
139
if
( ( *it ) )
140
{
141
if
( ( *it )->Name() == iName )
142
{
143
return
true
;
144
}
145
}
146
}
147
return
false
;
148
}
149
150
void
QGoPluginManager::LoadPlugin
(
const
QString
& path)
151
{
152
QPluginLoader
loader(path);
153
154
if
( !loader.
load
() )
155
{
156
std::cout <<
"Plugin was not loaded"
<< std::endl;
157
return
;
158
}
159
160
QObject
*obj = loader.
instance
();
161
if
( obj )
162
{
163
QGoPlugin
*plugin = qobject_cast<
QGoPlugin
* >(obj);
164
if
( plugin )
165
{
166
// Check if plugin with the same name was already loaded.
167
// If is was then exit.
168
if
(
IsPluginAlreadyLoaded
( plugin->
Name
() ) )
169
{
170
return
;
171
}
172
173
if
( plugin )
174
{
175
m_PluginList
.push_back(plugin);
176
std::cout <<
"Plugin LOADED"
<< std::endl;
177
}
178
else
179
{
180
//note that for now this case can never happen!
181
loader.
unload
();
182
}
183
}
184
else
185
{
186
std::cout <<
"Error while casting"
<< std::endl;
187
}
188
}
189
else
190
{
191
std::cout <<
"Null plugin"
<< std::endl;
192
}
193
}
194
195
void
QGoPluginManager::LoadPlugins
()
196
{
197
// global plugins
198
QDir
gPluginDir =
FindPluginDirectory
(
"plugins"
);
199
200
foreach
(
QString
fileName, gPluginDir.
entryList
(QDir::Files) )
201
{
202
QString
path = gPluginDir.
absoluteFilePath
(fileName);
203
204
LoadPlugin
(path);
205
}
206
207
// std::list< QDockWidget* >::iterator it
208
// = m_InternalManager->m_Docks.begin();
209
// std::list< QDockWidget* >::iterator end
210
// = m_InternalManager->m_Docks.end();
211
//
212
// for( ; it != end; ++it )
213
// {
214
// m_InternalManager->m_MainWindow->AddDockWidget( *it );
215
// }
216
}
217
218
void
QGoPluginManager::ApplySettings
()
219
{
220
std::list< QGoPlugin * >::iterator it =
m_PluginList
.begin();
221
std::list< QGoPlugin * >::iterator end =
m_PluginList
.end();
222
223
for
(; it != end; ++it )
224
{
225
( *it )->ReadSettings();
226
}
227
}
228
229
std::list< QMenu * >
QGoPluginManager::GetMenus
()
230
{
231
std::list< QMenu * > oMenuList;
232
233
std::list< QGoPlugin * >::iterator it =
m_PluginList
.begin();
234
std::list< QGoPlugin * >::iterator end =
m_PluginList
.end();
235
236
for
(; it != end; ++it )
237
{
238
if
( ( *it )->Menu() )
239
{
240
oMenuList.push_back( ( *it )->Menu() );
241
}
242
}
243
244
return
oMenuList;
245
}
QPluginLoader::load
bool load()
QGoPluginManager::LoadPlugins
void LoadPlugins()
Definition:
QGoPluginManager.cxx:195
QGoPluginManager.h
QGoPluginManager::IsPluginAlreadyLoaded
bool IsPluginAlreadyLoaded(const QString &iName)
Definition:
QGoPluginManager.cxx:132
QGoPluginManager::m_PluginList
std::list< QGoPlugin * > m_PluginList
Definition:
QGoPluginManager.h:75
QGoPluginManager::QGoPluginManager
QGoPluginManager()
Definition:
QGoPluginManager.cxx:75
QGoPluginManager::GetMenus
std::list< QMenu * > GetMenus()
Returns list of menus.
Definition:
QGoPluginManager.cxx:229
QGoPluginHelper.h
QGoPlugin
Abstract class for any kind of plugins used by GoFigure2.
Definition:
QGoPlugin.h:54
QPluginLoader::unload
bool unload()
QGoPluginManager::LoadPlugin
void LoadPlugin(const QString &)
Definition:
QGoPluginManager.cxx:150
QObject
QGoPluginManager::NotifyTabMoved
virtual void NotifyTabMoved(const int &, const int &)
Definition:
QGoPluginManager.cxx:116
QPluginLoader::instance
QObject * instance()
QString
QGoPluginManager::NotifyTabActivated
virtual void NotifyTabActivated(const int &)
Definition:
QGoPluginManager.cxx:88
FindPluginDirectory
QDir FindPluginDirectory(const QString &iSubdir)
Definition:
QGoPluginHelper.cxx:41
QGoPluginManager::ApplySettings
void ApplySettings()
Definition:
QGoPluginManager.cxx:218
QGoPlugin::Name
QString Name() const
return Plugin Name of the plugin.
Definition:
QGoPlugin.cxx:39
QDir
QGoPluginManager::NotifyTabClosed
virtual void NotifyTabClosed(const int &)
Definition:
QGoPluginManager.cxx:102
QDir::entryList
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QDir::absoluteFilePath
QString absoluteFilePath(const QString &fileName) const
QGoPlugin.h
QGoPluginManager::~QGoPluginManager
virtual ~QGoPluginManager()
Definition:
QGoPluginManager.cxx:80
QPluginLoader
Generated on Sat Apr 26 2014 11:38:14 for GOFIGURE2 by
1.8.6