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