@@ -1,248 +1,301 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "socexplorersettings.h" |
|
22 | #include "socexplorersettings.h" | |
23 |
|
23 | |||
24 | SocExplorerSettings* SocExplorerSettings::_self=NULL; |
|
24 | SocExplorerSettings* SocExplorerSettings::_self=NULL; | |
25 | QSettings* SocExplorerSettings::m_settings=NULL; |
|
25 | QSettings* SocExplorerSettings::m_settings=NULL; | |
26 | QSettings* SocExplorerSettings::m_sessionSettings=NULL; |
|
26 | QSettings* SocExplorerSettings::m_sessionSettings=NULL; | |
27 | SocExplorerSettingsDialog* SocExplorerSettings::m_configDialog = NULL; |
|
27 | SocExplorerSettingsDialog* SocExplorerSettings::m_configDialog = NULL; | |
28 | #include <socexplorergui.h> |
|
28 | #include <socexplorergui.h> | |
29 | #include <QFile> |
|
29 | #include <QFile> | |
30 | #include <QFileInfo> |
|
30 | #include <QFileInfo> | |
31 | #include <QDir> |
|
31 | #include <QDir> | |
32 | #include <QDebug> |
|
32 | #include <QDebug> | |
33 |
|
33 | |||
34 | #define INIT() \ |
|
34 | #define INIT() \ | |
35 | if(Q_UNLIKELY(_self==NULL))\ |
|
35 | if(Q_UNLIKELY(_self==NULL))\ | |
36 | {\ |
|
36 | {\ | |
37 | init();\ |
|
37 | init();\ | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | SocExplorerSettings::SocExplorerSettings(QObject *parent) : QObject(parent) |
|
41 | SocExplorerSettings::SocExplorerSettings(QObject *parent) : QObject(parent) | |
42 | { |
|
42 | { | |
43 | m_settings = new QSettings(); |
|
43 | m_settings = new QSettings(); | |
44 | m_configDialog = new SocExplorerSettingsDialog(); |
|
44 | m_configDialog = new SocExplorerSettingsDialog(); | |
45 | QAction* trigerGUI = new QAction(tr("Settings"),this); |
|
45 | QAction* trigerGUI = new QAction(tr("Settings"),this); | |
46 | connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog())); |
|
46 | connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog())); | |
47 | SocExplorerGUI::addSettingsAction(trigerGUI); |
|
47 | SocExplorerGUI::addSettingsAction(trigerGUI); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | SocExplorerSettings::~SocExplorerSettings() |
|
50 | SocExplorerSettings::~SocExplorerSettings() | |
51 | { |
|
51 | { | |
52 | if(m_settings) |
|
52 | if(m_settings) | |
53 | { |
|
53 | { | |
54 | m_settings->sync(); |
|
54 | m_settings->sync(); | |
55 | delete m_settings; |
|
55 | delete m_settings; | |
56 | } |
|
56 | } | |
57 | if(m_sessionSettings) |
|
57 | if(m_sessionSettings) | |
58 | { |
|
58 | { | |
59 | m_sessionSettings->sync(); |
|
59 | m_sessionSettings->sync(); | |
60 | delete m_sessionSettings; |
|
60 | delete m_sessionSettings; | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void SocExplorerSettings::init() |
|
64 | void SocExplorerSettings::init() | |
65 | { |
|
65 | { | |
66 | if(!_self) |
|
66 | if(!_self) | |
67 | { |
|
67 | { | |
68 | _self= new SocExplorerSettings(); |
|
68 | _self= new SocExplorerSettings(); | |
69 | } |
|
69 | } | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void SocExplorerSettings::setValue(QObject *object, const QString &key, const QVariant &value, SettingScope Sscope) |
|
72 | void SocExplorerSettings::setValue(QObject *object, const QString &key, const QVariant &value, SettingScope Sscope) | |
73 | { |
|
73 | { | |
74 | INIT(); |
|
74 | INIT(); | |
75 | setValue(object->metaObject()->className(),key,value,Sscope); |
|
75 | setValue(object->metaObject()->className(),key,value,Sscope); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | QVariant SocExplorerSettings::value(QObject *object, const QString &key, const QVariant &defaultValue, SettingScope Sscope) |
|
78 | QVariant SocExplorerSettings::value(QObject *object, const QString &key, const QVariant &defaultValue, SettingScope Sscope) | |
79 | { |
|
79 | { | |
80 | INIT(); |
|
80 | INIT(); | |
81 | return value(object->metaObject()->className(),key,defaultValue,Sscope); |
|
81 | return value(object->metaObject()->className(),key,defaultValue,Sscope); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void SocExplorerSettings::setValue(const QString scope, const QString &key, const QVariant &value, SettingScope Sscope) |
|
84 | void SocExplorerSettings::setValue(const QString scope, const QString &key, const QVariant &value, SettingScope Sscope) | |
85 | { |
|
85 | { | |
86 | INIT(); |
|
86 | INIT(); | |
87 | switch (Sscope) |
|
87 | switch (Sscope) | |
88 | { |
|
88 | { | |
89 | case SystemWide: |
|
89 | case SystemWide: | |
90 | if(m_settings) |
|
90 | if(m_settings) | |
91 | m_settings->setValue(scope+"/"+key,value); |
|
91 | m_settings->setValue(scope+"/"+key,value); | |
92 | break; |
|
92 | break; | |
93 | case Session: |
|
93 | case Session: | |
94 | if(m_sessionSettings) |
|
94 | if(m_sessionSettings) | |
95 | m_sessionSettings->setValue(scope+"/"+key,value); |
|
95 | m_sessionSettings->setValue(scope+"/"+key,value); | |
96 | break; |
|
96 | break; | |
97 | default: |
|
97 | default: | |
98 | break; |
|
98 | break; | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | QVariant SocExplorerSettings::value(const QString scope, const QString &key, const QVariant &defaultValue, SettingScope Sscope) |
|
102 | QVariant SocExplorerSettings::value(const QString scope, const QString &key, const QVariant &defaultValue, SettingScope Sscope) | |
103 | { |
|
103 | { | |
104 | INIT(); |
|
104 | INIT(); | |
105 | switch (Sscope) |
|
105 | switch (Sscope) | |
106 | { |
|
106 | { | |
107 | case SystemWide: |
|
107 | case SystemWide: | |
108 | if(m_settings) |
|
108 | if(m_settings) | |
109 | return m_settings->value(scope+"/"+key,defaultValue); |
|
109 | return m_settings->value(scope+"/"+key,defaultValue); | |
110 | break; |
|
110 | break; | |
111 | case Session: |
|
111 | case Session: | |
112 | if(m_sessionSettings) |
|
112 | if(m_sessionSettings) | |
113 | return m_sessionSettings->value(scope+"/"+key,defaultValue); |
|
113 | return m_sessionSettings->value(scope+"/"+key,defaultValue); | |
114 | break; |
|
114 | break; | |
115 | default: |
|
115 | default: | |
116 | break; |
|
116 | break; | |
117 | } |
|
117 | } | |
118 | return defaultValue; |
|
118 | return defaultValue; | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, SocExplorerSettings::SettingScope Sscope) |
|
121 | QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, SocExplorerSettings::SettingScope Sscope) | |
122 | { |
|
122 | { | |
123 | INIT(); |
|
123 | INIT(); | |
124 | QList<QList<QVariant> > defaultValue; |
|
124 | QList<QList<QVariant> > defaultValue; | |
125 | switch (Sscope) |
|
125 | switch (Sscope) | |
126 | { |
|
126 | { | |
127 | case SystemWide: |
|
127 | case SystemWide: | |
128 | if(m_settings) |
|
128 | if(m_settings) | |
129 | return arrays(prefix,keys,m_settings); |
|
129 | return arrays(prefix,keys,m_settings); | |
130 | break; |
|
130 | break; | |
131 | case Session: |
|
131 | case Session: | |
132 | if(m_sessionSettings) |
|
132 | if(m_sessionSettings) | |
133 | return arrays(prefix,keys,m_sessionSettings); |
|
133 | return arrays(prefix,keys,m_sessionSettings); | |
134 | break; |
|
134 | break; | |
135 | default: |
|
135 | default: | |
136 | break; |
|
136 | break; | |
137 | } |
|
137 | } | |
138 | return defaultValue; |
|
138 | return defaultValue; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, SocExplorerSettings::SettingScope Sscope) |
|
141 | void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, SocExplorerSettings::SettingScope Sscope) | |
142 | { |
|
142 | { | |
143 | INIT(); |
|
143 | INIT(); | |
144 | switch (Sscope) |
|
144 | switch (Sscope) | |
145 | { |
|
145 | { | |
146 | case SystemWide: |
|
146 | case SystemWide: | |
147 | if(m_settings) |
|
147 | if(m_settings) | |
148 | return setArrays(prefix,keys,values,m_settings); |
|
148 | return setArrays(prefix,keys,values,m_settings); | |
149 | break; |
|
149 | break; | |
150 | case Session: |
|
150 | case Session: | |
151 | if(m_sessionSettings) |
|
151 | if(m_sessionSettings) | |
152 | return setArrays(prefix,keys,values,m_sessionSettings); |
|
152 | return setArrays(prefix,keys,values,m_sessionSettings); | |
153 | break; |
|
153 | break; | |
154 | default: |
|
154 | default: | |
155 | break; |
|
155 | break; | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | void SocExplorerSettings::sync() |
|
160 | void SocExplorerSettings::sync() | |
161 | { |
|
161 | { | |
162 | INIT(); |
|
162 | INIT(); | |
163 | if(m_settings) |
|
163 | if(m_settings) | |
164 | { |
|
164 | { | |
165 | m_settings->sync(); |
|
165 | m_settings->sync(); | |
166 | } |
|
166 | } | |
167 | if(m_sessionSettings) |
|
167 | if(m_sessionSettings) | |
168 | { |
|
168 | { | |
169 | m_sessionSettings->sync(); |
|
169 | m_sessionSettings->sync(); | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | bool SocExplorerSettings::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text) |
|
173 | bool SocExplorerSettings::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text) | |
174 | { |
|
174 | { | |
175 | INIT(); |
|
175 | INIT(); | |
176 | return m_configDialog->registerConfigEntry(configEntry,icon,text); |
|
176 | return m_configDialog->registerConfigEntry(configEntry,icon,text); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | bool SocExplorerSettings::loadSession(const QString &session) |
|
179 | bool SocExplorerSettings::loadSession(const QString &session) | |
180 | { |
|
180 | { | |
181 | INIT(); |
|
181 | INIT(); | |
182 | QFileInfo sessionInfo(m_settings->fileName()); |
|
182 | QFileInfo sessionInfo(m_settings->fileName()); | |
183 | QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf"; |
|
183 | QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf"; | |
184 | if(m_sessionSettings) |
|
184 | if(m_sessionSettings) | |
185 | { |
|
185 | { | |
186 | delete m_sessionSettings; |
|
186 | delete m_sessionSettings; | |
187 | m_sessionSettings = NULL; |
|
187 | m_sessionSettings = NULL; | |
188 | } |
|
188 | } | |
189 | m_sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self()); |
|
189 | m_sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self()); | |
190 | qDebug()<< m_sessionSettings->fileName(); |
|
190 | qDebug()<< m_sessionSettings->fileName(); | |
191 | if(m_sessionSettings->status()==QSettings::NoError) |
|
191 | if(m_sessionSettings->status()==QSettings::NoError) | |
192 | { |
|
192 | { | |
193 | return true; |
|
193 | return true; | |
194 | } |
|
194 | } | |
195 | delete m_sessionSettings; |
|
195 | delete m_sessionSettings; | |
196 | m_sessionSettings = NULL; |
|
196 | m_sessionSettings = NULL; | |
197 | return false; |
|
197 | return false; | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
|
200 | bool SocExplorerSettings::deleteSession() | |||
|
201 | { | |||
|
202 | INIT(); | |||
|
203 | if(m_sessionSettings) | |||
|
204 | { | |||
|
205 | m_sessionSettings->clear(); | |||
|
206 | QString filename= m_sessionSettings->fileName(); | |||
|
207 | if(QFile::exists(filename)) | |||
|
208 | { | |||
|
209 | delete m_sessionSettings; | |||
|
210 | QFile::remove(filename); | |||
|
211 | } | |||
|
212 | else | |||
|
213 | delete m_sessionSettings; | |||
|
214 | m_sessionSettings = NULL; | |||
|
215 | return true; | |||
|
216 | } | |||
|
217 | return false; | |||
|
218 | } | |||
|
219 | ||||
|
220 | bool SocExplorerSettings::deleteSession(const QString &session) | |||
|
221 | { | |||
|
222 | QFileInfo sessionInfo(m_settings->fileName()); | |||
|
223 | QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf"; | |||
|
224 | if(m_sessionSettings) | |||
|
225 | { | |||
|
226 | if(m_sessionSettings->fileName()==fullpath) | |||
|
227 | { | |||
|
228 | deleteSession(); | |||
|
229 | return true; | |||
|
230 | } | |||
|
231 | } | |||
|
232 | QSettings* sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self()); | |||
|
233 | if(sessionSettings) | |||
|
234 | { | |||
|
235 | if(sessionSettings->status()==QSettings::NoError) | |||
|
236 | { | |||
|
237 | sessionSettings->clear(); | |||
|
238 | QString filename= m_sessionSettings->fileName(); | |||
|
239 | if(QFile::exists(filename)) | |||
|
240 | { | |||
|
241 | delete sessionSettings; | |||
|
242 | QFile::remove(filename); | |||
|
243 | } | |||
|
244 | else | |||
|
245 | delete sessionSettings; | |||
|
246 | return true; | |||
|
247 | } | |||
|
248 | delete sessionSettings; | |||
|
249 | } | |||
|
250 | return false; | |||
|
251 | } | |||
|
252 | ||||
200 | void SocExplorerSettings::popConfigDialog() |
|
253 | void SocExplorerSettings::popConfigDialog() | |
201 | { |
|
254 | { | |
202 | m_configDialog->popConfigDialog(NULL); |
|
255 | m_configDialog->popConfigDialog(NULL); | |
203 | } |
|
256 | } | |
204 |
|
257 | |||
205 | QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, QSettings *settings) |
|
258 | QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, QSettings *settings) | |
206 | { |
|
259 | { | |
207 | QList<QList<QVariant> > result; |
|
260 | QList<QList<QVariant> > result; | |
208 | if(settings) |
|
261 | if(settings) | |
209 | { |
|
262 | { | |
210 | int size = settings->beginReadArray(prefix); |
|
263 | int size = settings->beginReadArray(prefix); | |
211 | for (int i = 0; i < size; ++i) |
|
264 | for (int i = 0; i < size; ++i) | |
212 | { |
|
265 | { | |
213 | result.append(QList<QVariant>()); |
|
266 | result.append(QList<QVariant>()); | |
214 | settings->setArrayIndex(i); |
|
267 | settings->setArrayIndex(i); | |
215 | for(int l=0;l<keys.count();l++) |
|
268 | for(int l=0;l<keys.count();l++) | |
216 | { |
|
269 | { | |
217 | result[i].append(settings->value(keys.at(l))); |
|
270 | result[i].append(settings->value(keys.at(l))); | |
218 | } |
|
271 | } | |
219 | } |
|
272 | } | |
220 | settings->endArray(); |
|
273 | settings->endArray(); | |
221 | } |
|
274 | } | |
222 | return result; |
|
275 | return result; | |
223 | } |
|
276 | } | |
224 |
|
277 | |||
225 | void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, QSettings *settings) |
|
278 | void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, QSettings *settings) | |
226 | { |
|
279 | { | |
227 | if(settings) |
|
280 | if(settings) | |
228 | { |
|
281 | { | |
229 | QString key; |
|
282 | QString key; | |
230 | foreach (key, keys) |
|
283 | foreach (key, keys) | |
231 | { |
|
284 | { | |
232 |
|
285 | |||
233 | settings->remove(prefix+"/"+key); |
|
286 | settings->remove(prefix+"/"+key); | |
234 | } |
|
287 | } | |
235 | settings->beginWriteArray(prefix); |
|
288 | settings->beginWriteArray(prefix); | |
236 | for (int i = 0; i < values.size(); ++i) |
|
289 | for (int i = 0; i < values.size(); ++i) | |
237 | { |
|
290 | { | |
238 | settings->setArrayIndex(i); |
|
291 | settings->setArrayIndex(i); | |
239 | for(int l=0;l<keys.count();l++) |
|
292 | for(int l=0;l<keys.count();l++) | |
240 | { |
|
293 | { | |
241 | settings->setValue(keys[l], values.at(i).at(l)); |
|
294 | settings->setValue(keys[l], values.at(i).at(l)); | |
242 | } |
|
295 | } | |
243 | } |
|
296 | } | |
244 | settings->endArray(); |
|
297 | settings->endArray(); | |
245 |
|
298 | |||
246 | } |
|
299 | } | |
247 | } |
|
300 | } | |
248 |
|
301 |
@@ -1,68 +1,70 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef SOCEXPLORERSETTINGS_H |
|
22 | #ifndef SOCEXPLORERSETTINGS_H | |
23 | #define SOCEXPLORERSETTINGS_H |
|
23 | #define SOCEXPLORERSETTINGS_H | |
24 |
|
24 | |||
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QWidget> |
|
26 | #include <QWidget> | |
27 | #include <QSettings> |
|
27 | #include <QSettings> | |
28 | #include <socexplorersettingsdialog.h> |
|
28 | #include <socexplorersettingsdialog.h> | |
29 |
|
29 | |||
30 | class SocExplorerSettings : public QObject |
|
30 | class SocExplorerSettings : public QObject | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | private: |
|
33 | private: | |
34 | static SocExplorerSettings* _self; |
|
34 | static SocExplorerSettings* _self; | |
35 | static QSettings* m_settings; |
|
35 | static QSettings* m_settings; | |
36 | static QSettings* m_sessionSettings; |
|
36 | static QSettings* m_sessionSettings; | |
37 | static SocExplorerSettingsDialog* m_configDialog; |
|
37 | static SocExplorerSettingsDialog* m_configDialog; | |
38 | SocExplorerSettings(QObject *parent = 0); |
|
38 | SocExplorerSettings(QObject *parent = 0); | |
39 | ~SocExplorerSettings(); |
|
39 | ~SocExplorerSettings(); | |
40 | public: |
|
40 | public: | |
41 | enum SettingScope { |
|
41 | enum SettingScope { | |
42 | SystemWide = 0, |
|
42 | SystemWide = 0, | |
43 | Session |
|
43 | Session | |
44 | }; |
|
44 | }; | |
45 | static void init(); |
|
45 | static void init(); | |
46 | static SocExplorerSettings* self(){ if(!_self){_self= new SocExplorerSettings;}return _self;} |
|
46 | static SocExplorerSettings* self(){ if(!_self){_self= new SocExplorerSettings;}return _self;} | |
47 | static void setValue(QObject* object,const QString & key, const QVariant & value,SettingScope Sscope =SystemWide); |
|
47 | static void setValue(QObject* object,const QString & key, const QVariant & value,SettingScope Sscope =SystemWide); | |
48 | static QVariant value(QObject* object, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope=SystemWide); |
|
48 | static QVariant value(QObject* object, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope=SystemWide); | |
49 | static void setValue(const QString scope,const QString & key, const QVariant & value,SettingScope Sscope= SystemWide); |
|
49 | static void setValue(const QString scope,const QString & key, const QVariant & value,SettingScope Sscope= SystemWide); | |
50 | static QVariant value(const QString scope, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope =SystemWide); |
|
50 | static QVariant value(const QString scope, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope =SystemWide); | |
51 | static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,SettingScope Sscope =SystemWide); |
|
51 | static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,SettingScope Sscope =SystemWide); | |
52 | static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,SettingScope Sscope =SystemWide); |
|
52 | static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,SettingScope Sscope =SystemWide); | |
53 | static void sync(); |
|
53 | static void sync(); | |
54 | static bool registerConfigEntry(SocExplorerSettingsItem* configEntry,QIcon icon, QString text); |
|
54 | static bool registerConfigEntry(SocExplorerSettingsItem* configEntry,QIcon icon, QString text); | |
55 | //! Loads the given session, or sreate it if doesn't exists. |
|
55 | //! Loads the given session, or sreate it if doesn't exists. | |
56 | //! \param session Session name. |
|
56 | //! \param session Session name. | |
57 | //! \return true if success or false if fails to create session config file. |
|
57 | //! \return true if success or false if fails to create session config file. | |
58 | static bool loadSession(const QString& session); |
|
58 | static bool loadSession(const QString& session); | |
|
59 | static bool deleteSession(); | |||
|
60 | static bool deleteSession(const QString& session); | |||
59 | signals: |
|
61 | signals: | |
60 |
|
62 | |||
61 | public slots: |
|
63 | public slots: | |
62 | void popConfigDialog(); |
|
64 | void popConfigDialog(); | |
63 | private: |
|
65 | private: | |
64 | static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,QSettings* settings); |
|
66 | static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,QSettings* settings); | |
65 | static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,QSettings* settings); |
|
67 | static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,QSettings* settings); | |
66 | }; |
|
68 | }; | |
67 |
|
69 | |||
68 | #endif // SOCEXPLORERSETTINGS_H |
|
70 | #endif // SOCEXPLORERSETTINGS_H |
@@ -1,181 +1,182 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | ββββββββ βββββββ βββββββ βββββββββββ ββββββββββ βββ βββββββ βββββββ βββββββββββββββ |
|
2 | ββββββββ βββββββ βββββββ βββββββββββ ββββββββββ βββ βββββββ βββββββ βββββββββββββββ | |
3 | βββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββ |
|
3 | βββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββ | |
4 | βββββββββββ ββββββ ββββββ ββββββ βββββββββββ βββ βββββββββββββββββ ββββββββ |
|
4 | βββββββββββ ββββββ ββββββ ββββββ βββββββββββ βββ βββββββββββββββββ ββββββββ | |
5 | βββββββββββ ββββββ ββββββ ββββββ βββββββ βββ βββ βββββββββββββββββ ββββββββ |
|
5 | βββββββββββ ββββββ ββββββ ββββββ βββββββ βββ βββ βββββββββββββββββ ββββββββ | |
6 | βββββββββββββββββββββββββ ββββββββββββ ββββββ ββββββββββββββββββββ ββββββββββββββ βββ |
|
6 | βββββββββββββββββββββββββ ββββββββββββ ββββββ ββββββββββββββββββββ ββββββββββββββ βββ | |
7 | ββββββββ βββββββ βββββββ βββββββββββ ββββββ ββββββββ βββββββ βββ ββββββββββββββ βββ |
|
7 | ββββββββ βββββββ βββββββ βββββββββββ ββββββ ββββββββ βββββββ βββ ββββββββββββββ βββ | |
8 |
|
8 | |||
9 | -- This file is a part of the SOC Explorer Software |
|
9 | -- This file is a part of the SOC Explorer Software | |
10 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS |
|
10 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS | |
11 | -- |
|
11 | -- | |
12 | -- This program is free software; you can redistribute it and/or modify |
|
12 | -- This program is free software; you can redistribute it and/or modify | |
13 | -- it under the terms of the GNU General Public License as published by |
|
13 | -- it under the terms of the GNU General Public License as published by | |
14 | -- the Free Software Foundation; either version 2 of the License, or |
|
14 | -- the Free Software Foundation; either version 2 of the License, or | |
15 | -- (at your option) any later version. |
|
15 | -- (at your option) any later version. | |
16 | -- |
|
16 | -- | |
17 | -- This program is distributed in the hope that it will be useful, |
|
17 | -- This program is distributed in the hope that it will be useful, | |
18 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | -- GNU General Public License for more details. |
|
20 | -- GNU General Public License for more details. | |
21 | -- |
|
21 | -- | |
22 | -- You should have received a copy of the GNU General Public License |
|
22 | -- You should have received a copy of the GNU General Public License | |
23 | -- along with this program; if not, write to the Free Software |
|
23 | -- along with this program; if not, write to the Free Software | |
24 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
25 | -------------------------------------------------------------------------------*/ |
|
25 | -------------------------------------------------------------------------------*/ | |
26 | /*-- Author : Alexis Jeandet |
|
26 | /*-- Author : Alexis Jeandet | |
27 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
27 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
28 | ----------------------------------------------------------------------------*/ |
|
28 | ----------------------------------------------------------------------------*/ | |
29 | #ifndef SOCEXPLORERPLUGIN_H |
|
29 | #ifndef SOCEXPLORERPLUGIN_H | |
30 | #define SOCEXPLORERPLUGIN_H |
|
30 | #define SOCEXPLORERPLUGIN_H | |
31 | #include <QWidget> |
|
31 | #include <QWidget> | |
32 | #include <QAction> |
|
32 | #include <QAction> | |
33 | #include <QDockWidget> |
|
33 | #include <QDockWidget> | |
34 | #include <QMainWindow> |
|
34 | #include <QMainWindow> | |
35 | #include <QList> |
|
35 | #include <QList> | |
36 | #include <QMenu> |
|
36 | #include <QMenu> | |
37 | #include <socexplorer.h> |
|
37 | #include <socexplorer.h> | |
38 | #include <QObject> |
|
38 | #include <QObject> | |
39 | #include <QVariant> |
|
39 | #include <QVariant> | |
40 | #include <QVariantList> |
|
40 | #include <QVariantList> | |
41 | #include <malloc.h> |
|
41 | #include <malloc.h> | |
42 | #include <QFile> |
|
42 | #include <QFile> | |
43 | #include <stdint.h> |
|
43 | #include <stdint.h> | |
44 | #include <QTextStream> |
|
44 | #include <QTextStream> | |
45 | #include <abstractbinfile.h> |
|
45 | #include <abstractbinfile.h> | |
46 | #ifndef driver_Name |
|
46 | #ifndef driver_Name | |
47 | #define driver_Name "Plugin" |
|
47 | #define driver_Name "Plugin" | |
48 | #endif |
|
48 | #endif | |
49 | #ifndef driver_Author |
|
49 | #ifndef driver_Author | |
50 | #define driver_Author "No Author" |
|
50 | #define driver_Author "No Author" | |
51 | #endif |
|
51 | #endif | |
52 | #ifndef driver_Version |
|
52 | #ifndef driver_Version | |
53 | #define driver_Version "0.0.0" |
|
53 | #define driver_Version "0.0.0" | |
54 | #endif |
|
54 | #endif | |
55 | #ifndef driver_Description |
|
55 | #ifndef driver_Description | |
56 | #define driver_Description "No description." |
|
56 | #define driver_Description "No description." | |
57 | #endif |
|
57 | #endif | |
58 | #ifndef driver_can_be_root |
|
58 | #ifndef driver_can_be_root | |
59 | #define driver_can_be_root 0 |
|
59 | #define driver_can_be_root 0 | |
60 | #endif |
|
60 | #endif | |
61 | #ifndef driver_can_be_child |
|
61 | #ifndef driver_can_be_child | |
62 | #define driver_can_be_child 0 |
|
62 | #define driver_can_be_child 0 | |
63 | #endif |
|
63 | #endif | |
64 | #ifndef driver_VID |
|
64 | #ifndef driver_VID | |
65 | #define driver_VID 0 |
|
65 | #define driver_VID 0 | |
66 | #endif |
|
66 | #endif | |
67 | #ifndef driver_PID |
|
67 | #ifndef driver_PID | |
68 | #define driver_PID 0 |
|
68 | #define driver_PID 0 | |
69 | #endif |
|
69 | #endif | |
70 |
|
70 | |||
71 | #if defined(SOCEXPLORER_SDK_BUILD) |
|
71 | #if defined(SOCEXPLORER_SDK_BUILD) | |
72 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT |
|
72 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT | |
73 | #else |
|
73 | #else | |
74 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT |
|
74 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT | |
75 | #endif |
|
75 | #endif | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | //! socexplorerplugin is the base class for any SocExplorer plugin, it gives a standard interface to communicate |
|
78 | //! socexplorerplugin is the base class for any SocExplorer plugin, it gives a standard interface to communicate | |
79 | //! between each plugins and to interact with SocExplorer software. |
|
79 | //! between each plugins and to interact with SocExplorer software. | |
80 |
|
80 | |||
81 | class SOCEXPLORER_SDK_EXPORT socexplorerplugin : public QDockWidget |
|
81 | class SOCEXPLORER_SDK_EXPORT socexplorerplugin : public QDockWidget | |
82 | { |
|
82 | { | |
83 | Q_OBJECT |
|
83 | Q_OBJECT | |
84 | public: |
|
84 | public: | |
85 | //! Default plugin constructor, any plugin should call this constructor. |
|
85 | //! Default plugin constructor, any plugin should call this constructor. | |
86 | socexplorerplugin(QWidget *parent = 0,bool createPyObject=true):QDockWidget(parent) |
|
86 | socexplorerplugin(QWidget *parent = 0,bool createPyObject=true):QDockWidget(parent) | |
87 | { |
|
87 | { | |
|
88 | Q_UNUSED(createPyObject) | |||
88 | closeAction=NULL; |
|
89 | closeAction=NULL; | |
89 | menu=NULL; |
|
90 | menu=NULL; | |
90 | ChildsMenu=NULL; |
|
91 | ChildsMenu=NULL; | |
91 | this->Connected = false; |
|
92 | this->Connected = false; | |
92 | this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetVerticalTitleBar); |
|
93 | this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetVerticalTitleBar); | |
93 | _Name = new QString(driver_Name); |
|
94 | _Name = new QString(driver_Name); | |
94 | _Author = new QString(driver_Author); |
|
95 | _Author = new QString(driver_Author); | |
95 | _Version = new QString(driver_Version); |
|
96 | _Version = new QString(driver_Version); | |
96 | _Description = new QString(driver_Description); |
|
97 | _Description = new QString(driver_Description); | |
97 | _canBeChild = driver_can_be_child; |
|
98 | _canBeChild = driver_can_be_child; | |
98 | _canBeRoot = driver_can_be_root; |
|
99 | _canBeRoot = driver_can_be_root; | |
99 | _VID = driver_VID; |
|
100 | _VID = driver_VID; | |
100 | _PID = driver_PID; |
|
101 | _PID = driver_PID; | |
101 | } |
|
102 | } | |
102 | //! Tells if the plugin is connected, it is used to enable or disable all childrens interfaces. |
|
103 | //! Tells if the plugin is connected, it is used to enable or disable all childrens interfaces. | |
103 | virtual int isConnected(); |
|
104 | virtual int isConnected(); | |
104 | //! Gives the associated Vendor IDentifier, usefull to automatically associate plugins with found |
|
105 | //! Gives the associated Vendor IDentifier, usefull to automatically associate plugins with found | |
105 | //! hardware while board enumeration. |
|
106 | //! hardware while board enumeration. | |
106 | virtual int VID(){return _PID;} |
|
107 | virtual int VID(){return _PID;} | |
107 | //! Gives the associated Product IDentifier, usefull to automatically associate plugins with found |
|
108 | //! Gives the associated Product IDentifier, usefull to automatically associate plugins with found | |
108 | //! hardware while board enumeration. |
|
109 | //! hardware while board enumeration. | |
109 | virtual int PID(){return _VID;} |
|
110 | virtual int PID(){return _VID;} | |
110 | //! Gives the plugin's base name, usefull to automatically generate instance name. |
|
111 | //! Gives the plugin's base name, usefull to automatically generate instance name. | |
111 | virtual QString baseName(); |
|
112 | virtual QString baseName(); | |
112 | //! Gives the base address of the current instance, for example if your plugin is supposed to drive |
|
113 | //! Gives the base address of the current instance, for example if your plugin is supposed to drive | |
113 | //! an UART it will correspond to the address of it's first register. This address have at least to |
|
114 | //! an UART it will correspond to the address of it's first register. This address have at least to | |
114 | //! be set by SocExplorer and it can be user accessible if you want. |
|
115 | //! be set by SocExplorer and it can be user accessible if you want. | |
115 | virtual int baseAddress(); |
|
116 | virtual int baseAddress(); | |
116 | //! Sets the base address of the current instance, for example if your plugin is supposed to drive |
|
117 | //! Sets the base address of the current instance, for example if your plugin is supposed to drive | |
117 | //! an UART it will correspond to the address of it's first register. This address have at least to |
|
118 | //! an UART it will correspond to the address of it's first register. This address have at least to | |
118 | //! be set by SocExplorer and it can be user accessible if you want. |
|
119 | //! be set by SocExplorer and it can be user accessible if you want. | |
119 | virtual void setBaseAddress(unsigned int baseAddress); |
|
120 | virtual void setBaseAddress(unsigned int baseAddress); | |
120 |
|
121 | |||
121 | QList<socexplorerplugin*> childs; |
|
122 | QList<socexplorerplugin*> childs; | |
122 | socexplorerplugin* parent; |
|
123 | socexplorerplugin* parent; | |
123 | QAction* closeAction; |
|
124 | QAction* closeAction; | |
124 | QString instanceName(); |
|
125 | QString instanceName(); | |
125 | QString instance(){return instanceName();} |
|
126 | QString instance(){return instanceName();} | |
126 | QMenu* menu; |
|
127 | QMenu* menu; | |
127 | QMenu* ChildsMenu; |
|
128 | QMenu* ChildsMenu; | |
128 |
|
129 | |||
129 | signals: |
|
130 | signals: | |
130 | //! Signal emited each time the plugin is about to be closed. |
|
131 | //! Signal emited each time the plugin is about to be closed. | |
131 | void closePlugin(socexplorerplugin* driver); |
|
132 | void closePlugin(socexplorerplugin* driver); | |
132 | void activateSig(bool flag); |
|
133 | void activateSig(bool flag); | |
133 | void registerObject(QObject* object,const QString& instanceName); |
|
134 | void registerObject(QObject* object,const QString& instanceName); | |
134 |
|
135 | |||
135 | public slots: |
|
136 | public slots: | |
136 | virtual int registermenu(QMenu* menu); |
|
137 | virtual int registermenu(QMenu* menu); | |
137 | virtual void postInstantiationTrigger(); |
|
138 | virtual void postInstantiationTrigger(); | |
138 | //! Write slot this is the way your children plugins ask you for writing data. |
|
139 | //! Write slot this is the way your children plugins ask you for writing data. | |
139 | //! If your plugin is supposed to have childern drivers you should implement this methode. |
|
140 | //! If your plugin is supposed to have childern drivers you should implement this methode. | |
140 | //! By default this methode forward the write request to the parent plugin. |
|
141 | //! By default this methode forward the write request to the parent plugin. | |
141 | //! \param Value Pointer the data buffer. |
|
142 | //! \param Value Pointer the data buffer. | |
142 | //! \param count Number of 32 bits words you should to write. |
|
143 | //! \param count Number of 32 bits words you should to write. | |
143 | //! \param address Address from where you should to start to write. |
|
144 | //! \param address Address from where you should to start to write. | |
144 | //! \return Quantity of 32 bits words writtens. |
|
145 | //! \return Quantity of 32 bits words writtens. | |
145 | virtual unsigned int Write(unsigned int* Value, unsigned int count,unsigned int address); |
|
146 | virtual unsigned int Write(unsigned int* Value, unsigned int count,unsigned int address); | |
146 | //! Read slot this is the way your children plugins ask you for reading data. |
|
147 | //! Read slot this is the way your children plugins ask you for reading data. | |
147 | //! If your plugin is supposed to have childern drivers you should implement this methode. |
|
148 | //! If your plugin is supposed to have childern drivers you should implement this methode. | |
148 | //! By default this methode forward the write request to the parent plugin. |
|
149 | //! By default this methode forward the write request to the parent plugin. | |
149 | //! \param Value Pointer the data buffer. |
|
150 | //! \param Value Pointer the data buffer. | |
150 | //! \param count Number of 32 bits words you should to read. |
|
151 | //! \param count Number of 32 bits words you should to read. | |
151 | //! \param address Address from where you should to start to read. |
|
152 | //! \param address Address from where you should to start to read. | |
152 | //! \return Quantity of 32 bits words read. |
|
153 | //! \return Quantity of 32 bits words read. | |
153 | virtual unsigned int Read(unsigned int* Value, unsigned int count,unsigned int address); |
|
154 | virtual unsigned int Read(unsigned int* Value, unsigned int count,unsigned int address); | |
154 | virtual void closeMe(); |
|
155 | virtual void closeMe(); | |
155 | virtual void activate(bool flag); |
|
156 | virtual void activate(bool flag); | |
156 | virtual void setInstanceName(const QString& newName); |
|
157 | virtual void setInstanceName(const QString& newName); | |
157 |
|
158 | |||
158 | virtual bool dumpMemory(unsigned int address,unsigned int count,QString file); |
|
159 | virtual bool dumpMemory(unsigned int address,unsigned int count,QString file); | |
159 | virtual bool memSet(unsigned int address,int value, unsigned int count); |
|
160 | virtual bool memSet(unsigned int address,int value, unsigned int count); | |
160 | virtual bool loadbin(unsigned int address,QString file); |
|
161 | virtual bool loadbin(unsigned int address,QString file); | |
161 | virtual bool loadfile(abstractBinFile* file); |
|
162 | virtual bool loadfile(abstractBinFile* file); | |
162 | virtual bool dumpMemory(unsigned int address,unsigned int count,QString file,const QString& format); |
|
163 | virtual bool dumpMemory(unsigned int address,unsigned int count,QString file,const QString& format); | |
163 | QVariantList Read(unsigned int address, unsigned int count); |
|
164 | QVariantList Read(unsigned int address, unsigned int count); | |
164 | void Write(unsigned int address, QList<QVariant> dataList); |
|
165 | void Write(unsigned int address, QList<QVariant> dataList); | |
165 | socexplorerplugin* parentPlugin(){return this->parent;} |
|
166 | socexplorerplugin* parentPlugin(){return this->parent;} | |
166 | socexplorerplugin* toPlugin(){return (socexplorerplugin*)this;} |
|
167 | socexplorerplugin* toPlugin(){return (socexplorerplugin*)this;} | |
167 | protected: |
|
168 | protected: | |
168 | int BaseAddress; |
|
169 | int BaseAddress; | |
169 | bool Connected; |
|
170 | bool Connected; | |
170 | QString* _Name; |
|
171 | QString* _Name; | |
171 | QString* _Author; |
|
172 | QString* _Author; | |
172 | QString* _Version; |
|
173 | QString* _Version; | |
173 | QString* _Description; |
|
174 | QString* _Description; | |
174 | QString _instanceName; |
|
175 | QString _instanceName; | |
175 | int _canBeChild; |
|
176 | int _canBeChild; | |
176 | int _canBeRoot; |
|
177 | int _canBeRoot; | |
177 | int _VID; |
|
178 | int _VID; | |
178 | int _PID; |
|
179 | int _PID; | |
179 | }; |
|
180 | }; | |
180 |
|
181 | |||
181 | #endif // SOCEXPLORERPLUGIN_H |
|
182 | #endif // SOCEXPLORERPLUGIN_H |
@@ -1,371 +1,434 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "socexplorerproxy.h" |
|
22 | #include "socexplorerproxy.h" | |
23 | #include <pluginmanagerWDGT.h> |
|
23 | #include <pluginmanagerWDGT.h> | |
24 | #include <socexplorerengine.h> |
|
24 | #include <socexplorerengine.h> | |
25 | #include <pluginloader.h> |
|
25 | #include <pluginloader.h> | |
26 | #include <socexplorerplugin.h> |
|
26 | #include <socexplorerplugin.h> | |
27 |
|
27 | |||
28 | socexplorerproxy* socexplorerproxy::_self=NULL; |
|
28 | socexplorerproxy* socexplorerproxy::_self=NULL; | |
29 | QMainWindow* socexplorerproxy::mainWindow=NULL; |
|
29 | QMainWindow* socexplorerproxy::mainWindow=NULL; | |
30 | QList<socexplorerplugin*>* socexplorerproxy::drivers=NULL; |
|
30 | QList<socexplorerplugin*>* socexplorerproxy::drivers=NULL; | |
31 | QList<socexplorerplugin*>* socexplorerproxy::linearDriverList=NULL; |
|
31 | QList<socexplorerplugin*>* socexplorerproxy::linearDriverList=NULL; | |
32 | socexplorerplugin* socexplorerproxy::root=NULL; |
|
32 | socexplorerplugin* socexplorerproxy::root=NULL; | |
33 | socexplorerplugin* socexplorerproxy::parent=NULL; |
|
33 | socexplorerplugin* socexplorerproxy::parent=NULL; | |
34 | PluginsCache* socexplorerproxy::cache=NULL; |
|
34 | PluginsCache* socexplorerproxy::cache=NULL; | |
|
35 | QStringList* socexplorerproxy::linearDriverPathList=NULL; | |||
35 |
|
36 | |||
36 | socexplorerproxy::socexplorerproxy(QObject *parent) : |
|
37 | socexplorerproxy::socexplorerproxy(QObject *parent) : | |
37 | QObject(parent) |
|
38 | QObject(parent) | |
38 | { |
|
39 | { | |
39 | cache = new PluginsCache; |
|
40 | cache = new PluginsCache; | |
40 | drivers = new QList<socexplorerplugin*>; |
|
41 | drivers = new QList<socexplorerplugin*>; | |
41 | linearDriverList=new QList<socexplorerplugin*>; |
|
42 | linearDriverList=new QList<socexplorerplugin*>; | |
|
43 | linearDriverPathList=new QStringList; | |||
42 | root = NULL; |
|
44 | root = NULL; | |
43 | } |
|
45 | } | |
44 |
|
46 | |||
45 |
|
47 | |||
46 | socexplorerproxy::socexplorerproxy(QMainWindow *Mainwindow, QObject *parent): |
|
48 | socexplorerproxy::socexplorerproxy(QMainWindow *Mainwindow, QObject *parent): | |
47 | QObject(parent) |
|
49 | QObject(parent) | |
48 | { |
|
50 | { | |
49 | mainWindow = Mainwindow; |
|
51 | mainWindow = Mainwindow; | |
50 | cache = new PluginsCache; |
|
52 | cache = new PluginsCache; | |
51 | drivers = new QList<socexplorerplugin*>; |
|
53 | drivers = new QList<socexplorerplugin*>; | |
52 | linearDriverList=new QList<socexplorerplugin*>; |
|
54 | linearDriverList=new QList<socexplorerplugin*>; | |
|
55 | linearDriverPathList=new QStringList; | |||
53 | root = NULL; |
|
56 | root = NULL; | |
54 | } |
|
57 | } | |
55 |
|
58 | |||
56 |
|
59 | |||
57 | void socexplorerproxy::init() |
|
60 | void socexplorerproxy::init() | |
58 | { |
|
61 | { | |
59 | if(!_self) |
|
62 | if(!_self) | |
60 | { |
|
63 | { | |
61 | _self = new socexplorerproxy(); |
|
64 | _self = new socexplorerproxy(); | |
62 | mainWindow = NULL; |
|
65 | mainWindow = NULL; | |
63 | } |
|
66 | } | |
64 |
|
67 | |||
65 | } |
|
68 | } | |
66 |
|
69 | |||
67 | void socexplorerproxy::setMainWindow(QMainWindow *Mainwindow) |
|
70 | void socexplorerproxy::setMainWindow(QMainWindow *Mainwindow) | |
68 | { |
|
71 | { | |
69 | if(!_self)init(); |
|
72 | if(!_self)init(); | |
70 | mainWindow=Mainwindow; |
|
73 | mainWindow=Mainwindow; | |
71 | } |
|
74 | } | |
72 |
|
75 | |||
73 | void socexplorerproxy::loadSysDriver(const QString name) |
|
76 | void socexplorerproxy::loadSysDriver(const QString name) | |
74 | { |
|
77 | { | |
75 | if(!_self)init(); |
|
78 | if(!_self)init(); | |
76 | if(pluginloader::libcanberoot(name)) |
|
79 | if(pluginloader::libcanberoot(name)) | |
77 | { |
|
80 | { | |
78 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); |
|
81 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); | |
79 | QString driverName = _self->getinstanceName(driver->baseName()); |
|
82 | QString driverName = _self->getinstanceName(driver->baseName()); | |
80 | loadSysDriver(driver,driverName); |
|
83 | loadSysDriver(driver,driverName,name); | |
81 | } |
|
84 | } | |
82 | } |
|
85 | } | |
83 |
|
86 | |||
84 | void socexplorerproxy::loadSysDriver(const QString name, const QString instanceName) |
|
87 | void socexplorerproxy::loadSysDriver(const QString name, const QString instanceName) | |
85 | { |
|
88 | { | |
86 | if(!_self)init(); |
|
89 | if(!_self)init(); | |
87 | if(pluginloader::libcanberoot(name) && !_self->instanceExists(instanceName)) |
|
90 | if(pluginloader::libcanberoot(name) && !_self->instanceExists(instanceName)) | |
88 | { |
|
91 | { | |
89 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); |
|
92 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); | |
90 | loadSysDriver(driver,instanceName); |
|
93 | loadSysDriver(driver,instanceName,name); | |
91 | } |
|
94 | } | |
92 | } |
|
95 | } | |
93 |
|
96 | |||
94 |
|
97 | |||
95 | void socexplorerproxy::loadSysDriver(socexplorerplugin *driver, const QString instanceName) |
|
98 | void socexplorerproxy::loadSysDriver(socexplorerplugin *driver, const QString instanceName, const QString path) | |
96 | { |
|
99 | { | |
97 | if(!_self)init(); |
|
100 | if(!_self)init(); | |
98 | driver->setInstanceName(instanceName); |
|
101 | driver->setInstanceName(instanceName); | |
99 | driver->parent = NULL; |
|
102 | driver->parent = NULL; | |
100 | drivers->append(driver); |
|
103 | drivers->append(driver); | |
101 | linearDriverList->append(driver); |
|
104 | linearDriverList->append(driver); | |
|
105 | if(path.isEmpty()) | |||
|
106 | linearDriverPathList->append(driver->baseName()); | |||
|
107 | else | |||
|
108 | linearDriverPathList->append(path); | |||
102 | connectChildToProxy(driver); |
|
109 | connectChildToProxy(driver); | |
103 | emit _self->addPluginGUI(driver); |
|
110 | emit _self->addPluginGUI(driver); | |
104 | emit _self->clearMenu(); |
|
111 | emit _self->clearMenu(); | |
105 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
112 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); | |
106 | SocExplorerEngine::addSOC(driver); |
|
113 | SocExplorerEngine::addSOC(driver); | |
107 | driver->postInstantiationTrigger(); |
|
114 | driver->postInstantiationTrigger(); | |
108 | } |
|
115 | } | |
109 |
|
116 | |||
110 | void socexplorerproxy::loadChildSysDriver(socexplorerplugin *parent, const QString child) |
|
117 | void socexplorerproxy::loadChildSysDriver(socexplorerplugin *parent, const QString child) | |
111 | { |
|
118 | { | |
112 | if(!_self)init(); |
|
119 | if(!_self)init(); | |
113 | if(pluginloader::libcanbechild(child)) |
|
120 | if(pluginloader::libcanbechild(child)) | |
114 | { |
|
121 | { | |
115 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(child); |
|
122 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(child); | |
116 | QString driverName = _self->getinstanceName(driver->baseName()); |
|
123 | QString driverName = _self->getinstanceName(driver->baseName()); | |
117 | bool ok=true; |
|
124 | bool ok=true; | |
118 | if(ok) |
|
125 | if(ok) | |
119 | { |
|
126 | { | |
120 | if(parent!=NULL)_self->loadSysDriverToParent(driver,parent,driverName); |
|
127 | if(parent!=NULL)_self->loadSysDriverToParent(driver,parent,driverName,child); | |
121 | } |
|
128 | } | |
122 | } |
|
129 | } | |
123 | } |
|
130 | } | |
124 |
|
131 | |||
125 | void socexplorerproxy::loadSysDriverToParent(const QString name,const QString ParentInst) |
|
132 | void socexplorerproxy::loadSysDriverToParent(const QString name,const QString ParentInst) | |
126 | { |
|
133 | { | |
127 | if(!_self)init(); |
|
134 | if(!_self)init(); | |
128 | if(pluginloader::libcanbechild(name)) |
|
135 | if(pluginloader::libcanbechild(name)) | |
129 | { |
|
136 | { | |
130 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); |
|
137 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); | |
131 | QString driverName = _self->getinstanceName(driver->baseName()); |
|
138 | QString driverName = _self->getinstanceName(driver->baseName()); | |
132 | bool ok=true; |
|
139 | bool ok=true; | |
133 | if(ok) |
|
140 | if(ok) | |
134 | { |
|
141 | { | |
135 | socexplorerplugin* parent=_self->getSysDriver(ParentInst); |
|
142 | socexplorerplugin* parent=_self->getSysDriver(ParentInst); | |
136 | if(parent!=NULL)loadSysDriverToParent(driver,parent,driverName); |
|
143 | if(parent!=NULL)loadSysDriverToParent(driver,parent,driverName,name); | |
137 | } |
|
144 | } | |
138 | } |
|
145 | } | |
139 | } |
|
146 | } | |
140 |
|
147 | |||
141 |
|
148 | |||
142 | void socexplorerproxy::loadSysDriverToParent(const QString name,const QString instanceName,const QString ParentInst) |
|
149 | void socexplorerproxy::loadSysDriverToParent(const QString name,const QString instanceName,const QString ParentInst) | |
143 | { |
|
150 | { | |
144 | if(!_self)init(); |
|
151 | if(!_self)init(); | |
145 | if(pluginloader::libcanbechild(name) && !_self->instanceExists(instanceName)) |
|
152 | if(pluginloader::libcanbechild(name) && !_self->instanceExists(instanceName)) | |
146 | { |
|
153 | { | |
147 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); |
|
154 | socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); | |
148 | bool ok=true; |
|
155 | bool ok=true; | |
149 | if(ok) |
|
156 | if(ok) | |
150 | { |
|
157 | { | |
151 | socexplorerplugin* parent=_self->getSysDriver(ParentInst); |
|
158 | socexplorerplugin* parent=_self->getSysDriver(ParentInst); | |
152 | if(parent!=NULL)loadSysDriverToParent(driver,parent,instanceName); |
|
159 | if(parent!=NULL)loadSysDriverToParent(driver,parent,instanceName,name); | |
153 | } |
|
160 | } | |
154 | } |
|
161 | } | |
155 | } |
|
162 | } | |
156 |
|
163 | |||
157 | void socexplorerproxy::loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName) |
|
164 | void socexplorerproxy::loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName,const QString path) | |
158 | { |
|
165 | { | |
159 | if(!_self)init(); |
|
166 | if(!_self)init(); | |
160 | linearDriverList->append(driver); |
|
167 | linearDriverList->append(driver); | |
|
168 | if(path.isEmpty()) | |||
|
169 | linearDriverPathList->append(driver->baseName()); | |||
|
170 | else | |||
|
171 | linearDriverPathList->append(path); | |||
161 | driver->parent = parent; |
|
172 | driver->parent = parent; | |
162 | driver->setInstanceName(instanceName); |
|
173 | driver->setInstanceName(instanceName); | |
163 | parent->childs.append(driver); |
|
174 | parent->childs.append(driver); | |
164 | connectChildToProxy(driver); |
|
175 | connectChildToProxy(driver); | |
165 | connectChildToParent(parent,driver); |
|
176 | connectChildToParent(parent,driver); | |
166 | emit _self->clearMenu(); |
|
177 | emit _self->clearMenu(); | |
167 | emit _self->addPluginGUI(driver); |
|
178 | emit _self->addPluginGUI(driver); | |
168 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
179 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); | |
169 | driver->postInstantiationTrigger(); |
|
180 | driver->postInstantiationTrigger(); | |
170 | } |
|
181 | } | |
171 |
|
182 | |||
172 |
|
183 | |||
173 | void socexplorerproxy::changeSysDriverInstName(const QString instanceName) |
|
184 | void socexplorerproxy::changeSysDriverInstName(const QString instanceName) | |
174 | { |
|
185 | { | |
175 | Q_UNUSED(instanceName) |
|
186 | Q_UNUSED(instanceName) | |
176 | } |
|
187 | } | |
177 |
|
188 | |||
178 | void socexplorerproxy::changeSysDriverInstName(const QString newinstanceName, const QString previnstanceName) |
|
189 | void socexplorerproxy::changeSysDriverInstName(const QString newinstanceName, const QString previnstanceName) | |
179 | { |
|
190 | { | |
180 | if(!_self)init(); |
|
191 | if(!_self)init(); | |
181 | socexplorerplugin*temp=_self->getSysDriver(previnstanceName); |
|
192 | socexplorerplugin*temp=_self->getSysDriver(previnstanceName); | |
182 | if(temp!=NULL) |
|
193 | if(temp!=NULL) | |
183 | { |
|
194 | { | |
184 | if(NULL!=_self->getSysDriver(newinstanceName)) |
|
195 | if(NULL!=_self->getSysDriver(newinstanceName)) | |
185 | { |
|
196 | { | |
186 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
197 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); | |
187 | return; |
|
198 | return; | |
188 | } |
|
199 | } | |
189 | temp->setInstanceName(newinstanceName); |
|
200 | temp->setInstanceName(newinstanceName); | |
190 | } |
|
201 | } | |
191 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
202 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); | |
192 | } |
|
203 | } | |
193 |
|
204 | |||
194 |
|
205 | |||
195 | void socexplorerproxy::connectChildToParent(socexplorerplugin *parent, socexplorerplugin *child) |
|
206 | void socexplorerproxy::connectChildToParent(socexplorerplugin *parent, socexplorerplugin *child) | |
196 | { |
|
207 | { | |
197 | if(!_self)init(); |
|
208 | if(!_self)init(); | |
198 | connect(parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool))); |
|
209 | connect(parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool))); | |
199 | child->activate(parent->isConnected()); |
|
210 | child->activate(parent->isConnected()); | |
200 | } |
|
211 | } | |
201 |
|
212 | |||
202 | void socexplorerproxy::disconnectChildToParent(socexplorerplugin *child) |
|
213 | void socexplorerproxy::disconnectChildToParent(socexplorerplugin *child) | |
203 | { |
|
214 | { | |
204 | if(!_self)init(); |
|
215 | if(!_self)init(); | |
205 | disconnect(child->parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool))); |
|
216 | disconnect(child->parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool))); | |
206 | } |
|
217 | } | |
207 |
|
218 | |||
208 |
|
219 | |||
209 | void socexplorerproxy::connectChildToProxy(socexplorerplugin *child) |
|
220 | void socexplorerproxy::connectChildToProxy(socexplorerplugin *child) | |
210 | { |
|
221 | { | |
211 | if(!_self)init(); |
|
222 | if(!_self)init(); | |
212 | connect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString))); |
|
223 | connect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString))); | |
213 | connect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriver(socexplorerplugin*))); |
|
224 | connect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriver(socexplorerplugin*))); | |
214 | } |
|
225 | } | |
215 |
|
226 | |||
216 | void socexplorerproxy::disconnectChildToProxy(socexplorerplugin *child) |
|
227 | void socexplorerproxy::disconnectChildToProxy(socexplorerplugin *child) | |
217 | { |
|
228 | { | |
218 | if(!_self)init(); |
|
229 | if(!_self)init(); | |
219 | disconnect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString))); |
|
230 | disconnect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString))); | |
220 | disconnect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriverFromDriver(socexplorerplugin*))); |
|
231 | disconnect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriverFromDriver(socexplorerplugin*))); | |
221 | } |
|
232 | } | |
222 |
|
233 | |||
223 | QString socexplorerproxy::getinstanceName(const QString& baseName) |
|
234 | QString socexplorerproxy::getinstanceName(const QString& baseName) | |
224 | { |
|
235 | { | |
225 | if(!_self)init(); |
|
236 | if(!_self)init(); | |
226 | int i=0; |
|
237 | int i=0; | |
227 | QString name; |
|
238 | QString name; | |
228 | bool validName = false; |
|
239 | bool validName = false; | |
229 | while(!validName) |
|
240 | while(!validName) | |
230 | { |
|
241 | { | |
231 | name.clear(); |
|
242 | name.clear(); | |
232 | name.append(baseName+QString::number(i)); |
|
243 | name.append(baseName+QString::number(i)); | |
233 | validName = instanceNameIsValid(name); |
|
244 | validName = instanceNameIsValid(name); | |
234 | i++; |
|
245 | i++; | |
235 | } |
|
246 | } | |
236 | return name; |
|
247 | return name; | |
237 | } |
|
248 | } | |
238 |
|
249 | |||
239 | void socexplorerproxy::changeSysDriverInstName(socexplorerplugin* driver) |
|
250 | void socexplorerproxy::changeSysDriverInstName(socexplorerplugin* driver) | |
240 | { |
|
251 | { | |
241 | if(!_self)init(); |
|
252 | if(!_self)init(); | |
242 | QString prevName(driver->instanceName()); |
|
253 | QString prevName(driver->instanceName()); | |
243 | } |
|
254 | } | |
244 |
|
255 | |||
245 | bool socexplorerproxy::instanceNameIsValid(const QString& instanceName) |
|
256 | bool socexplorerproxy::instanceNameIsValid(const QString& instanceName) | |
246 | { |
|
257 | { | |
247 | if(!_self)init(); |
|
258 | if(!_self)init(); | |
248 | for(int k=0;k<linearDriverList->count();k++) |
|
259 | for(int k=0;k<linearDriverList->count();k++) | |
249 | { |
|
260 | { | |
250 | if(!linearDriverList->at(k)->instanceName().compare(instanceName)) |
|
261 | if(!linearDriverList->at(k)->instanceName().compare(instanceName)) | |
251 | return false; |
|
262 | return false; | |
252 | } |
|
263 | } | |
253 | return true; |
|
264 | return true; | |
254 | } |
|
265 | } | |
255 |
|
266 | |||
256 | socexplorerplugin *socexplorerproxy::findPlugin(const QString &instanceName) |
|
267 | socexplorerplugin *socexplorerproxy::findPlugin(const QString &instanceName) | |
257 | { |
|
268 | { | |
258 | if(!_self)init(); |
|
269 | if(!_self)init(); | |
259 | for(int k=0;k<linearDriverList->count();k++) |
|
270 | for(int k=0;k<linearDriverList->count();k++) | |
260 | { |
|
271 | { | |
261 | if(!linearDriverList->at(k)->instanceName().compare(instanceName)) |
|
272 | if(!linearDriverList->at(k)->instanceName().compare(instanceName)) | |
262 | return linearDriverList->at(k); |
|
273 | return linearDriverList->at(k); | |
263 | } |
|
274 | } | |
264 | return NULL; |
|
275 | return NULL; | |
265 | } |
|
276 | } | |
266 |
|
277 | |||
|
278 | QStringList socexplorerproxy::getPluginsList() | |||
|
279 | { | |||
|
280 | if(!_self)init(); | |||
|
281 | QStringList result; | |||
|
282 | socexplorerplugin* plugin; | |||
|
283 | for(int i=0; i<linearDriverList->count();i++) | |||
|
284 | { | |||
|
285 | QString parent=""; | |||
|
286 | plugin=linearDriverList->at(i); | |||
|
287 | if(plugin->parent)parent=plugin->parent->instanceName(); | |||
|
288 | result.append(linearDriverList->at(i)->instanceName()+":"+parent+":"+linearDriverPathList->at(i)); | |||
|
289 | } | |||
|
290 | return result; | |||
|
291 | } | |||
|
292 | ||||
|
293 | bool socexplorerproxy::loadPluginsList(QStringList plugins) | |||
|
294 | { | |||
|
295 | if(!_self)init(); | |||
|
296 | QString plugin; | |||
|
297 | int lastLoadedPlugins=-1; | |||
|
298 | QStringList loadedPlugins; | |||
|
299 | while(plugins.count() && lastLoadedPlugins!=loadedPlugins.count()) | |||
|
300 | { | |||
|
301 | lastLoadedPlugins=loadedPlugins.count(); | |||
|
302 | for (int i = 0; i < plugins.count(); i++) | |||
|
303 | { | |||
|
304 | plugin=plugins[i]; | |||
|
305 | QStringList args=plugin.split(':',QString::KeepEmptyParts); | |||
|
306 | if(args.count()==3) | |||
|
307 | { | |||
|
308 | if(args[1].isEmpty()) | |||
|
309 | { | |||
|
310 | _self->loadSysDriver(args[2],args[0]); | |||
|
311 | loadedPlugins.append(args[0]); | |||
|
312 | plugins.removeAt(i); | |||
|
313 | } | |||
|
314 | else if(loadedPlugins.contains(args[1])) | |||
|
315 | { | |||
|
316 | _self->loadSysDriverToParent(args[2],args[0],args[1]); | |||
|
317 | loadedPlugins.append(args[0]); | |||
|
318 | plugins.removeAt(i); | |||
|
319 | } | |||
|
320 | } | |||
|
321 | else | |||
|
322 | { | |||
|
323 | plugins.removeAt(i); | |||
|
324 | } | |||
|
325 | } | |||
|
326 | } | |||
|
327 | } | |||
|
328 | ||||
267 | bool socexplorerproxy::instanceExists(const QString &instanceName) |
|
329 | bool socexplorerproxy::instanceExists(const QString &instanceName) | |
268 | { |
|
330 | { | |
269 | return !socexplorerproxy::instanceNameIsValid(instanceName); |
|
331 | return !socexplorerproxy::instanceNameIsValid(instanceName); | |
270 | } |
|
332 | } | |
271 |
|
333 | |||
272 | void socexplorerproxy::close() |
|
334 | void socexplorerproxy::close() | |
273 | { |
|
335 | { | |
274 | if(!_self)init(); |
|
336 | if(!_self)init(); | |
275 | socexplorerplugin* tmpPtr; |
|
337 | socexplorerplugin* tmpPtr; | |
276 | while(drivers->count()>0) |
|
338 | while(drivers->count()>0) | |
277 | { |
|
339 | { | |
278 | tmpPtr = drivers->last(); |
|
340 | tmpPtr = drivers->last(); | |
279 | drivers->removeLast(); |
|
341 | drivers->removeLast(); | |
280 | _self->closeSysDriver(tmpPtr); |
|
342 | _self->closeSysDriver(tmpPtr); | |
281 | } |
|
343 | } | |
282 | if(root!=NULL) |
|
344 | if(root!=NULL) | |
283 | { |
|
345 | { | |
284 | _self->closeSysDriver(root); |
|
346 | _self->closeSysDriver(root); | |
285 | } |
|
347 | } | |
286 |
|
348 | |||
287 | } |
|
349 | } | |
288 |
|
350 | |||
289 | socexplorerplugin* socexplorerproxy::getSysDriver(const QString instanceName) |
|
351 | socexplorerplugin* socexplorerproxy::getSysDriver(const QString instanceName) | |
290 | { |
|
352 | { | |
291 | if(!_self)init(); |
|
353 | if(!_self)init(); | |
292 | for(int i=0;i<linearDriverList->count();i++) |
|
354 | for(int i=0;i<linearDriverList->count();i++) | |
293 | { |
|
355 | { | |
294 | if(!linearDriverList->at(i)->instanceName().compare(instanceName)) |
|
356 | if(!linearDriverList->at(i)->instanceName().compare(instanceName)) | |
295 | return linearDriverList->at(i); |
|
357 | return linearDriverList->at(i); | |
296 | } |
|
358 | } | |
297 | return NULL; |
|
359 | return NULL; | |
298 | } |
|
360 | } | |
299 |
|
361 | |||
300 |
|
362 | |||
301 | void socexplorerproxy::closeSysDriver(const QString instanceName) |
|
363 | void socexplorerproxy::closeSysDriver(const QString instanceName) | |
302 | { |
|
364 | { | |
303 | if(!_self)init(); |
|
365 | if(!_self)init(); | |
304 | closeSysDriver(getSysDriver(instanceName),false); |
|
366 | closeSysDriver(getSysDriver(instanceName),false); | |
305 | } |
|
367 | } | |
306 |
|
368 | |||
307 | void socexplorerproxy::closeSysDriver(socexplorerplugin *driver, bool recursive) |
|
369 | void socexplorerproxy::closeSysDriver(socexplorerplugin *driver, bool recursive) | |
308 | { |
|
370 | { | |
309 | if(!_self)init(); |
|
371 | if(!_self)init(); | |
310 | if(driver!=NULL) |
|
372 | if(driver!=NULL) | |
311 | { |
|
373 | { | |
312 | emit _self->removePluginGUI(driver); |
|
374 | emit _self->removePluginGUI(driver); | |
313 | if(driver->parent==NULL)SocExplorerEngine::removeSOC(driver); |
|
375 | if(driver->parent==NULL)SocExplorerEngine::removeSOC(driver); | |
314 | while(driver->childs.count()!=0)closeSysDriver(driver->childs.first()); |
|
376 | while(driver->childs.count()!=0)closeSysDriver(driver->childs.first()); | |
|
377 | linearDriverPathList->removeAt(linearDriverList->indexOf(driver)); | |||
315 | linearDriverList->removeOne(driver); |
|
378 | linearDriverList->removeOne(driver); | |
316 | if(driver->parent!= NULL) |
|
379 | if(driver->parent!= NULL) | |
317 | { |
|
380 | { | |
318 | driver->parent->childs.removeOne(driver); //Have parent so it's a child |
|
381 | driver->parent->childs.removeOne(driver); //Have parent so it's a child | |
319 | disconnectChildToParent(driver); |
|
382 | disconnectChildToParent(driver); | |
320 | disconnectChildToProxy(driver); |
|
383 | disconnectChildToProxy(driver); | |
321 | delete driver; |
|
384 | delete driver; | |
322 | } |
|
385 | } | |
323 | else |
|
386 | else | |
324 | { |
|
387 | { | |
325 | drivers->removeOne(driver); |
|
388 | drivers->removeOne(driver); | |
326 | disconnectChildToProxy(driver); |
|
389 | disconnectChildToProxy(driver); | |
327 | delete driver; |
|
390 | delete driver; | |
328 | } |
|
391 | } | |
329 | if(!recursive) |
|
392 | if(!recursive) | |
330 | { |
|
393 | { | |
331 | emit _self->clearMenu(); |
|
394 | emit _self->clearMenu(); | |
332 | emit _self->registermenu(mainWindow); |
|
395 | emit _self->registermenu(mainWindow); | |
333 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
396 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); | |
334 | } |
|
397 | } | |
335 | } |
|
398 | } | |
336 |
|
399 | |||
337 | } |
|
400 | } | |
338 |
|
401 | |||
339 | void socexplorerproxy::geteplugintree() |
|
402 | void socexplorerproxy::geteplugintree() | |
340 | { |
|
403 | { | |
341 | if(!_self)init(); |
|
404 | if(!_self)init(); | |
342 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); |
|
405 | emit _self->treeChanged(QList<socexplorerplugin*>(*drivers)); | |
343 | } |
|
406 | } | |
344 |
|
407 | |||
345 | void socexplorerproxy::closeSysDriverFromDriver(socexplorerplugin *driver) |
|
408 | void socexplorerproxy::closeSysDriverFromDriver(socexplorerplugin *driver) | |
346 | { |
|
409 | { | |
347 | if(!_self)init(); |
|
410 | if(!_self)init(); | |
348 | emit _self->closeSysDriverSig(driver); |
|
411 | emit _self->closeSysDriverSig(driver); | |
349 | } |
|
412 | } | |
350 |
|
413 | |||
351 | void socexplorerproxy::updateText() |
|
414 | void socexplorerproxy::updateText() | |
352 | { |
|
415 | { | |
353 | if(!_self)init(); |
|
416 | if(!_self)init(); | |
354 | emit _self->clearMenu(); |
|
417 | emit _self->clearMenu(); | |
355 | emit _self->registermenu(mainWindow); |
|
418 | emit _self->registermenu(mainWindow); | |
356 | } |
|
419 | } | |
357 |
|
420 | |||
358 |
|
421 | |||
359 |
|
422 | |||
360 |
|
423 | |||
361 |
|
424 | |||
362 | void socexplorerproxy::makeMenu(QMenu* menu) |
|
425 | void socexplorerproxy::makeMenu(QMenu* menu) | |
363 | { |
|
426 | { | |
364 | if(!_self)init(); |
|
427 | if(!_self)init(); | |
365 | for(int i=0;i<drivers->count();i++) |
|
428 | for(int i=0;i<drivers->count();i++) | |
366 | { |
|
429 | { | |
367 | drivers->at(i)->registermenu(menu); |
|
430 | drivers->at(i)->registermenu(menu); | |
368 | } |
|
431 | } | |
369 | } |
|
432 | } | |
370 |
|
433 | |||
371 |
|
434 |
@@ -1,103 +1,106 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef SOCEXPLORERPROXY_H |
|
22 | #ifndef SOCEXPLORERPROXY_H | |
23 | #define SOCEXPLORERPROXY_H |
|
23 | #define SOCEXPLORERPROXY_H | |
24 |
|
24 | |||
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QString> |
|
26 | #include <QString> | |
27 | #include <QList> |
|
27 | #include <QList> | |
28 | #include "pluginscache.h" |
|
28 | #include "pluginscache.h" | |
29 | #include <socexplorerplugin.h> |
|
29 | #include <socexplorerplugin.h> | |
30 | #include <socexplorerplugininterface.h> |
|
30 | #include <socexplorerplugininterface.h> | |
31 | #include <QInputDialog> |
|
31 | #include <QInputDialog> | |
32 | #include <QtGlobal> |
|
32 | #include <QtGlobal> | |
33 |
|
33 | |||
34 | #if defined(SOCEXPLORER_SDK_BUILD) |
|
34 | #if defined(SOCEXPLORER_SDK_BUILD) | |
35 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT |
|
35 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT | |
36 | #else |
|
36 | #else | |
37 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT |
|
37 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT | |
38 | #endif |
|
38 | #endif | |
39 |
|
39 | |||
40 | class SOCEXPLORER_SDK_EXPORT socexplorerproxy : public QObject |
|
40 | class SOCEXPLORER_SDK_EXPORT socexplorerproxy : public QObject | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | private: |
|
43 | private: | |
44 | socexplorerproxy(QObject *parent = 0); |
|
44 | socexplorerproxy(QObject *parent = 0); | |
45 | socexplorerproxy(QMainWindow* Mainwindow,QObject *parent = 0); |
|
45 | socexplorerproxy(QMainWindow* Mainwindow,QObject *parent = 0); | |
46 | static socexplorerproxy* _self; |
|
46 | static socexplorerproxy* _self; | |
47 | public: |
|
47 | public: | |
48 | static socexplorerproxy* self(){if(!_self)init(); return _self;} |
|
48 | static socexplorerproxy* self(){if(!_self)init(); return _self;} | |
49 | static void init(); |
|
49 | static void init(); | |
50 | static void setMainWindow(QMainWindow* Mainwindow); |
|
50 | static void setMainWindow(QMainWindow* Mainwindow); | |
51 | static void connectChildToParent(socexplorerplugin* parent, socexplorerplugin* child); |
|
51 | static void connectChildToParent(socexplorerplugin* parent, socexplorerplugin* child); | |
52 | static void connectChildToProxy(socexplorerplugin* child); |
|
52 | static void connectChildToProxy(socexplorerplugin* child); | |
53 | static void disconnectChildToParent(socexplorerplugin* child); |
|
53 | static void disconnectChildToParent(socexplorerplugin* child); | |
54 | static void disconnectChildToProxy(socexplorerplugin* child); |
|
54 | static void disconnectChildToProxy(socexplorerplugin* child); | |
55 | static bool instanceNameIsValid(const QString& instanceName); |
|
55 | static bool instanceNameIsValid(const QString& instanceName); | |
56 | static socexplorerplugin* findPlugin(const QString &instanceName); |
|
56 | static socexplorerplugin* findPlugin(const QString &instanceName); | |
|
57 | static QStringList getPluginsList(); | |||
|
58 | static bool loadPluginsList( QStringList plugins); | |||
57 |
|
59 | |||
58 | QT_ENSURE_STACK_ALIGNED_FOR_SSE static void loadChildSysDriver(socexplorerplugin* parent,const QString child); |
|
60 | QT_ENSURE_STACK_ALIGNED_FOR_SSE static void loadChildSysDriver(socexplorerplugin* parent,const QString child); | |
59 |
|
61 | |||
60 | signals: |
|
62 | signals: | |
61 | void addPluginGUI(QDockWidget* plugin); |
|
63 | void addPluginGUI(QDockWidget* plugin); | |
62 | void removePluginGUI(QDockWidget* plugin); |
|
64 | void removePluginGUI(QDockWidget* plugin); | |
63 | int registermenu(QMainWindow* menuHolder); |
|
65 | int registermenu(QMainWindow* menuHolder); | |
64 | void clearMenu(); |
|
66 | void clearMenu(); | |
65 | QStringList findDrivers(int VID,int PID); |
|
67 | QStringList findDrivers(int VID,int PID); | |
66 | void rootDriverAdded(socexplorerplugin* driver); |
|
68 | void rootDriverAdded(socexplorerplugin* driver); | |
67 | void rootDriverRemoved(); |
|
69 | void rootDriverRemoved(); | |
68 | void closeSysDriverSig(socexplorerplugin* driver); |
|
70 | void closeSysDriverSig(socexplorerplugin* driver); | |
69 | void registerObject(QObject* object,const QString& instanceName); |
|
71 | void registerObject(QObject* object,const QString& instanceName); | |
70 | void treeChanged(const QList<socexplorerplugin*>& drivers); |
|
72 | void treeChanged(const QList<socexplorerplugin*>& drivers); | |
71 |
|
73 | |||
72 | public slots: |
|
74 | public slots: | |
73 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(const QString name); |
|
75 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(const QString name); | |
74 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(const QString name,const QString instanceName); |
|
76 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(const QString name,const QString instanceName); | |
75 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(socexplorerplugin* driver,const QString instanceName); |
|
77 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(socexplorerplugin* driver,const QString instanceName,const QString path=""); | |
76 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(const QString name,const QString ParentInst); |
|
78 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(const QString name,const QString ParentInst); | |
77 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(const QString name,const QString instanceName,const QString ParentInst); |
|
79 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(const QString name,const QString instanceName,const QString ParentInst); | |
78 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName); |
|
80 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName,const QString path=""); | |
79 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void changeSysDriverInstName(const QString instanceName); |
|
81 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void changeSysDriverInstName(const QString instanceName); | |
80 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void changeSysDriverInstName(const QString newinstanceName,const QString previnstanceName); |
|
82 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void changeSysDriverInstName(const QString newinstanceName,const QString previnstanceName); | |
81 | // QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadChild(socexplorerplugin* parent); |
|
83 | // QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadChild(socexplorerplugin* parent); | |
82 | void updateText(); |
|
84 | void updateText(); | |
83 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void closeSysDriverFromDriver(socexplorerplugin* driver); |
|
85 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void closeSysDriverFromDriver(socexplorerplugin* driver); | |
84 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void closeSysDriver(socexplorerplugin* driver,bool recursive=false); |
|
86 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void closeSysDriver(socexplorerplugin* driver,bool recursive=false); | |
85 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void closeSysDriver(const QString instanceName); |
|
87 | QT_ENSURE_STACK_ALIGNED_FOR_SSE void closeSysDriver(const QString instanceName); | |
86 | void makeMenu(QMenu* menu); |
|
88 | void makeMenu(QMenu* menu); | |
87 | void close(); |
|
89 | void close(); | |
88 | QString getinstanceName(const QString& baseName); |
|
90 | QString getinstanceName(const QString& baseName); | |
89 | void geteplugintree(); |
|
91 | void geteplugintree(); | |
90 | QT_ENSURE_STACK_ALIGNED_FOR_SSE socexplorerplugin* getSysDriver(const QString instanceName); |
|
92 | QT_ENSURE_STACK_ALIGNED_FOR_SSE socexplorerplugin* getSysDriver(const QString instanceName); | |
91 | bool instanceExists(const QString& instanceName); |
|
93 | bool instanceExists(const QString& instanceName); | |
92 | private: |
|
94 | private: | |
93 |
|
95 | |||
94 | static void changeSysDriverInstName(socexplorerplugin* driver); |
|
96 | static void changeSysDriverInstName(socexplorerplugin* driver); | |
95 | static QMainWindow* mainWindow; |
|
97 | static QMainWindow* mainWindow; | |
96 | static QList<socexplorerplugin*>* drivers; |
|
98 | static QList<socexplorerplugin*>* drivers; | |
97 | static QList<socexplorerplugin*>* linearDriverList; |
|
99 | static QList<socexplorerplugin*>* linearDriverList; | |
|
100 | static QStringList* linearDriverPathList; | |||
98 | static socexplorerplugin* root; |
|
101 | static socexplorerplugin* root; | |
99 | static socexplorerplugin* parent; |
|
102 | static socexplorerplugin* parent; | |
100 | static PluginsCache* cache; |
|
103 | static PluginsCache* cache; | |
101 | }; |
|
104 | }; | |
102 |
|
105 | |||
103 | #endif // SOCEXPLORERPROXY_H |
|
106 | #endif // SOCEXPLORERPROXY_H |
@@ -1,258 +1,328 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2011-2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2011-2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "mainwindow.h" |
|
22 | #include "mainwindow.h" | |
23 | #include <QDockWidget> |
|
23 | #include <QDockWidget> | |
24 | #include <socexplorersettings.h> |
|
24 | #include <socexplorersettings.h> | |
25 | #include <socexplorerconfigkeys.h> |
|
25 | #include <socexplorerconfigkeys.h> | |
26 |
|
26 | |||
27 | SocExplorerMainWindow::SocExplorerMainWindow(QString ScriptToEval, QWidget *parent) |
|
27 | SocExplorerMainWindow::SocExplorerMainWindow(QString ScriptToEval, QWidget *parent) | |
28 | : QMainWindow(parent) |
|
28 | : QMainWindow(parent) | |
29 | { |
|
29 | { | |
30 | QCoreApplication::setApplicationName("SocExplorer"); |
|
30 | QCoreApplication::setApplicationName("SocExplorer"); | |
31 | QCoreApplication::setOrganizationName("LPP"); |
|
31 | QCoreApplication::setOrganizationName("LPP"); | |
32 | QCoreApplication::setOrganizationDomain("lpp.fr"); |
|
32 | QCoreApplication::setOrganizationDomain("lpp.fr"); | |
33 | this->makeObjects(ScriptToEval); |
|
33 | this->makeObjects(ScriptToEval); | |
34 | this->makeLayout(); |
|
34 | this->makeLayout(); | |
35 | this->makeMenu(); |
|
35 | this->makeMenu(); | |
36 | SocExplorerSettings::init(); |
|
36 | SocExplorerSettings::init(); | |
37 | SocExplorerSettings::loadSession("Session1"); |
|
|||
38 | this->makeConnections(); |
|
37 | this->makeConnections(); | |
39 | this->setWindowIcon(QIcon(":/images/icon.png")); |
|
38 | this->setWindowIcon(QIcon(":/images/icon.png")); | |
40 | this->setAcceptDrops(true); |
|
39 | this->setAcceptDrops(true); | |
41 | this->pluginManager->setRootLoadable(true); |
|
40 | this->pluginManager->setRootLoadable(true); | |
42 | this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval); |
|
41 | this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval); | |
43 | QFile file(":/styles/SocExplorer.css"); |
|
42 | QFile file(":/styles/SocExplorer.css"); | |
44 | if(file.open(QIODevice::ReadOnly | QIODevice::Text)) |
|
43 | if(file.open(QIODevice::ReadOnly | QIODevice::Text)) | |
45 | { |
|
44 | { | |
46 | qApp->setStyleSheet(file.readAll()); |
|
45 | qApp->setStyleSheet(file.readAll()); | |
47 | file.close(); |
|
46 | file.close(); | |
48 | } |
|
47 | } | |
49 | } |
|
48 | } | |
50 |
|
49 | |||
51 |
|
50 | |||
52 | void SocExplorerMainWindow::makeObjects(QString ScriptToEval) |
|
51 | void SocExplorerMainWindow::makeObjects(QString ScriptToEval) | |
53 | { |
|
52 | { | |
54 | Q_UNUSED(ScriptToEval) |
|
53 | Q_UNUSED(ScriptToEval) | |
55 | this->p_pluginGUIlist = new QList<QDockWidget*>(); |
|
54 | this->p_pluginGUIlist = new QList<QDockWidget*>(); | |
56 | pluginsDockContainer = new QMainWindow; |
|
55 | pluginsDockContainer = new QMainWindow; | |
|
56 | pluginsDockContainer->setObjectName("pluginsDockContainer"); | |||
57 | pluginsDockContainer->setWindowFlags(Qt::Widget); |
|
57 | pluginsDockContainer->setWindowFlags(Qt::Widget); | |
58 | pluginsDockContainer->setDockNestingEnabled(true); |
|
58 | pluginsDockContainer->setDockNestingEnabled(true); | |
59 | this->mainWidget = new QSplitter(Qt::Vertical); |
|
59 | this->mainWidget = new QSplitter(Qt::Vertical); | |
60 | this->appTranslator = new QTranslator; |
|
60 | this->appTranslator = new QTranslator; | |
61 | this->Quit = new QAction(tr("&Quit"),this); |
|
61 | this->Quit = new QAction(tr("&Quit"),this); | |
62 | this->Quit->setShortcut(tr("CTRL+Q")); |
|
62 | this->Quit->setShortcut(tr("CTRL+Q")); | |
63 | this->ManagePlugins = new QAction(tr("&Manage Plugins"),this); |
|
63 | this->ManagePlugins = new QAction(tr("&Manage Plugins"),this); | |
64 | this->ManagePlugins->setShortcut(tr("CTRL+P")); |
|
64 | this->ManagePlugins->setShortcut(tr("CTRL+P")); | |
65 | this->regsManager = new QAction(tr("&Manage registers"),this); |
|
65 | this->regsManager = new QAction(tr("&Manage registers"),this); | |
66 | this->exploreRegs = new QAction(tr("&Explore registers"),this); |
|
66 | this->exploreRegs = new QAction(tr("&Explore registers"),this); | |
67 | this->help = new QAction(tr("&Help"),this); |
|
67 | this->help = new QAction(tr("&Help"),this); | |
68 | this->help->setShortcut(tr("CTRL+H")); |
|
68 | this->help->setShortcut(tr("CTRL+H")); | |
69 | this->about = new QAction(tr("&About"),this); |
|
69 | this->about = new QAction(tr("&About"),this); | |
70 | this->p_SessionManagerDialog = new SessionManagerDialog(); |
|
70 | this->p_SessionManagerDialog = new SessionManagerDialog(); | |
71 | socexplorerproxy::setMainWindow(this); |
|
71 | socexplorerproxy::setMainWindow(this); | |
72 | SocExplorerEngine::setMainWindow(this); |
|
72 | SocExplorerEngine::setMainWindow(this); | |
73 | SocExplorerEngine::xmlModel()->scanXmlFiles(); |
|
73 | SocExplorerEngine::xmlModel()->scanXmlFiles(); | |
74 | this->regExplorer = new RegsExplorer(); |
|
74 | this->regExplorer = new RegsExplorer(); | |
75 | this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
75 | this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas); | |
|
76 | this->regExplorer->setObjectName("regExplorer"); | |||
76 | this->addPluginInterface(this->regExplorer); |
|
77 | this->addPluginInterface(this->regExplorer); | |
77 | this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self()); |
|
78 | this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self()); | |
78 | this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self()); |
|
79 | this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self()); | |
79 | this->pluginManager = new dockablePluginManager(); |
|
80 | this->pluginManager = new dockablePluginManager(); | |
80 | this->toolpane = new toolBar; |
|
81 | this->toolpane = new toolBar; | |
|
82 | this->toolpane->setObjectName("toolpane"); | |||
81 | this->p_about = new aboutsocexplorer(); |
|
83 | this->p_about = new aboutsocexplorer(); | |
82 | } |
|
84 | } | |
83 |
|
85 | |||
84 | void SocExplorerMainWindow::makeLayout() |
|
86 | void SocExplorerMainWindow::makeLayout() | |
85 | { |
|
87 | { | |
86 | this->mainWidget->addWidget(pluginsDockContainer); |
|
88 | this->mainWidget->addWidget(pluginsDockContainer); | |
87 | this->mainWidget->addWidget(this->PythonConsoleInst); |
|
89 | this->mainWidget->addWidget(this->PythonConsoleInst); | |
88 | this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); |
|
90 | this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); | |
89 | this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane); |
|
91 | this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane); | |
90 | this->toolpane->addTool(this->pluginManager); |
|
92 | this->toolpane->addTool(this->pluginManager); | |
91 | this->setCentralWidget(this->mainWidget); |
|
93 | this->setCentralWidget(this->mainWidget); | |
92 | } |
|
94 | } | |
93 |
|
95 | |||
94 |
|
96 | |||
95 | void SocExplorerMainWindow::makeConnections() |
|
97 | void SocExplorerMainWindow::makeConnections() | |
96 | { |
|
98 | { | |
97 | connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu())); |
|
99 | connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu())); | |
98 | connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText())); |
|
100 | connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText())); | |
99 | connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*))); |
|
101 | connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*))); | |
100 | connect(socexplorerproxy::self(),SIGNAL(removePluginGUI(QDockWidget*)),this,SLOT(removePluginInterface(QDockWidget*))); |
|
102 | connect(socexplorerproxy::self(),SIGNAL(removePluginGUI(QDockWidget*)),this,SLOT(removePluginInterface(QDockWidget*))); | |
101 | connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager())); |
|
103 | connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager())); | |
102 | connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit())); |
|
104 | connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit())); | |
103 | connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString))); |
|
105 | connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString))); | |
104 | connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString))); |
|
106 | connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString))); | |
105 | connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree())); |
|
107 | connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree())); | |
106 | connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>))); |
|
108 | connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>))); | |
107 | connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString))); |
|
109 | connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString))); | |
108 | connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString))); |
|
110 | connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString))); | |
109 | connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString))); |
|
111 | connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString))); | |
110 | connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString))); |
|
112 | connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString))); | |
111 | connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString))); |
|
113 | connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString))); | |
112 | connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox())); |
|
114 | connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox())); | |
113 | connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show())); |
|
115 | connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show())); | |
114 |
|
116 | |||
115 |
connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this |
|
117 | connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this,SLOT(showSessionManager(bool))); | |
|
118 | connect(this->p_SessionManagerDialog, SIGNAL(switchSession(QString)),this,SLOT(setActiveSession(QString))); | |||
116 |
|
119 | |||
117 | this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString))); |
|
120 | this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString))); | |
118 | this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString))); |
|
121 | this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString))); | |
119 |
|
122 | |||
120 | } |
|
123 | } | |
121 |
|
124 | |||
122 |
|
125 | |||
123 | void SocExplorerMainWindow::launchPluginManager() |
|
126 | void SocExplorerMainWindow::launchPluginManager() | |
124 | { |
|
127 | { | |
125 |
|
||||
126 | if(this->pluginManager->isHidden()) |
|
128 | if(this->pluginManager->isHidden()) | |
127 | { |
|
129 | { | |
128 | this->pluginManager->setHidden(false); |
|
130 | this->pluginManager->setHidden(false); | |
129 | } |
|
131 | } | |
130 |
|
||||
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 |
|
134 | |||
134 | void SocExplorerMainWindow::addPluginInterface(QDockWidget *plugin) |
|
135 | void SocExplorerMainWindow::addPluginInterface(QDockWidget *plugin) | |
135 | { |
|
136 | { | |
136 | plugin->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
137 | plugin->setAllowedAreas(Qt::AllDockWidgetAreas); | |
137 | this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin); |
|
138 | this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin); | |
138 | if(p_pluginGUIlist->count()!=0) |
|
139 | if(p_pluginGUIlist->count()!=0) | |
139 | this->pluginsDockContainer->tabifyDockWidget(p_pluginGUIlist->last(),plugin); |
|
140 | this->pluginsDockContainer->tabifyDockWidget(p_pluginGUIlist->last(),plugin); | |
140 | p_pluginGUIlist->append(plugin); |
|
141 | p_pluginGUIlist->append(plugin); | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | void SocExplorerMainWindow::removePluginInterface(QDockWidget *plugin) |
|
144 | void SocExplorerMainWindow::removePluginInterface(QDockWidget *plugin) | |
144 | { |
|
145 | { | |
145 | p_pluginGUIlist->removeOne(plugin); |
|
146 | p_pluginGUIlist->removeOne(plugin); | |
146 | this->pluginsDockContainer->removeDockWidget(plugin); |
|
147 | this->pluginsDockContainer->removeDockWidget(plugin); | |
147 | } |
|
148 | } | |
148 |
|
149 | |||
149 |
|
150 | |||
150 | void SocExplorerMainWindow::clearMenu() |
|
151 | void SocExplorerMainWindow::clearMenu() | |
151 | { |
|
152 | { | |
152 | this->menuBar()->clear(); |
|
153 | this->menuBar()->clear(); | |
153 | this->makeMenu(); |
|
154 | this->makeMenu(); | |
154 | } |
|
155 | } | |
155 |
|
156 | |||
156 |
|
157 | |||
157 | void SocExplorerMainWindow::makeMenu() |
|
158 | void SocExplorerMainWindow::makeMenu() | |
158 | { |
|
159 | { | |
159 | this->FileMenu = menuBar()->addMenu(tr("&File")); |
|
160 | this->FileMenu = menuBar()->addMenu(tr("&File")); | |
160 | this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions")); |
|
161 | this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions")); | |
|
162 | this->loadSessions(); | |||
161 | this->sessionManagerAction = this->FileMenu->addAction(tr("&Session manager...")); |
|
163 | this->sessionManagerAction = this->FileMenu->addAction(tr("&Session manager...")); | |
162 | this->SettingsMenu = menuBar()->addMenu(tr("&Settings")); |
|
164 | this->SettingsMenu = menuBar()->addMenu(tr("&Settings")); | |
163 | SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu); |
|
165 | SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu); | |
164 | this->PluginsMenu = menuBar()->addMenu(tr("&Plugins")); |
|
166 | this->PluginsMenu = menuBar()->addMenu(tr("&Plugins")); | |
165 | this->ToolsMenu = menuBar()->addMenu(tr("&Tools")); |
|
167 | this->ToolsMenu = menuBar()->addMenu(tr("&Tools")); | |
166 | this->ToolsMenu->addAction(this->exploreRegs); |
|
168 | this->ToolsMenu->addAction(this->exploreRegs); | |
167 | this->FileMenu->addAction(this->Quit); |
|
169 | this->FileMenu->addAction(this->Quit); | |
168 | socexplorerproxy::self()->makeMenu(this->PluginsMenu); |
|
170 | socexplorerproxy::self()->makeMenu(this->PluginsMenu); | |
169 | this->PluginsMenu->addAction(this->ManagePlugins); |
|
171 | this->PluginsMenu->addAction(this->ManagePlugins); | |
170 |
|
172 | |||
171 | this->helpMenu = menuBar()->addMenu(tr("Help")); |
|
173 | this->helpMenu = menuBar()->addMenu(tr("Help")); | |
172 | this->helpMenu->addAction(this->help); |
|
174 | this->helpMenu->addAction(this->help); | |
173 | this->helpMenu->addAction(this->about); |
|
175 | this->helpMenu->addAction(this->about); | |
174 |
|
176 | |||
175 | } |
|
177 | } | |
176 |
|
178 | |||
177 | void SocExplorerMainWindow::loadSessions() |
|
179 | void SocExplorerMainWindow::loadSessions() | |
178 | { |
|
180 | { | |
179 | p_Sessions=this->p_SessionManagerDialog->getSessionsList(); |
|
181 | p_Sessions=this->p_SessionManagerDialog->getSessionsList(); | |
|
182 | sessionsActions_t* sact; | |||
|
183 | QString stext; | |||
|
184 | foreach (sact, sessionsActions) | |||
|
185 | { | |||
|
186 | sessionsActions.removeAll(sact); | |||
|
187 | SessionsMenu->removeAction(sact); | |||
|
188 | disconnect(sact); | |||
|
189 | delete sact; | |||
|
190 | } | |||
|
191 | foreach (stext, p_Sessions) | |||
|
192 | { | |||
|
193 | sact = new sessionsActions_t(stext,this); | |||
|
194 | sact->setCheckable(true); | |||
|
195 | connect(sact,SIGNAL(triggered(QString)),this,SLOT(setActiveSession(QString))); | |||
|
196 | sessionsActions.append(sact); | |||
|
197 | SessionsMenu->addAction(sact); | |||
|
198 | } | |||
|
199 | } | |||
|
200 | ||||
|
201 | void SocExplorerMainWindow::savePlugins() | |||
|
202 | { | |||
|
203 | ||||
|
204 | } | |||
|
205 | ||||
|
206 | void SocExplorerMainWindow::saveCurrentSession() | |||
|
207 | { | |||
|
208 | if(p_currentSession.isEmpty()) | |||
|
209 | { | |||
|
210 | SocExplorerSettings::loadSession("default"); | |||
|
211 | } | |||
|
212 | SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session); | |||
|
213 | SocExplorerSettings::setValue(this,"DOCK_LOCATIONS",this->saveState(0),SocExplorerSettings::Session); | |||
|
214 | SocExplorerSettings::setValue(this,"MAIN_WINDOW_GEOMETRY",this->saveGeometry(),SocExplorerSettings::Session); | |||
|
215 | QStringList plugins = socexplorerproxy::getPluginsList(); | |||
|
216 | SocExplorerSettings::setValue(this,"LOADED_PLUGINS",QVariant(plugins),SocExplorerSettings::Session); | |||
|
217 | SocExplorerSettings::sync(); | |||
|
218 | } | |||
|
219 | ||||
|
220 | void SocExplorerMainWindow::loadCurrentSession() | |||
|
221 | { | |||
|
222 | ||||
|
223 | QStringList plugins = SocExplorerSettings::value(this,"LOADED_PLUGINS",QVariant(),SocExplorerSettings::Session).toStringList(); | |||
|
224 | socexplorerproxy::loadPluginsList(plugins); | |||
|
225 | this->restoreGeometry(SocExplorerSettings::value(this,"MAIN_WINDOW_GEOMETRY",QVariant(),SocExplorerSettings::Session).toByteArray()); | |||
|
226 | this->restoreState(SocExplorerSettings::value(this,"DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray()); | |||
180 | } |
|
227 | } | |
181 |
|
228 | |||
182 |
|
229 | |||
183 | SocExplorerMainWindow::~SocExplorerMainWindow() |
|
230 | SocExplorerMainWindow::~SocExplorerMainWindow() | |
184 | { |
|
231 | { | |
185 | SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session); |
|
232 | ||
186 | SocExplorerSettings::sync(); |
|
|||
187 | } |
|
233 | } | |
188 |
|
234 | |||
189 |
|
235 | |||
190 | void SocExplorerMainWindow::setLangage(QAction *action) |
|
236 | void SocExplorerMainWindow::setLangage(QAction *action) | |
191 | { |
|
237 | { | |
192 | QString local = action->data().toString(); |
|
238 | QString local = action->data().toString(); | |
193 | QString qmPath = QDir(QString("translations")).absolutePath(); |
|
239 | QString qmPath = QDir(QString("translations")).absolutePath(); | |
194 | appTranslator->load(qmPath+"/socexplorer_"+local+".qm"); |
|
240 | appTranslator->load(qmPath+"/socexplorer_"+local+".qm"); | |
195 | qApp->installTranslator(appTranslator); |
|
241 | qApp->installTranslator(appTranslator); | |
196 | emit this->translateSig(); |
|
242 | emit this->translateSig(); | |
197 | } |
|
243 | } | |
198 |
|
244 | |||
199 |
|
245 | |||
200 | void SocExplorerMainWindow::createLangMenu() |
|
246 | void SocExplorerMainWindow::createLangMenu() | |
201 | { |
|
247 | { | |
202 | this->langMenu = menuBar()->addMenu(tr("&Langue")); |
|
248 | this->langMenu = menuBar()->addMenu(tr("&Langue")); | |
203 | this->langActionGrp = new QActionGroup(this); |
|
249 | this->langActionGrp = new QActionGroup(this); | |
204 | connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*))); |
|
250 | connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*))); | |
205 | QDir* qmDir = new QDir(QString("translations")); |
|
251 | QDir* qmDir = new QDir(QString("translations")); | |
206 | QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm")); |
|
252 | QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm")); | |
207 | for(int i=0;i<LangFiles.size();++i) |
|
253 | for(int i=0;i<LangFiles.size();++i) | |
208 | { |
|
254 | { | |
209 | QString Local = LangFiles[i]; |
|
255 | QString Local = LangFiles[i]; | |
210 | Local.remove(0,Local.indexOf('_')+1); |
|
256 | Local.remove(0,Local.indexOf('_')+1); | |
211 | Local.chop(3); |
|
257 | Local.chop(3); | |
212 | QTranslator translator; |
|
258 | QTranslator translator; | |
213 | translator.load(LangFiles[i],qmDir->absolutePath()); |
|
259 | translator.load(LangFiles[i],qmDir->absolutePath()); | |
214 | QString langage = translator.translate("MainWindow","English"); |
|
260 | QString langage = translator.translate("MainWindow","English"); | |
215 | QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this); |
|
261 | QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this); | |
216 | action->setCheckable(true); |
|
262 | action->setCheckable(true); | |
217 | action->setData(Local); |
|
263 | action->setData(Local); | |
218 | langMenu->addAction(action); |
|
264 | langMenu->addAction(action); | |
219 | langActionGrp->addAction(action); |
|
265 | langActionGrp->addAction(action); | |
220 | if(langage==tr("English")) |
|
266 | if(langage==tr("English")) | |
221 | action->setChecked(true); |
|
267 | action->setChecked(true); | |
222 | } |
|
268 | } | |
223 | } |
|
269 | } | |
224 |
|
270 | |||
225 |
|
271 | |||
226 | void SocExplorerMainWindow::updateText() |
|
272 | void SocExplorerMainWindow::updateText() | |
227 | { |
|
273 | { | |
228 | emit this->translateSig(); |
|
274 | emit this->translateSig(); | |
229 | } |
|
275 | } | |
230 |
|
276 | |||
231 |
|
277 | |||
232 |
|
278 | |||
233 | void SocExplorerMainWindow::showAboutBox() |
|
279 | void SocExplorerMainWindow::showAboutBox() | |
234 | { |
|
280 | { | |
235 | p_about->show(); |
|
281 | p_about->show(); | |
236 | } |
|
282 | } | |
237 |
|
283 | |||
238 | void SocExplorerMainWindow::pluginselected(const QString &instanceName) |
|
284 | void SocExplorerMainWindow::pluginselected(const QString &instanceName) | |
239 | { |
|
285 | { | |
240 | socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName); |
|
286 | socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName); | |
241 | if(drv) |
|
287 | if(drv) | |
242 | drv->raise(); |
|
288 | drv->raise(); | |
243 | } |
|
289 | } | |
244 |
|
290 | |||
|
291 | void SocExplorerMainWindow::setActiveSession(const QString &session) | |||
|
292 | { | |||
|
293 | if(!(p_currentSession.isNull() && session=="default")) | |||
|
294 | saveCurrentSession(); | |||
|
295 | socexplorerproxy::self()->close(); | |||
|
296 | this->p_currentSession = session; | |||
|
297 | sessionsActions_t* sact; | |||
|
298 | SocExplorerSettings::loadSession(session); | |||
|
299 | loadCurrentSession(); | |||
|
300 | foreach (sact, sessionsActions) | |||
|
301 | { | |||
|
302 | if(sact->text().compare(session)) | |||
|
303 | sact->setChecked(false); | |||
|
304 | else | |||
|
305 | sact->setChecked(true); | |||
|
306 | } | |||
|
307 | } | |||
|
308 | ||||
|
309 | void SocExplorerMainWindow::showSessionManager(bool) | |||
|
310 | { | |||
|
311 | this->p_SessionManagerDialog->show(); | |||
|
312 | } | |||
|
313 | ||||
245 |
|
314 | |||
246 |
|
315 | |||
247 | void SocExplorerMainWindow::closeEvent(QCloseEvent *event) |
|
316 | void SocExplorerMainWindow::closeEvent(QCloseEvent *event) | |
248 | { |
|
317 | { | |
|
318 | saveCurrentSession(); | |||
249 | socexplorerproxy::self()->close(); |
|
319 | socexplorerproxy::self()->close(); | |
250 | qApp->closeAllWindows(); |
|
320 | qApp->closeAllWindows(); | |
251 | event->accept(); |
|
321 | event->accept(); | |
252 | } |
|
322 | } | |
253 |
|
323 | |||
254 |
|
324 | |||
255 |
|
325 | |||
256 |
|
326 | |||
257 |
|
327 | |||
258 |
|
328 |
@@ -1,91 +1,116 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef MAINWINDOW_H |
|
22 | #ifndef MAINWINDOW_H | |
23 | #define MAINWINDOW_H |
|
23 | #define MAINWINDOW_H | |
24 |
|
24 | |||
25 | #include <QMainWindow> |
|
25 | #include <QMainWindow> | |
26 | #include <QApplication> |
|
26 | #include <QApplication> | |
27 | #include <QVBoxLayout> |
|
27 | #include <QVBoxLayout> | |
28 | #include <QIcon> |
|
28 | #include <QIcon> | |
29 | #include <QMenuBar> |
|
29 | #include <QMenuBar> | |
30 | #include <QMenu> |
|
30 | #include <QMenu> | |
31 | #include <QAction> |
|
31 | #include <QAction> | |
32 | #include <QDockWidget> |
|
32 | #include <QDockWidget> | |
33 | #include <QTranslator> |
|
33 | #include <QTranslator> | |
34 | #include <QSplitter> |
|
34 | #include <QSplitter> | |
35 | #include "dockablepluginmanager.h" |
|
35 | #include "dockablepluginmanager.h" | |
36 | #include <socexplorerproxy.h> |
|
36 | #include <socexplorerproxy.h> | |
37 | #include "PyWdgt/pythonconsole.h" |
|
37 | #include "PyWdgt/pythonconsole.h" | |
38 | #include "aboutsocexplorer.h" |
|
38 | #include "aboutsocexplorer.h" | |
39 | #include "toolbar.h" |
|
39 | #include "toolbar.h" | |
40 | #include "regsExplorer/regsexplorer.h" |
|
40 | #include "regsExplorer/regsexplorer.h" | |
41 | #include "socexplorergui.h" |
|
41 | #include "socexplorergui.h" | |
42 | #include "sessionmanagerdialog.h" |
|
42 | #include "sessionmanagerdialog.h" | |
|
43 | class sessionsActions_t: public QAction | |||
|
44 | { | |||
|
45 | Q_OBJECT | |||
|
46 | public: | |||
|
47 | sessionsActions_t(const QString &text, QObject* parent) | |||
|
48 | : QAction(text,parent) | |||
|
49 | { | |||
|
50 | connect(this,SIGNAL(triggered(bool)),this,SLOT(p_triggered(bool))); | |||
|
51 | } | |||
|
52 | signals: | |||
|
53 | void triggered(const QString & session); | |||
|
54 | private slots: | |||
|
55 | void p_triggered(bool checked = false) | |||
|
56 | { | |||
|
57 | Q_UNUSED(checked) | |||
|
58 | emit triggered(this->text()); | |||
|
59 | } | |||
|
60 | }; | |||
43 |
|
61 | |||
44 | class SocExplorerMainWindow : public QMainWindow |
|
62 | class SocExplorerMainWindow : public QMainWindow | |
45 | { |
|
63 | { | |
46 | Q_OBJECT |
|
64 | Q_OBJECT | |
47 |
|
65 | |||
|
66 | ||||
48 | public: |
|
67 | public: | |
49 | SocExplorerMainWindow(QString ScriptToEval,QWidget *parent = 0); |
|
68 | SocExplorerMainWindow(QString ScriptToEval,QWidget *parent = 0); | |
50 | ~SocExplorerMainWindow(); |
|
69 | ~SocExplorerMainWindow(); | |
51 | QAction* Quit,*LoadPlugin,*ManagePlugins,*help,*regsManager,*exploreRegs,*about,*translateAction,*sessionManagerAction; |
|
70 | QAction* Quit,*LoadPlugin,*ManagePlugins,*help,*regsManager,*exploreRegs,*about,*translateAction,*sessionManagerAction; | |
|
71 | QList<sessionsActions_t*> sessionsActions; | |||
52 | QActionGroup*langActionGrp; |
|
72 | QActionGroup*langActionGrp; | |
53 | QMenu* FileMenu,*SettingsMenu,*PluginsMenu,*ToolsMenu,*langMenu,*helpMenu,*SessionsMenu; |
|
73 | QMenu* FileMenu,*SettingsMenu,*PluginsMenu,*ToolsMenu,*langMenu,*helpMenu,*SessionsMenu; | |
54 | QTranslator* appTranslator; |
|
74 | QTranslator* appTranslator; | |
55 | void createLangMenu(); |
|
75 | void createLangMenu(); | |
56 | void closeEvent(QCloseEvent *event); |
|
76 | void closeEvent(QCloseEvent *event); | |
57 | toolBar* toolpane; |
|
77 | toolBar* toolpane; | |
58 |
|
78 | |||
59 |
|
79 | |||
60 | public slots: |
|
80 | public slots: | |
61 | void launchPluginManager(); |
|
81 | void launchPluginManager(); | |
62 | void addPluginInterface(QDockWidget* plugin); |
|
82 | void addPluginInterface(QDockWidget* plugin); | |
63 | void removePluginInterface(QDockWidget* plugin); |
|
83 | void removePluginInterface(QDockWidget* plugin); | |
64 | void clearMenu(); |
|
84 | void clearMenu(); | |
65 | void updateText(); |
|
85 | void updateText(); | |
66 | void setLangage(QAction* action); |
|
86 | void setLangage(QAction* action); | |
67 | void showAboutBox(); |
|
87 | void showAboutBox(); | |
68 | void pluginselected(const QString& instanceName); |
|
88 | void pluginselected(const QString& instanceName); | |
69 |
|
89 | void setActiveSession(const QString & session); | ||
|
90 | void showSessionManager(bool); | |||
70 | signals: |
|
91 | signals: | |
71 | void translateSig(); |
|
92 | void translateSig(); | |
72 | void registerObject(QObject* object,const QString& instanceName); |
|
93 | void registerObject(QObject* object,const QString& instanceName); | |
73 |
|
94 | |||
74 | private: |
|
95 | private: | |
75 | void makeObjects(QString ScriptToEval); |
|
96 | void makeObjects(QString ScriptToEval); | |
76 | void makeLayout(); |
|
97 | void makeLayout(); | |
77 | void makeConnections(); |
|
98 | void makeConnections(); | |
78 | void makeMenu(); |
|
99 | void makeMenu(); | |
79 | void loadSessions(); |
|
100 | void loadSessions(); | |
|
101 | void savePlugins(); | |||
|
102 | void saveCurrentSession(); | |||
|
103 | void loadCurrentSession(); | |||
80 | QMainWindow* pluginsDockContainer; |
|
104 | QMainWindow* pluginsDockContainer; | |
81 | QSplitter* mainWidget; |
|
105 | QSplitter* mainWidget; | |
82 | PythonConsole* PythonConsoleInst; |
|
106 | PythonConsole* PythonConsoleInst; | |
83 | dockablePluginManager* pluginManager; |
|
107 | dockablePluginManager* pluginManager; | |
84 | RegsExplorer* regExplorer; |
|
108 | RegsExplorer* regExplorer; | |
85 | aboutsocexplorer* p_about; |
|
109 | aboutsocexplorer* p_about; | |
86 | QList<QDockWidget*>* p_pluginGUIlist; |
|
110 | QList<QDockWidget*>* p_pluginGUIlist; | |
87 | QStringList p_Sessions; |
|
111 | QStringList p_Sessions; | |
|
112 | QString p_currentSession; | |||
88 | SessionManagerDialog* p_SessionManagerDialog; |
|
113 | SessionManagerDialog* p_SessionManagerDialog; | |
89 | }; |
|
114 | }; | |
90 |
|
115 | |||
91 | #endif // MAINWINDOW_H |
|
116 | #endif // MAINWINDOW_H |
@@ -1,143 +1,174 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "sessionmanagerdialog.h" |
|
22 | #include "sessionmanagerdialog.h" | |
23 | #include "ui_sessionmanagerdialog.h" |
|
23 | #include "ui_sessionmanagerdialog.h" | |
24 | #include <socexplorersettings.h> |
|
24 | #include <socexplorersettings.h> | |
25 | #include <socexplorerconfigkeys.h> |
|
25 | #include <socexplorerconfigkeys.h> | |
26 | #include <QInputDialog> |
|
26 | #include <QInputDialog> | |
27 | #include <QMessageBox> |
|
27 | #include <QMessageBox> | |
28 |
|
28 | |||
29 | SessionManagerDialog::SessionManagerDialog(QWidget *parent) : |
|
29 | SessionManagerDialog::SessionManagerDialog(QWidget *parent) : | |
30 | QDialog(parent), |
|
30 | QDialog(parent), | |
31 | ui(new Ui::SessionManagerDialog) |
|
31 | ui(new Ui::SessionManagerDialog) | |
32 | { |
|
32 | { | |
33 | ui->setupUi(this); |
|
33 | ui->setupUi(this); | |
34 | connect(this->ui->NewQPB,SIGNAL(clicked(bool)),this,SLOT(newSession())); |
|
34 | connect(this->ui->NewQPB,SIGNAL(clicked(bool)),this,SLOT(newSession())); | |
35 | connect(this->ui->DeleteQPB,SIGNAL(clicked(bool)),this,SLOT(deleteSession())); |
|
35 | connect(this->ui->DeleteQPB,SIGNAL(clicked(bool)),this,SLOT(deleteSession())); | |
|
36 | connect(this->ui->RenameQPB,SIGNAL(clicked(bool)),this,SLOT(renameSession())); | |||
|
37 | connect(this->ui->SwitchToQPB,SIGNAL(clicked(bool)),this,SLOT(switchSession())); | |||
36 | } |
|
38 | } | |
37 |
|
39 | |||
38 | SessionManagerDialog::~SessionManagerDialog() |
|
40 | SessionManagerDialog::~SessionManagerDialog() | |
39 | { |
|
41 | { | |
40 | delete ui; |
|
42 | delete ui; | |
41 | } |
|
43 | } | |
42 |
|
44 | |||
43 |
|
45 | |||
44 | QStringList SessionManagerDialog::getSessionsList() |
|
46 | QStringList SessionManagerDialog::getSessionsList() | |
45 | { |
|
47 | { | |
46 | QStringList result; |
|
48 | QStringList result; | |
47 | QList<QList<QVariant> > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME); |
|
49 | QList<QList<QVariant> > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME); | |
48 | for(int i=0;i<sessions.count();i++) |
|
50 | for(int i=0;i<sessions.count();i++) | |
49 | { |
|
51 | { | |
50 | if(sessions.at(i).count()>=1) |
|
52 | if(sessions.at(i).count()>=1) | |
51 | { |
|
53 | { | |
52 | result.append(sessions.at(i).at(0).toString()); |
|
54 | result.append(sessions.at(i).at(0).toString()); | |
53 | } |
|
55 | } | |
54 | } |
|
56 | } | |
55 | // May always return at least default session |
|
57 | // May always return at least default session | |
56 | if(result.count()==0) |
|
58 | if(result.count()==0) | |
57 | { |
|
59 | { | |
58 | result.append("default"); |
|
60 | result.append("default"); | |
59 | } |
|
61 | } | |
60 | return result; |
|
62 | return result; | |
61 | } |
|
63 | } | |
62 |
|
64 | |||
63 | void SessionManagerDialog::show() |
|
65 | void SessionManagerDialog::show() | |
64 | { |
|
66 | { | |
65 | QStringList sessions = getSessionsList(); |
|
67 | QStringList sessions = getSessionsList(); | |
|
68 | this->ui->listWidget->clear(); | |||
66 | this->ui->listWidget->addItems(sessions); |
|
69 | this->ui->listWidget->addItems(sessions); | |
67 | QDialog::show(); |
|
70 | QDialog::show(); | |
68 | } |
|
71 | } | |
69 |
|
72 | |||
70 | void SessionManagerDialog::newSession() |
|
73 | void SessionManagerDialog::newSession() | |
71 | { |
|
74 | { | |
72 | bool ok=true,exists=false; |
|
75 | bool ok=true,exists=false; | |
73 | QString text; |
|
76 | QString text; | |
74 | do |
|
77 | do | |
75 | { |
|
78 | { | |
76 |
text = QInputDialog::getText(this, tr(" |
|
79 | text = QInputDialog::getText(this, tr("SocExplorer Session Manager"), | |
77 | tr("Session name:"), QLineEdit::Normal, |
|
80 | tr("Session name:"), QLineEdit::Normal, | |
78 | "New Session", &ok); |
|
81 | "New Session", &ok); | |
79 | exists = sessionExists(text); |
|
82 | exists = sessionExists(text); | |
80 | if(exists && ok) |
|
83 | if(exists && ok) | |
81 | { |
|
84 | { | |
82 | QMessageBox::warning(this, tr("SocExplorer Session Manager"), |
|
85 | QMessageBox::warning(this, tr("SocExplorer Session Manager"), | |
83 | tr("The session ")+text+tr(" already exists."), |
|
86 | tr("The session ")+text+tr(" already exists."), | |
84 | QMessageBox::Ok); |
|
87 | QMessageBox::Ok); | |
85 | } |
|
88 | } | |
86 |
}while(ok && |
|
89 | }while(ok && (text.isEmpty() || exists)); | |
87 |
|
90 | |||
88 | if (ok && !text.isEmpty()) |
|
91 | if (ok && !text.isEmpty()) | |
89 | { |
|
92 | { | |
90 | this->newSession(text); |
|
93 | this->newSession(text); | |
91 | } |
|
94 | } | |
92 | } |
|
95 | } | |
93 |
|
96 | |||
94 | void SessionManagerDialog::newSession(QString session) |
|
97 | void SessionManagerDialog::newSession(QString session) | |
95 | { |
|
98 | { | |
96 | if (!session.isEmpty()) |
|
99 | if (!session.isEmpty()) | |
97 | { |
|
100 | { | |
98 | this->ui->listWidget->addItem(session); |
|
101 | this->ui->listWidget->addItem(session); | |
99 | updateSessionList(); |
|
102 | updateSessionList(); | |
100 | } |
|
103 | } | |
101 | } |
|
104 | } | |
102 |
|
105 | |||
103 | void SessionManagerDialog::renameSession() |
|
106 | void SessionManagerDialog::renameSession() | |
104 | { |
|
107 | { | |
|
108 | bool ok=true; | |||
|
109 | int exists=0; | |||
|
110 | QListWidgetItem* item = this->ui->listWidget->currentItem(); | |||
|
111 | QString text= item->text(); | |||
|
112 | do | |||
|
113 | { | |||
|
114 | text = QInputDialog::getText(this, tr("SocExplorer Session Manager"), | |||
|
115 | tr("New session name:"), QLineEdit::Normal, | |||
|
116 | text, &ok); | |||
|
117 | exists = sessionExists(text); | |||
|
118 | if(exists&& ok) | |||
|
119 | { | |||
|
120 | QMessageBox::warning(this, tr("SocExplorer Session Manager"), | |||
|
121 | tr("The session ")+text+tr(" already exists."), | |||
|
122 | QMessageBox::Ok); | |||
|
123 | } | |||
|
124 | }while(ok && text.isEmpty()); | |||
105 |
|
125 | |||
|
126 | if (ok && !text.isEmpty()) | |||
|
127 | { | |||
|
128 | item->setText(text); | |||
|
129 | } | |||
106 | } |
|
130 | } | |
107 |
|
131 | |||
108 | void SessionManagerDialog::deleteSession() |
|
132 | void SessionManagerDialog::deleteSession() | |
109 | { |
|
133 | { | |
110 | if(this->ui->listWidget->selectedItems().count()) |
|
134 | if(this->ui->listWidget->selectedItems().count()) | |
111 | { |
|
135 | { | |
112 | QListWidgetItem* item = this->ui->listWidget->currentItem(); |
|
136 | QListWidgetItem* item = this->ui->listWidget->currentItem(); | |
113 | if(item && item->text().compare("default")) |
|
137 | if(item && item->text().compare("default")) | |
114 | { |
|
138 | { | |
115 | this->ui->listWidget->removeItemWidget(item); |
|
139 | this->ui->listWidget->removeItemWidget(item); | |
116 | //TODO delete session FILE! |
|
140 | SocExplorerSettings::deleteSession(item->text()); | |
117 | delete item; |
|
141 | delete item; | |
118 | updateSessionList(); |
|
142 | updateSessionList(); | |
119 | } |
|
143 | } | |
120 | } |
|
144 | } | |
121 | } |
|
145 | } | |
122 |
|
146 | |||
123 |
|
|
147 | void SessionManagerDialog::switchSession() | |
124 | { |
|
148 | { | |
125 | bool diff=true; |
|
149 | QListWidgetItem* item = this->ui->listWidget->currentItem(); | |
|
150 | if(item) | |||
|
151 | emit switchSession(item->text()); | |||
|
152 | } | |||
|
153 | ||||
|
154 | int SessionManagerDialog::sessionExists(QString session) | |||
|
155 | { | |||
|
156 | int exists=0; | |||
126 | for(int i=0;i< this->ui->listWidget->count();i++) |
|
157 | for(int i=0;i< this->ui->listWidget->count();i++) | |
127 | { |
|
158 | { | |
128 |
|
|
159 | exists += (this->ui->listWidget->item(i)->text().compare(session)==0); | |
129 | } |
|
160 | } | |
130 |
return |
|
161 | return exists; | |
131 | } |
|
162 | } | |
132 |
|
163 | |||
133 | void SessionManagerDialog::updateSessionList() |
|
164 | void SessionManagerDialog::updateSessionList() | |
134 | { |
|
165 | { | |
135 | QList<QList<QVariant> > sessions; |
|
166 | QList<QList<QVariant> > sessions; | |
136 | for(int i=0;i< this->ui->listWidget->count();i++) |
|
167 | for(int i=0;i< this->ui->listWidget->count();i++) | |
137 | { |
|
168 | { | |
138 | QList<QVariant> sess; |
|
169 | QList<QVariant> sess; | |
139 | sess.append(this->ui->listWidget->item(i)->text()); |
|
170 | sess.append(this->ui->listWidget->item(i)->text()); | |
140 | sessions.append(sess); |
|
171 | sessions.append(sess); | |
141 | } |
|
172 | } | |
142 | SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME,sessions); |
|
173 | SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME,sessions); | |
143 | } |
|
174 | } |
@@ -1,53 +1,57 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef SESSIONMANAGERDIALOG_H |
|
22 | #ifndef SESSIONMANAGERDIALOG_H | |
23 | #define SESSIONMANAGERDIALOG_H |
|
23 | #define SESSIONMANAGERDIALOG_H | |
24 |
|
24 | |||
25 | #include <QDialog> |
|
25 | #include <QDialog> | |
26 |
|
26 | |||
27 | namespace Ui { |
|
27 | namespace Ui { | |
28 | class SessionManagerDialog; |
|
28 | class SessionManagerDialog; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | class SessionManagerDialog : public QDialog |
|
31 | class SessionManagerDialog : public QDialog | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | explicit SessionManagerDialog(QWidget *parent = 0); |
|
36 | explicit SessionManagerDialog(QWidget *parent = 0); | |
37 | ~SessionManagerDialog(); |
|
37 | ~SessionManagerDialog(); | |
38 |
|
38 | |||
39 | QStringList getSessionsList(); |
|
39 | QStringList getSessionsList(); | |
40 | public slots: |
|
40 | public slots: | |
41 | void show(); |
|
41 | void show(); | |
|
42 | void newSession(QString session); | |||
|
43 | int sessionExists(QString session); | |||
|
44 | private slots: | |||
42 | void newSession(); |
|
45 | void newSession(); | |
43 | void newSession(QString session); |
|
|||
44 | void renameSession(); |
|
46 | void renameSession(); | |
45 | void deleteSession(); |
|
47 | void deleteSession(); | |
46 | bool sessionExists(QString session); |
|
48 | void switchSession(); | |
|
49 | signals: | |||
|
50 | void switchSession(QString session); | |||
47 |
|
51 | |||
48 | private: |
|
52 | private: | |
49 | void updateSessionList(); |
|
53 | void updateSessionList(); | |
50 | Ui::SessionManagerDialog *ui; |
|
54 | Ui::SessionManagerDialog *ui; | |
51 | }; |
|
55 | }; | |
52 |
|
56 | |||
53 | #endif // SESSIONMANAGERDIALOG_H |
|
57 | #endif // SESSIONMANAGERDIALOG_H |
@@ -1,121 +1,121 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>SessionManagerDialog</class> |
|
3 | <class>SessionManagerDialog</class> | |
4 | <widget class="QDialog" name="SessionManagerDialog"> |
|
4 | <widget class="QDialog" name="SessionManagerDialog"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>553</width> |
|
9 | <width>553</width> | |
10 | <height>275</height> |
|
10 | <height>275</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="windowTitle"> |
|
13 | <property name="windowTitle"> | |
14 |
<string> |
|
14 | <string>SocExplorer Session Manager</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QGridLayout" name="gridLayout"> |
|
16 | <layout class="QGridLayout" name="gridLayout"> | |
17 | <item row="0" column="0"> |
|
17 | <item row="0" column="0"> | |
18 | <widget class="QListWidget" name="listWidget"/> |
|
18 | <widget class="QListWidget" name="listWidget"/> | |
19 | </item> |
|
19 | </item> | |
20 | <item row="0" column="1"> |
|
20 | <item row="0" column="1"> | |
21 | <widget class="QWidget" name="widget" native="true"> |
|
21 | <widget class="QWidget" name="widget" native="true"> | |
22 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
22 | <layout class="QVBoxLayout" name="verticalLayout"> | |
23 | <item> |
|
23 | <item> | |
24 | <widget class="QPushButton" name="NewQPB"> |
|
24 | <widget class="QPushButton" name="NewQPB"> | |
25 | <property name="text"> |
|
25 | <property name="text"> | |
26 | <string>New</string> |
|
26 | <string>New</string> | |
27 | </property> |
|
27 | </property> | |
28 | </widget> |
|
28 | </widget> | |
29 | </item> |
|
29 | </item> | |
30 | <item> |
|
30 | <item> | |
31 | <widget class="QPushButton" name="RenameQPB"> |
|
31 | <widget class="QPushButton" name="RenameQPB"> | |
32 | <property name="text"> |
|
32 | <property name="text"> | |
33 | <string>Rename</string> |
|
33 | <string>Rename</string> | |
34 | </property> |
|
34 | </property> | |
35 | </widget> |
|
35 | </widget> | |
36 | </item> |
|
36 | </item> | |
37 | <item> |
|
37 | <item> | |
38 | <widget class="QPushButton" name="CloneQPB"> |
|
38 | <widget class="QPushButton" name="CloneQPB"> | |
39 | <property name="text"> |
|
39 | <property name="text"> | |
40 | <string>Clone</string> |
|
40 | <string>Clone</string> | |
41 | </property> |
|
41 | </property> | |
42 | </widget> |
|
42 | </widget> | |
43 | </item> |
|
43 | </item> | |
44 | <item> |
|
44 | <item> | |
45 | <widget class="QPushButton" name="DeleteQPB"> |
|
45 | <widget class="QPushButton" name="DeleteQPB"> | |
46 | <property name="text"> |
|
46 | <property name="text"> | |
47 | <string>Delete</string> |
|
47 | <string>Delete</string> | |
48 | </property> |
|
48 | </property> | |
49 | </widget> |
|
49 | </widget> | |
50 | </item> |
|
50 | </item> | |
51 | <item> |
|
51 | <item> | |
52 | <widget class="QPushButton" name="SwitchToQPB"> |
|
52 | <widget class="QPushButton" name="SwitchToQPB"> | |
53 | <property name="text"> |
|
53 | <property name="text"> | |
54 | <string>Switch to</string> |
|
54 | <string>Switch to</string> | |
55 | </property> |
|
55 | </property> | |
56 | </widget> |
|
56 | </widget> | |
57 | </item> |
|
57 | </item> | |
58 | <item> |
|
58 | <item> | |
59 | <spacer name="verticalSpacer"> |
|
59 | <spacer name="verticalSpacer"> | |
60 | <property name="orientation"> |
|
60 | <property name="orientation"> | |
61 | <enum>Qt::Vertical</enum> |
|
61 | <enum>Qt::Vertical</enum> | |
62 | </property> |
|
62 | </property> | |
63 | <property name="sizeHint" stdset="0"> |
|
63 | <property name="sizeHint" stdset="0"> | |
64 | <size> |
|
64 | <size> | |
65 | <width>20</width> |
|
65 | <width>20</width> | |
66 | <height>40</height> |
|
66 | <height>40</height> | |
67 | </size> |
|
67 | </size> | |
68 | </property> |
|
68 | </property> | |
69 | </spacer> |
|
69 | </spacer> | |
70 | </item> |
|
70 | </item> | |
71 | </layout> |
|
71 | </layout> | |
72 | </widget> |
|
72 | </widget> | |
73 | </item> |
|
73 | </item> | |
74 | <item row="1" column="0" colspan="2"> |
|
74 | <item row="1" column="0" colspan="2"> | |
75 | <widget class="QDialogButtonBox" name="buttonBox"> |
|
75 | <widget class="QDialogButtonBox" name="buttonBox"> | |
76 | <property name="orientation"> |
|
76 | <property name="orientation"> | |
77 | <enum>Qt::Horizontal</enum> |
|
77 | <enum>Qt::Horizontal</enum> | |
78 | </property> |
|
78 | </property> | |
79 | <property name="standardButtons"> |
|
79 | <property name="standardButtons"> | |
80 | <set>QDialogButtonBox::Close</set> |
|
80 | <set>QDialogButtonBox::Close</set> | |
81 | </property> |
|
81 | </property> | |
82 | </widget> |
|
82 | </widget> | |
83 | </item> |
|
83 | </item> | |
84 | </layout> |
|
84 | </layout> | |
85 | </widget> |
|
85 | </widget> | |
86 | <resources/> |
|
86 | <resources/> | |
87 | <connections> |
|
87 | <connections> | |
88 | <connection> |
|
88 | <connection> | |
89 | <sender>buttonBox</sender> |
|
89 | <sender>buttonBox</sender> | |
90 | <signal>accepted()</signal> |
|
90 | <signal>accepted()</signal> | |
91 | <receiver>SessionManagerDialog</receiver> |
|
91 | <receiver>SessionManagerDialog</receiver> | |
92 | <slot>accept()</slot> |
|
92 | <slot>accept()</slot> | |
93 | <hints> |
|
93 | <hints> | |
94 | <hint type="sourcelabel"> |
|
94 | <hint type="sourcelabel"> | |
95 | <x>248</x> |
|
95 | <x>248</x> | |
96 | <y>254</y> |
|
96 | <y>254</y> | |
97 | </hint> |
|
97 | </hint> | |
98 | <hint type="destinationlabel"> |
|
98 | <hint type="destinationlabel"> | |
99 | <x>157</x> |
|
99 | <x>157</x> | |
100 | <y>274</y> |
|
100 | <y>274</y> | |
101 | </hint> |
|
101 | </hint> | |
102 | </hints> |
|
102 | </hints> | |
103 | </connection> |
|
103 | </connection> | |
104 | <connection> |
|
104 | <connection> | |
105 | <sender>buttonBox</sender> |
|
105 | <sender>buttonBox</sender> | |
106 | <signal>rejected()</signal> |
|
106 | <signal>rejected()</signal> | |
107 | <receiver>SessionManagerDialog</receiver> |
|
107 | <receiver>SessionManagerDialog</receiver> | |
108 | <slot>reject()</slot> |
|
108 | <slot>reject()</slot> | |
109 | <hints> |
|
109 | <hints> | |
110 | <hint type="sourcelabel"> |
|
110 | <hint type="sourcelabel"> | |
111 | <x>316</x> |
|
111 | <x>316</x> | |
112 | <y>260</y> |
|
112 | <y>260</y> | |
113 | </hint> |
|
113 | </hint> | |
114 | <hint type="destinationlabel"> |
|
114 | <hint type="destinationlabel"> | |
115 | <x>286</x> |
|
115 | <x>286</x> | |
116 | <y>274</y> |
|
116 | <y>274</y> | |
117 | </hint> |
|
117 | </hint> | |
118 | </hints> |
|
118 | </hints> | |
119 | </connection> |
|
119 | </connection> | |
120 | </connections> |
|
120 | </connections> | |
121 | </ui> |
|
121 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now