//test
@@ -1,380 +1,370 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the SocExplorer Software |
|
3 | 3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 2 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
21 | 21 | ----------------------------------------------------------------------------*/ |
|
22 | 22 | #include "socexplorerproxy.h" |
|
23 | 23 | #include <pluginmanagerWDGT.h> |
|
24 | 24 | #include <socexplorerengine.h> |
|
25 | 25 | #include <pluginloader.h> |
|
26 | 26 | #include <socexplorerplugin.h> |
|
27 | 27 | |
|
28 | 28 | socexplorerproxy* socexplorerproxy::_self=NULL; |
|
29 | 29 | QMainWindow* socexplorerproxy::mainWindow=NULL; |
|
30 | 30 | QList<socexplorerplugin*>* socexplorerproxy::drivers=NULL; |
|
31 | 31 | QList<socexplorerplugin*>* socexplorerproxy::linearDriverList=NULL; |
|
32 | 32 | socexplorerplugin* socexplorerproxy::root=NULL; |
|
33 | 33 | socexplorerplugin* socexplorerproxy::parent=NULL; |
|
34 | 34 | PluginsCache* socexplorerproxy::cache=NULL; |
|
35 | 35 | |
|
36 | 36 | socexplorerproxy::socexplorerproxy(QObject *parent) : |
|
37 | 37 | QObject(parent) |
|
38 | 38 | { |
|
39 | 39 | cache = new PluginsCache; |
|
40 | 40 | drivers = new QList<socexplorerplugin*>; |
|
41 | 41 | linearDriverList=new QList<socexplorerplugin*>; |
|
42 | 42 | root = NULL; |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | |
|
46 | 46 | socexplorerproxy::socexplorerproxy(QMainWindow *Mainwindow, QObject *parent): |
|
47 | 47 | QObject(parent) |
|
48 | 48 | { |
|
49 | 49 | mainWindow = Mainwindow; |
|
50 | 50 | cache = new PluginsCache; |
|
51 | 51 | drivers = new QList<socexplorerplugin*>; |
|
52 | 52 | linearDriverList=new QList<socexplorerplugin*>; |
|
53 | 53 | root = NULL; |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | void socexplorerproxy::init() |
|
58 | 58 | { |
|
59 | 59 | if(!_self) |
|
60 | 60 | { |
|
61 | 61 | _self = new socexplorerproxy(); |
|
62 | 62 | mainWindow = NULL; |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | void socexplorerproxy::setMainWindow(QMainWindow *Mainwindow) |
|
68 | 68 | { |
|
69 | 69 | if(!_self)init(); |
|
70 | 70 | mainWindow=Mainwindow; |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | void socexplorerproxy::loadSysDriver(const QString name) |
|
74 | 74 | { |
|
75 | 75 | if(!_self)init(); |
|
76 | 76 | if(pluginloader::libcanberoot(name)) |
|
77 | 77 | { |
|
78 | 78 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); |
|
79 | 79 | QString driverName = _self->getinstanceName(driver->baseName()); |
|
80 | 80 | loadSysDriver(driver,driverName); |
|
81 | 81 | } |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | void socexplorerproxy::loadSysDriver(const QString name, const QString instanceName) |
|
85 | 85 | { |
|
86 | 86 | if(!_self)init(); |
|
87 | 87 | if(pluginloader::libcanberoot(name) && !_self->instanceExists(instanceName)) |
|
88 | 88 | { |
|
89 | 89 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); |
|
90 | 90 | loadSysDriver(driver,instanceName); |
|
91 | 91 | } |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | |
|
95 | 95 | void socexplorerproxy::loadSysDriver(socexplorerplugin *driver, const QString instanceName) |
|
96 | 96 | { |
|
97 | 97 | if(!_self)init(); |
|
98 | 98 | driver->setInstanceName(instanceName); |
|
99 | 99 | driver->parent = NULL; |
|
100 | 100 | drivers->append(driver); |
|
101 | 101 | linearDriverList->append(driver); |
|
102 | 102 | connectChildToProxy(driver); |
|
103 | 103 | emit _self->addPluginGUI(driver); |
|
104 | 104 | emit _self->clearMenu(); |
|
105 | 105 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
106 | 106 | SocExplorerEngine::addSOC(driver); |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | void socexplorerproxy::loadChildSysDriver(socexplorerplugin *parent, const QString child) |
|
110 | 110 | { |
|
111 | 111 | if(!_self)init(); |
|
112 | 112 | if(pluginloader::libcanbechild(child)) |
|
113 | 113 | { |
|
114 | 114 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(child); |
|
115 | 115 | QString driverName = _self->getinstanceName(driver->baseName()); |
|
116 | 116 | bool ok=true; |
|
117 | 117 | if(ok) |
|
118 | 118 | { |
|
119 | 119 | if(parent!=NULL)_self->loadSysDriverToParent(driver,parent,driverName); |
|
120 | 120 | } |
|
121 | 121 | } |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | void socexplorerproxy::loadSysDriverToParent(const QString name,const QString ParentInst) |
|
125 | 125 | { |
|
126 | 126 | if(!_self)init(); |
|
127 | 127 | if(pluginloader::libcanbechild(name)) |
|
128 | 128 | { |
|
129 | 129 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); |
|
130 | 130 | QString driverName = _self->getinstanceName(driver->baseName()); |
|
131 | 131 | bool ok=true; |
|
132 | 132 | if(ok) |
|
133 | 133 | { |
|
134 | 134 | socexplorerplugin* parent=_self->getSysDriver(ParentInst); |
|
135 | 135 | if(parent!=NULL)loadSysDriverToParent(driver,parent,driverName); |
|
136 | 136 | } |
|
137 | 137 | } |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | |
|
141 | 141 | void socexplorerproxy::loadSysDriverToParent(const QString name,const QString instanceName,const QString ParentInst) |
|
142 | 142 | { |
|
143 | 143 | if(!_self)init(); |
|
144 | 144 | if(pluginloader::libcanbechild(name) && !_self->instanceExists(instanceName)) |
|
145 | 145 | { |
|
146 | 146 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); |
|
147 | 147 | bool ok=true; |
|
148 | 148 | if(ok) |
|
149 | 149 | { |
|
150 | 150 | socexplorerplugin* parent=_self->getSysDriver(ParentInst); |
|
151 | 151 | if(parent!=NULL)loadSysDriverToParent(driver,parent,instanceName); |
|
152 | 152 | } |
|
153 | 153 | } |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | void socexplorerproxy::loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName) |
|
157 | 157 | { |
|
158 | 158 | if(!_self)init(); |
|
159 | 159 | linearDriverList->append(driver); |
|
160 | 160 | driver->parent = parent; |
|
161 | 161 | driver->setInstanceName(instanceName); |
|
162 | 162 | parent->childs.append(driver); |
|
163 | 163 | connectChildToProxy(driver); |
|
164 | 164 | connectChildToParent(parent,driver); |
|
165 | 165 | emit _self->clearMenu(); |
|
166 | 166 | emit _self->addPluginGUI(driver); |
|
167 | 167 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
168 | 168 | driver->postInstantiationTrigger(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | |
|
172 | 172 | void socexplorerproxy::changeSysDriverInstName(const QString instanceName) |
|
173 | 173 | { |
|
174 | 174 | Q_UNUSED(instanceName) |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | void socexplorerproxy::changeSysDriverInstName(const QString newinstanceName, const QString previnstanceName) |
|
178 | 178 | { |
|
179 | 179 | if(!_self)init(); |
|
180 | 180 | socexplorerplugin*temp=_self->getSysDriver(previnstanceName); |
|
181 | 181 | if(temp!=NULL) |
|
182 | 182 | { |
|
183 | 183 | if(NULL!=_self->getSysDriver(newinstanceName)) |
|
184 | 184 | { |
|
185 | 185 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
186 | 186 | return; |
|
187 | 187 | } |
|
188 | 188 | temp->setInstanceName(newinstanceName); |
|
189 | 189 | } |
|
190 | 190 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
191 | 191 | } |
|
192 | 192 | |
|
193 | //void socexplorerproxy::loadChild(socexplorerplugin *parent) | |
|
194 | //{ | |
|
195 | // if(!_self)init(); | |
|
196 | // parent = parent; | |
|
197 | // pluginmanagerWDGT* pluginmanager0 = new pluginmanagerWDGT; | |
|
198 | // pluginmanager0->setChildLoadable(true); | |
|
199 | // pluginmanager0->connect(pluginmanager0,SIGNAL(loadSysDrviver(QString)),_self,SLOT(loadSysDriverToParent(QString))); | |
|
200 |
// pluginmanager0->show();
|
|
|
201 | //} | |
|
202 | ||
|
203 | 193 | |
|
204 | 194 | void socexplorerproxy::connectChildToParent(socexplorerplugin *parent, socexplorerplugin *child) |
|
205 | 195 | { |
|
206 | 196 | if(!_self)init(); |
|
207 | 197 | connect(parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool))); |
|
208 | 198 | child->activate(parent->isConnected()); |
|
209 | 199 | } |
|
210 | 200 | |
|
211 | 201 | void socexplorerproxy::disconnectChildToParent(socexplorerplugin *child) |
|
212 | 202 | { |
|
213 | 203 | if(!_self)init(); |
|
214 | 204 | disconnect(child->parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool))); |
|
215 | 205 | } |
|
216 | 206 | |
|
217 | 207 | |
|
218 | 208 | void socexplorerproxy::connectChildToProxy(socexplorerplugin *child) |
|
219 | 209 | { |
|
220 | 210 | if(!_self)init(); |
|
221 | 211 | connect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString))); |
|
222 | 212 | connect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriver(socexplorerplugin*))); |
|
223 | 213 | } |
|
224 | 214 | |
|
225 | 215 | void socexplorerproxy::disconnectChildToProxy(socexplorerplugin *child) |
|
226 | 216 | { |
|
227 | 217 | if(!_self)init(); |
|
228 | 218 | disconnect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString))); |
|
229 | 219 | disconnect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriverFromDriver(socexplorerplugin*))); |
|
230 | 220 | } |
|
231 | 221 | |
|
232 | 222 | QString socexplorerproxy::getinstanceName(const QString& baseName) |
|
233 | 223 | { |
|
234 | 224 | if(!_self)init(); |
|
235 | 225 | int i=0; |
|
236 | 226 | QString name; |
|
237 | 227 | bool validName = false; |
|
238 | 228 | while(!validName) |
|
239 | 229 | { |
|
240 | 230 | name.clear(); |
|
241 | 231 | name.append(baseName+QString::number(i)); |
|
242 | 232 | validName = instanceNameIsValid(name); |
|
243 | 233 | i++; |
|
244 | 234 | } |
|
245 | 235 | return name; |
|
246 | 236 | } |
|
247 | 237 | |
|
248 | 238 | void socexplorerproxy::changeSysDriverInstName(socexplorerplugin* driver) |
|
249 | 239 | { |
|
250 | 240 | if(!_self)init(); |
|
251 | 241 | QString prevName(driver->instanceName()); |
|
252 | 242 | } |
|
253 | 243 | |
|
254 | 244 | bool socexplorerproxy::instanceNameIsValid(const QString& instanceName) |
|
255 | 245 | { |
|
256 | 246 | if(!_self)init(); |
|
257 | 247 | for(int k=0;k<linearDriverList->count();k++) |
|
258 | 248 | { |
|
259 | 249 | if(!linearDriverList->at(k)->instanceName().compare(instanceName)) |
|
260 | 250 | return false; |
|
261 | 251 | } |
|
262 | 252 | return true; |
|
263 | 253 | } |
|
264 | 254 | |
|
265 | 255 | socexplorerplugin *socexplorerproxy::findPlugin(const QString &instanceName) |
|
266 | 256 | { |
|
267 | 257 | if(!_self)init(); |
|
268 | 258 | for(int k=0;k<linearDriverList->count();k++) |
|
269 | 259 | { |
|
270 | 260 | if(linearDriverList->at(k)->instanceName().compare(instanceName)) |
|
271 | 261 | return linearDriverList->at(k); |
|
272 | 262 | } |
|
273 | 263 | return NULL; |
|
274 | 264 | } |
|
275 | 265 | |
|
276 | 266 | bool socexplorerproxy::instanceExists(const QString &instanceName) |
|
277 | 267 | { |
|
278 | 268 | return !socexplorerproxy::instanceNameIsValid(instanceName); |
|
279 | 269 | } |
|
280 | 270 | |
|
281 | 271 | void socexplorerproxy::close() |
|
282 | 272 | { |
|
283 | 273 | if(!_self)init(); |
|
284 | 274 | socexplorerplugin* tmpPtr; |
|
285 | 275 | while(drivers->count()>0) |
|
286 | 276 | { |
|
287 | 277 | tmpPtr = drivers->last(); |
|
288 | 278 | drivers->removeLast(); |
|
289 | 279 | _self->closeSysDriver(tmpPtr); |
|
290 | 280 | } |
|
291 | 281 | if(root!=NULL) |
|
292 | 282 | { |
|
293 | 283 | _self->closeSysDriver(root); |
|
294 | 284 | } |
|
295 | 285 | |
|
296 | 286 | } |
|
297 | 287 | |
|
298 | 288 | socexplorerplugin* socexplorerproxy::getSysDriver(const QString instanceName) |
|
299 | 289 | { |
|
300 | 290 | if(!_self)init(); |
|
301 | 291 | for(int i=0;i<linearDriverList->count();i++) |
|
302 | 292 | { |
|
303 | 293 | if(!linearDriverList->at(i)->instanceName().compare(instanceName)) |
|
304 | 294 | return linearDriverList->at(i); |
|
305 | 295 | } |
|
306 | 296 | return NULL; |
|
307 | 297 | } |
|
308 | 298 | |
|
309 | 299 | |
|
310 | 300 | void socexplorerproxy::closeSysDriver(const QString instanceName) |
|
311 | 301 | { |
|
312 | 302 | if(!_self)init(); |
|
313 | 303 | closeSysDriver(getSysDriver(instanceName),false); |
|
314 | 304 | } |
|
315 | 305 | |
|
316 | 306 | void socexplorerproxy::closeSysDriver(socexplorerplugin *driver, bool recursive) |
|
317 | 307 | { |
|
318 | 308 | if(!_self)init(); |
|
319 | 309 | if(driver!=NULL) |
|
320 | 310 | { |
|
321 | 311 | emit _self->removePluginGUI(driver); |
|
322 | 312 | if(driver->parent==NULL)SocExplorerEngine::removeSOC(driver); |
|
323 | 313 | while(driver->childs.count()!=0)closeSysDriver(driver->childs.first()); |
|
324 | 314 | linearDriverList->removeOne(driver); |
|
325 | 315 | if(driver->parent!= NULL) |
|
326 | 316 | { |
|
327 | 317 | driver->parent->childs.removeOne(driver); //Have parent so it's a child |
|
328 | 318 | disconnectChildToParent(driver); |
|
329 | 319 | disconnectChildToProxy(driver); |
|
330 | 320 | delete driver; |
|
331 | 321 | } |
|
332 | 322 | else |
|
333 | 323 | { |
|
334 | 324 | drivers->removeOne(driver); |
|
335 | 325 | disconnectChildToProxy(driver); |
|
336 | 326 | delete driver; |
|
337 | 327 | } |
|
338 | 328 | if(!recursive) |
|
339 | 329 | { |
|
340 | 330 | emit _self->clearMenu(); |
|
341 | 331 | emit _self->registermenu(mainWindow); |
|
342 | 332 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
343 | 333 | } |
|
344 | 334 | } |
|
345 | 335 | |
|
346 | 336 | } |
|
347 | 337 | |
|
348 | 338 | void socexplorerproxy::geteplugintree() |
|
349 | 339 | { |
|
350 | 340 | if(!_self)init(); |
|
351 | 341 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
352 | 342 | } |
|
353 | 343 | |
|
354 | 344 | void socexplorerproxy::closeSysDriverFromDriver(socexplorerplugin *driver) |
|
355 | 345 | { |
|
356 | 346 | if(!_self)init(); |
|
357 | 347 | emit _self->closeSysDriverSig(driver); |
|
358 | 348 | } |
|
359 | 349 | |
|
360 | 350 | void socexplorerproxy::updateText() |
|
361 | 351 | { |
|
362 | 352 | if(!_self)init(); |
|
363 | 353 | emit _self->clearMenu(); |
|
364 | 354 | emit _self->registermenu(mainWindow); |
|
365 | 355 | } |
|
366 | 356 | |
|
367 | 357 | |
|
368 | 358 | |
|
369 | 359 | |
|
370 | 360 | |
|
371 | 361 | void socexplorerproxy::makeMenu(QMenu* menu) |
|
372 | 362 | { |
|
373 | 363 | if(!_self)init(); |
|
374 | 364 | for(int i=0;i<drivers->count();i++) |
|
375 | 365 | { |
|
376 | 366 | drivers->at(i)->registermenu(menu); |
|
377 | 367 | } |
|
378 | 368 | } |
|
379 | 369 | |
|
380 | 370 |
General Comments 0
You need to be logged in to leave comments.
Login now