##// END OF EJS Templates
Sync
Jeandet Alexis -
r95:083d612a5a2d default
parent child
Show More
@@ -1,301 +1,321
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::renameSession(const QString &session, const QString &newName)
201 {
202 INIT();
203 sync();
204 QFileInfo sessionInfo(m_settings->fileName());
205 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
206 QString newFullpath=sessionInfo.absoluteDir().absolutePath() +"/"+newName+".conf";
207 if(m_sessionSettings && m_sessionSettings->fileName()==fullpath)
208 {
209 delete m_sessionSettings;
210 QFile::rename(fullpath,newFullpath);
211 m_sessionSettings = new QSettings(newFullpath,QSettings::NativeFormat,self());
212 }
213 else
214 {
215 QFile::rename(fullpath,newFullpath);
216 }
217 return true;
218 }
219
200 220 bool SocExplorerSettings::deleteSession()
201 221 {
202 222 INIT();
203 223 if(m_sessionSettings)
204 224 {
205 225 m_sessionSettings->clear();
206 226 QString filename= m_sessionSettings->fileName();
207 227 if(QFile::exists(filename))
208 228 {
209 229 delete m_sessionSettings;
210 230 QFile::remove(filename);
211 231 }
212 232 else
213 233 delete m_sessionSettings;
214 234 m_sessionSettings = NULL;
215 235 return true;
216 236 }
217 237 return false;
218 238 }
219 239
220 240 bool SocExplorerSettings::deleteSession(const QString &session)
221 241 {
222 242 QFileInfo sessionInfo(m_settings->fileName());
223 243 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
224 244 if(m_sessionSettings)
225 245 {
226 246 if(m_sessionSettings->fileName()==fullpath)
227 247 {
228 248 deleteSession();
229 249 return true;
230 250 }
231 251 }
232 252 QSettings* sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self());
233 253 if(sessionSettings)
234 254 {
235 255 if(sessionSettings->status()==QSettings::NoError)
236 256 {
237 257 sessionSettings->clear();
238 258 QString filename= m_sessionSettings->fileName();
239 259 if(QFile::exists(filename))
240 260 {
241 261 delete sessionSettings;
242 262 QFile::remove(filename);
243 263 }
244 264 else
245 265 delete sessionSettings;
246 266 return true;
247 267 }
248 268 delete sessionSettings;
249 269 }
250 270 return false;
251 271 }
252 272
253 273 void SocExplorerSettings::popConfigDialog()
254 274 {
255 275 m_configDialog->popConfigDialog(NULL);
256 276 }
257 277
258 278 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, QSettings *settings)
259 279 {
260 280 QList<QList<QVariant> > result;
261 281 if(settings)
262 282 {
263 283 int size = settings->beginReadArray(prefix);
264 284 for (int i = 0; i < size; ++i)
265 285 {
266 286 result.append(QList<QVariant>());
267 287 settings->setArrayIndex(i);
268 288 for(int l=0;l<keys.count();l++)
269 289 {
270 290 result[i].append(settings->value(keys.at(l)));
271 291 }
272 292 }
273 293 settings->endArray();
274 294 }
275 295 return result;
276 296 }
277 297
278 298 void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, QSettings *settings)
279 299 {
280 300 if(settings)
281 301 {
282 302 QString key;
283 303 foreach (key, keys)
284 304 {
285 305
286 306 settings->remove(prefix+"/"+key);
287 307 }
288 308 settings->beginWriteArray(prefix);
289 309 for (int i = 0; i < values.size(); ++i)
290 310 {
291 311 settings->setArrayIndex(i);
292 312 for(int l=0;l<keys.count();l++)
293 313 {
294 314 settings->setValue(keys[l], values.at(i).at(l));
295 315 }
296 316 }
297 317 settings->endArray();
298 318
299 319 }
300 320 }
301 321
@@ -1,70 +1,71
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 renameSession(const QString& session,const QString& newName);
59 60 static bool deleteSession();
60 61 static bool deleteSession(const QString& session);
61 62 signals:
62 63
63 64 public slots:
64 65 void popConfigDialog();
65 66 private:
66 67 static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,QSettings* settings);
67 68 static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,QSettings* settings);
68 69 };
69 70
70 71 #endif // SOCEXPLORERSETTINGS_H
@@ -1,264 +1,265
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, 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
23 23 #include <socexplorerplugin.h>
24 24 #include <abstractbinfile.h>
25 25 #include <srec/srecfile.h>
26 26 #include <BinFile/binaryfile.h>
27 27
28 28 int socexplorerplugin::isConnected(){return this->Connected;}
29 29
30 30 QString socexplorerplugin::baseName(){return *_Name;}
31 31
32 32 int socexplorerplugin::baseAddress(){return this->BaseAddress;}
33 33
34 34 void socexplorerplugin::setBaseAddress(unsigned int baseAddress){this->BaseAddress = baseAddress;}
35 35
36 36 QString socexplorerplugin::instanceName()
37 37 {
38 38 return this->_instanceName;
39 39 }
40 40
41 41 int socexplorerplugin::registermenu(QMenu *menu)
42 42 {
43 43 this->menu = menu->addMenu(this->_instanceName);
44 44 this->closeAction = this->menu->addAction(tr("Close plugin"));
45 45 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
46 46 this->ChildsMenu = this->menu->addMenu(QString("Childs"));
47 47 for(int i=0;i<this->childs.count();i++)
48 48 {
49 49 this->childs.at(i)->registermenu(this->ChildsMenu);
50 50 }
51 51 emit this->registerObject((QObject*)this,this->instanceName());
52 52 return 0;
53 53 }
54 54
55 55 void socexplorerplugin::postInstantiationTrigger()
56 56 {
57 57 return;
58 58 }
59 59
60 60 unsigned int socexplorerplugin::Write(unsigned int *Value, unsigned int count, unsigned int address)
61 61 {
62 62 if(parent!=NULL)
63 63 {
64 64 return parent->Write(Value,count,address);
65 65 }
66 66 return 0;
67 67 }
68 68
69 69 unsigned int socexplorerplugin::Read(unsigned int *Value, unsigned int count, unsigned int address)
70 70 {
71 71 if(parent!=NULL)
72 72 {
73 73 return parent->Read(Value,count,address);
74 74 }
75 75 return 0;
76 76 }
77 77
78 78 QVariantList socexplorerplugin::Read(unsigned int address,unsigned int count)
79 79 {
80 80 unsigned int data[count];
81 81 QVariantList result;
82 82 Read(data,count,address);
83 83 for(unsigned int i = 0;i<count;i++)
84 84 {
85 85 result.append(QVariant((int)data[i]));
86 86 }
87 87 return result;
88 88 }
89 89 void socexplorerplugin::Write(unsigned int address,QList<QVariant> dataList)
90 90 {
91 91 unsigned int data[dataList.count()];
92 92 for(int i = 0;i<dataList.count();i++)
93 93 {
94 94 data[i] = (unsigned int)dataList.at(i).toUInt();
95 95 }
96 96 Write(data,dataList.count(),address);
97 97 }
98 98
99 99
100 100
101 101 void socexplorerplugin::closeMe(){emit this->closePlugin(this);}
102 102
103 103 void socexplorerplugin::activate(bool flag){this->setEnabled(flag);emit this->activateSig(flag);}
104 104
105 105 void socexplorerplugin::setInstanceName(const QString &newName)
106 106 {
107 107 this->_instanceName = newName;
108 108 if(this->menu)
109 109 this->menu->setTitle(this->_instanceName);
110 110 this->setWindowTitle(newName);
111 this->setObjectName(newName);
111 112 }
112 113
113 114 bool socexplorerplugin::dumpMemory(unsigned int address, unsigned int count, QString file)
114 115 {
115 116 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
116 117 if(buffer!=NULL)
117 118 {
118 119 this->Read(buffer,count,address);
119 120 QFile outfile(file);
120 121 if (!outfile.open(QIODevice::ReadWrite | QIODevice::Text))
121 122 return false;
122 123 QTextStream out(&outfile);
123 124 for(int i=0;(unsigned int)i<count;i++)
124 125 out << "0x"+QString::number(address+(i*4),16) + ": 0x" + QString::number(buffer[i],16) + "\n";
125 126 free(buffer);
126 127 out.flush();
127 128 outfile.close();
128 129 return true;
129 130 }
130 131 return false;
131 132 }
132 133
133 134 bool socexplorerplugin::memSet(unsigned int address, int value, unsigned int count)
134 135 {
135 136 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
136 137 if(buffer!=NULL)
137 138 {
138 139 memset((void*)buffer,value,count*sizeof(unsigned int));
139 140 this->Write(buffer,count,address);
140 141 free(buffer );
141 142 return true;
142 143 }
143 144 return false;
144 145 }
145 146
146 147 bool socexplorerplugin::loadbin(unsigned int address, QString file)
147 148 {
148 149 QFile infile(file);
149 150 if (!infile.open(QIODevice::ReadOnly))
150 151 return false;
151 152 uint32_t* buffer = (uint32_t*)malloc(infile.size());
152 153 if(buffer!=NULL)
153 154 {
154 155 infile.read((char*)buffer,infile.size());
155 156 for(int i=0;i<(infile.size()/4);i++)
156 157 {
157 158 buffer[i] = socexplorerBswap32(buffer[i]);
158 159 }
159 160 this->Write(buffer,infile.size()/4,address);
160 161 free(buffer);
161 162 return true;
162 163 }
163 164 return false;
164 165
165 166 }
166 167
167 168 bool socexplorerplugin::loadfile(abstractBinFile *file)
168 169 {
169 170 if(file->isopened())
170 171 {
171 172 QList<codeFragment*> fragments= file->getFragments();
172 173 for(int i=0;i<fragments.count();i++)
173 174 {
174 175 int size = fragments.at(i)->size/4;
175 176 // TODO fixme, should be the oposite
176 177 #if __BYTE_ORDER == __LITTLE_ENDIAN
177 178 if(!file->litleendian)
178 179 {
179 180 uint32_t* buffer = (uint32_t*)malloc(fragments.at(i)->size);
180 181 memcpy(buffer,fragments.at(i)->data,fragments.at(i)->size);
181 182 if(buffer!=NULL)
182 183 {
183 184 for(int l=0;l<(size);l++)
184 185 {
185 186 buffer[l] = socexplorerBswap32(buffer[l]);
186 187 }
187 188 this->Write(buffer,size,fragments.at(i)->address);
188 189 free(buffer);
189 190 }
190 191 }
191 192 else
192 193 {
193 194 this->Write((uint32_t*) fragments.at(i)->data,size,fragments.at(i)->address);
194 195 }
195 196 #elif __BYTE_ORDER == __BIG_ENDIAN
196 197 if(file->litleendian)
197 198 {
198 199 uint32_t* buffer = (uint32_t*)malloc(fragments.at(i)->size);
199 200 memcpy(buffer,fragments.at(i)->data,fragments.at(i)->size);
200 201 if(buffer!=NULL)
201 202 {
202 203 for(int l=0;l<(size);l++)
203 204 {
204 205 buffer[l] = socexplorerBswap32(buffer[l]);
205 206 }
206 207 this->Write(buffer,size,fragments.at(i)->address);
207 208 free(buffer);
208 209 }
209 210 }
210 211 else
211 212 {
212 213 this->Write((uint32_t*) fragments.at(i)->data,size,fragments.at(i)->address);
213 214 }
214 215 #endif
215 216 }
216 217 }
217 218 return true;
218 219 }
219 220
220 221 bool socexplorerplugin::dumpMemory(unsigned int address, unsigned int count, QString file, const QString &format)
221 222 {
222 223 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
223 224 if(buffer!=NULL)
224 225 {
225 226 this->Read(buffer,count,address);
226 227 if(!format.compare("srec",Qt::CaseInsensitive))
227 228 {
228 229 //need to convert from in memory endianness to file endianness
229 230 //SREC is always big endian
230 231 #if __BYTE_ORDER == __LITTLE_ENDIAN
231 232 for(int l=0;l<(count);l++)
232 233 {
233 234 buffer[l] = socexplorerBswap32(buffer[l]);
234 235 }
235 236 #elif __BYTE_ORDER == __BIG_ENDIAN
236 237
237 238 #endif
238 239 codeFragment fragment((char*)buffer,count*4,address);
239 240 srecFile::toSrec(QList<codeFragment*>()<<&fragment,file);
240 241 }
241 242 if(!format.compare("bin",Qt::CaseInsensitive))
242 243 {
243 244 //beware this format is not portable from a big endian host to a litle endian one
244 245 codeFragment fragment((char*)buffer,count*4,address);
245 246 binaryFile::toBinary(QList<codeFragment*>()<<&fragment,file);
246 247 }
247 248 if(!format.compare("hexa",Qt::CaseInsensitive))
248 249 {
249 250 QFile outfile(file);
250 251 if (!outfile.open(QIODevice::ReadWrite | QIODevice::Text))
251 252 return false;
252 253 QTextStream out(&outfile);
253 254 for(int i=0;(unsigned int)i<count;i++)
254 255 out << "0x"+QString::number(address+(i*4),16) + ": 0x" + QString::number(buffer[i],16) + "\n";
255 256 free(buffer);
256 257 out.flush();
257 258 outfile.close();
258 259 }
259 260 return true;
260 261 }
261 262 return false;
262 263 }
263 264
264 265
@@ -1,328 +1,339
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 37 this->makeConnections();
38 38 this->setWindowIcon(QIcon(":/images/icon.png"));
39 39 this->setAcceptDrops(true);
40 40 this->pluginManager->setRootLoadable(true);
41 41 this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval);
42 42 QFile file(":/styles/SocExplorer.css");
43 43 if(file.open(QIODevice::ReadOnly | QIODevice::Text))
44 44 {
45 45 qApp->setStyleSheet(file.readAll());
46 46 file.close();
47 47 }
48 48 }
49 49
50 50
51 51 void SocExplorerMainWindow::makeObjects(QString ScriptToEval)
52 52 {
53 53 Q_UNUSED(ScriptToEval)
54 54 this->p_pluginGUIlist = new QList<QDockWidget*>();
55 55 pluginsDockContainer = new QMainWindow;
56 56 pluginsDockContainer->setObjectName("pluginsDockContainer");
57 57 pluginsDockContainer->setWindowFlags(Qt::Widget);
58 58 pluginsDockContainer->setDockNestingEnabled(true);
59 this->sessionsActions = new QActionGroup(this);
60 this->sessionManagerAction =new QAction(tr("&Session manager"),this);
59 61 this->mainWidget = new QSplitter(Qt::Vertical);
60 62 this->appTranslator = new QTranslator;
61 63 this->Quit = new QAction(tr("&Quit"),this);
62 64 this->Quit->setShortcut(tr("CTRL+Q"));
63 65 this->ManagePlugins = new QAction(tr("&Manage Plugins"),this);
64 66 this->ManagePlugins->setShortcut(tr("CTRL+P"));
65 67 this->regsManager = new QAction(tr("&Manage registers"),this);
66 68 this->exploreRegs = new QAction(tr("&Explore registers"),this);
67 69 this->help = new QAction(tr("&Help"),this);
68 70 this->help->setShortcut(tr("CTRL+H"));
69 71 this->about = new QAction(tr("&About"),this);
70 72 this->p_SessionManagerDialog = new SessionManagerDialog();
71 73 socexplorerproxy::setMainWindow(this);
72 74 SocExplorerEngine::setMainWindow(this);
73 75 SocExplorerEngine::xmlModel()->scanXmlFiles();
74 76 this->regExplorer = new RegsExplorer();
75 77 this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas);
76 78 this->regExplorer->setObjectName("regExplorer");
77 79 this->addPluginInterface(this->regExplorer);
78 80 this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self());
79 81 this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self());
80 82 this->pluginManager = new dockablePluginManager();
81 83 this->toolpane = new toolBar;
82 84 this->toolpane->setObjectName("toolpane");
83 85 this->p_about = new aboutsocexplorer();
84 86 }
85 87
86 88 void SocExplorerMainWindow::makeLayout()
87 89 {
88 90 this->mainWidget->addWidget(pluginsDockContainer);
89 91 this->mainWidget->addWidget(this->PythonConsoleInst);
90 92 this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
91 93 this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane);
92 94 this->toolpane->addTool(this->pluginManager);
93 95 this->setCentralWidget(this->mainWidget);
94 96 }
95 97
96 98
97 99 void SocExplorerMainWindow::makeConnections()
98 100 {
99 101 connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu()));
100 102 connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText()));
101 103 connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*)));
102 104 connect(socexplorerproxy::self(),SIGNAL(removePluginGUI(QDockWidget*)),this,SLOT(removePluginInterface(QDockWidget*)));
103 105 connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager()));
104 106 connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit()));
105 107 connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString)));
106 108 connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString)));
107 109 connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree()));
108 110 connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
109 111 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString)));
110 112 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString)));
111 113 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString)));
112 114 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString)));
113 115 connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString)));
114 116 connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox()));
115 117 connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show()));
116 118
117 119 connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this,SLOT(showSessionManager(bool)));
118 120 connect(this->p_SessionManagerDialog, SIGNAL(switchSession(QString)),this,SLOT(setActiveSession(QString)));
121 connect(this->sessionsActions,SIGNAL(triggered(QAction*)),this,SLOT(setActiveSession(QAction*)));
119 122
120 123 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString)));
121 124 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString)));
122 125
123 126 }
124 127
125 128
126 129 void SocExplorerMainWindow::launchPluginManager()
127 130 {
128 131 if(this->pluginManager->isHidden())
129 132 {
130 133 this->pluginManager->setHidden(false);
131 134 }
132 135 }
133 136
134 137
135 138 void SocExplorerMainWindow::addPluginInterface(QDockWidget *plugin)
136 139 {
137 140 plugin->setAllowedAreas(Qt::AllDockWidgetAreas);
138 141 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin);
139 142 if(p_pluginGUIlist->count()!=0)
140 143 this->pluginsDockContainer->tabifyDockWidget(p_pluginGUIlist->last(),plugin);
141 144 p_pluginGUIlist->append(plugin);
142 145 }
143 146
144 147 void SocExplorerMainWindow::removePluginInterface(QDockWidget *plugin)
145 148 {
146 149 p_pluginGUIlist->removeOne(plugin);
147 150 this->pluginsDockContainer->removeDockWidget(plugin);
148 151 }
149 152
150 153
151 154 void SocExplorerMainWindow::clearMenu()
152 155 {
153 156 this->menuBar()->clear();
154 157 this->makeMenu();
155 158 }
156 159
157 160
158 161 void SocExplorerMainWindow::makeMenu()
159 162 {
160 163 this->FileMenu = menuBar()->addMenu(tr("&File"));
161 164 this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions"));
162 165 this->loadSessions();
163 this->sessionManagerAction = this->FileMenu->addAction(tr("&Session manager..."));
166 this->FileMenu->addAction(this->sessionManagerAction);
164 167 this->SettingsMenu = menuBar()->addMenu(tr("&Settings"));
165 168 SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu);
166 169 this->PluginsMenu = menuBar()->addMenu(tr("&Plugins"));
167 170 this->ToolsMenu = menuBar()->addMenu(tr("&Tools"));
168 171 this->ToolsMenu->addAction(this->exploreRegs);
169 172 this->FileMenu->addAction(this->Quit);
170 173 socexplorerproxy::self()->makeMenu(this->PluginsMenu);
171 174 this->PluginsMenu->addAction(this->ManagePlugins);
172 175
173 176 this->helpMenu = menuBar()->addMenu(tr("Help"));
174 177 this->helpMenu->addAction(this->help);
175 178 this->helpMenu->addAction(this->about);
176 179
177 180 }
178 181
179 182 void SocExplorerMainWindow::loadSessions()
180 183 {
181 184 p_Sessions=this->p_SessionManagerDialog->getSessionsList();
182 sessionsActions_t* sact;
185 QAction* sact;
183 186 QString stext;
184 foreach (sact, sessionsActions)
187 QList<QAction*> sessions=sessionsActions->actions();
188 foreach (sact, sessions)
185 189 {
186 sessionsActions.removeAll(sact);
190 sessionsActions->removeAction(sact);
187 191 SessionsMenu->removeAction(sact);
188 disconnect(sact);
189 192 delete sact;
190 193 }
191 194 foreach (stext, p_Sessions)
192 195 {
193 sact = new sessionsActions_t(stext,this);
196 sact = new QAction(stext,this);
194 197 sact->setCheckable(true);
195 connect(sact,SIGNAL(triggered(QString)),this,SLOT(setActiveSession(QString)));
196 sessionsActions.append(sact);
198 sact->setData(stext);
199 if(p_currentSession==stext)
200 sact->setChecked(true);
201 sessionsActions->addAction(sact);
197 202 SessionsMenu->addAction(sact);
198 203 }
199 204 }
200 205
201 206 void SocExplorerMainWindow::savePlugins()
202 207 {
203 208
204 209 }
205 210
206 211 void SocExplorerMainWindow::saveCurrentSession()
207 212 {
208 213 if(p_currentSession.isEmpty())
209 214 {
210 215 SocExplorerSettings::loadSession("default");
211 216 }
212 217 SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session);
213 218 SocExplorerSettings::setValue(this,"DOCK_LOCATIONS",this->saveState(0),SocExplorerSettings::Session);
219 SocExplorerSettings::setValue(this,"PLUGINS_DOCK_LOCATIONS",this->pluginsDockContainer->saveState(0),SocExplorerSettings::Session);
214 220 SocExplorerSettings::setValue(this,"MAIN_WINDOW_GEOMETRY",this->saveGeometry(),SocExplorerSettings::Session);
215 221 QStringList plugins = socexplorerproxy::getPluginsList();
216 222 SocExplorerSettings::setValue(this,"LOADED_PLUGINS",QVariant(plugins),SocExplorerSettings::Session);
217 223 SocExplorerSettings::sync();
218 224 }
219 225
220 226 void SocExplorerMainWindow::loadCurrentSession()
221 227 {
222 228
223 229 QStringList plugins = SocExplorerSettings::value(this,"LOADED_PLUGINS",QVariant(),SocExplorerSettings::Session).toStringList();
224 230 socexplorerproxy::loadPluginsList(plugins);
225 231 this->restoreGeometry(SocExplorerSettings::value(this,"MAIN_WINDOW_GEOMETRY",QVariant(),SocExplorerSettings::Session).toByteArray());
226 232 this->restoreState(SocExplorerSettings::value(this,"DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray());
233 this->pluginsDockContainer->restoreState(SocExplorerSettings::value(this,"PLUGINS_DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray());
227 234 }
228 235
229 236
230 237 SocExplorerMainWindow::~SocExplorerMainWindow()
231 238 {
232 239
233 240 }
234 241
235 242
236 243 void SocExplorerMainWindow::setLangage(QAction *action)
237 244 {
238 245 QString local = action->data().toString();
239 246 QString qmPath = QDir(QString("translations")).absolutePath();
240 247 appTranslator->load(qmPath+"/socexplorer_"+local+".qm");
241 248 qApp->installTranslator(appTranslator);
242 249 emit this->translateSig();
243 250 }
244 251
245 252
246 253 void SocExplorerMainWindow::createLangMenu()
247 254 {
248 255 this->langMenu = menuBar()->addMenu(tr("&Langue"));
249 256 this->langActionGrp = new QActionGroup(this);
250 257 connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*)));
251 258 QDir* qmDir = new QDir(QString("translations"));
252 259 QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm"));
253 260 for(int i=0;i<LangFiles.size();++i)
254 261 {
255 262 QString Local = LangFiles[i];
256 263 Local.remove(0,Local.indexOf('_')+1);
257 264 Local.chop(3);
258 265 QTranslator translator;
259 266 translator.load(LangFiles[i],qmDir->absolutePath());
260 267 QString langage = translator.translate("MainWindow","English");
261 268 QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this);
262 269 action->setCheckable(true);
263 270 action->setData(Local);
264 271 langMenu->addAction(action);
265 272 langActionGrp->addAction(action);
266 273 if(langage==tr("English"))
267 274 action->setChecked(true);
268 275 }
269 276 }
270 277
271 278
272 279 void SocExplorerMainWindow::updateText()
273 280 {
274 281 emit this->translateSig();
275 282 }
276 283
277 284
278 285
279 286 void SocExplorerMainWindow::showAboutBox()
280 287 {
281 288 p_about->show();
282 289 }
283 290
284 291 void SocExplorerMainWindow::pluginselected(const QString &instanceName)
285 292 {
286 293 socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName);
287 294 if(drv)
288 295 drv->raise();
289 296 }
290 297
291 298 void SocExplorerMainWindow::setActiveSession(const QString &session)
292 299 {
293 300 if(!(p_currentSession.isNull() && session=="default"))
294 301 saveCurrentSession();
295 302 socexplorerproxy::self()->close();
296 303 this->p_currentSession = session;
297 sessionsActions_t* sact;
298 304 SocExplorerSettings::loadSession(session);
299 305 loadCurrentSession();
300 foreach (sact, sessionsActions)
301 {
302 if(sact->text().compare(session))
303 sact->setChecked(false);
304 else
305 sact->setChecked(true);
306 }
306
307 }
308
309 void SocExplorerMainWindow::setActiveSession(QAction *session)
310 {
311 this->setActiveSession(session->text());
307 312 }
308 313
309 314 void SocExplorerMainWindow::showSessionManager(bool)
310 315 {
311 316 this->p_SessionManagerDialog->show();
312 317 }
313 318
319 //TODO handle rename
320 void SocExplorerMainWindow::sessionListChanged()
321 {
322
323 }
324
314 325
315 326
316 327 void SocExplorerMainWindow::closeEvent(QCloseEvent *event)
317 328 {
318 329 saveCurrentSession();
319 330 socexplorerproxy::self()->close();
320 331 qApp->closeAllWindows();
321 332 event->accept();
322 333 }
323 334
324 335
325 336
326 337
327 338
328 339
@@ -1,116 +1,100
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 };
61 43
62 44 class SocExplorerMainWindow : public QMainWindow
63 45 {
64 46 Q_OBJECT
65 47
66 48
67 49 public:
68 50 SocExplorerMainWindow(QString ScriptToEval,QWidget *parent = 0);
69 51 ~SocExplorerMainWindow();
70 52 QAction* Quit,*LoadPlugin,*ManagePlugins,*help,*regsManager,*exploreRegs,*about,*translateAction,*sessionManagerAction;
71 QList<sessionsActions_t*> sessionsActions;
53 QActionGroup*sessionsActions;
72 54 QActionGroup*langActionGrp;
73 55 QMenu* FileMenu,*SettingsMenu,*PluginsMenu,*ToolsMenu,*langMenu,*helpMenu,*SessionsMenu;
74 56 QTranslator* appTranslator;
75 57 void createLangMenu();
76 58 void closeEvent(QCloseEvent *event);
77 59 toolBar* toolpane;
78 60
79 61
80 62 public slots:
81 63 void launchPluginManager();
82 64 void addPluginInterface(QDockWidget* plugin);
83 65 void removePluginInterface(QDockWidget* plugin);
84 66 void clearMenu();
85 67 void updateText();
86 68 void setLangage(QAction* action);
87 69 void showAboutBox();
88 70 void pluginselected(const QString& instanceName);
89 71 void setActiveSession(const QString & session);
72 void setActiveSession(QAction* session);
90 73 void showSessionManager(bool);
74 void sessionListChanged();
91 75 signals:
92 76 void translateSig();
93 77 void registerObject(QObject* object,const QString& instanceName);
94 78
95 79 private:
96 80 void makeObjects(QString ScriptToEval);
97 81 void makeLayout();
98 82 void makeConnections();
99 83 void makeMenu();
100 84 void loadSessions();
101 85 void savePlugins();
102 86 void saveCurrentSession();
103 87 void loadCurrentSession();
104 88 QMainWindow* pluginsDockContainer;
105 89 QSplitter* mainWidget;
106 90 PythonConsole* PythonConsoleInst;
107 91 dockablePluginManager* pluginManager;
108 92 RegsExplorer* regExplorer;
109 93 aboutsocexplorer* p_about;
110 94 QList<QDockWidget*>* p_pluginGUIlist;
111 95 QStringList p_Sessions;
112 96 QString p_currentSession;
113 97 SessionManagerDialog* p_SessionManagerDialog;
114 98 };
115 99
116 100 #endif // MAINWINDOW_H
@@ -1,174 +1,178
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 36 connect(this->ui->RenameQPB,SIGNAL(clicked(bool)),this,SLOT(renameSession()));
37 37 connect(this->ui->SwitchToQPB,SIGNAL(clicked(bool)),this,SLOT(switchSession()));
38 38 }
39 39
40 40 SessionManagerDialog::~SessionManagerDialog()
41 41 {
42 42 delete ui;
43 43 }
44 44
45 45
46 46 QStringList SessionManagerDialog::getSessionsList()
47 47 {
48 48 QStringList result;
49 49 QList<QList<QVariant> > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME);
50 50 for(int i=0;i<sessions.count();i++)
51 51 {
52 52 if(sessions.at(i).count()>=1)
53 53 {
54 54 result.append(sessions.at(i).at(0).toString());
55 55 }
56 56 }
57 57 // May always return at least default session
58 58 if(result.count()==0)
59 59 {
60 60 result.append("default");
61 61 }
62 62 return result;
63 63 }
64 64
65 65 void SessionManagerDialog::show()
66 66 {
67 67 QStringList sessions = getSessionsList();
68 68 this->ui->listWidget->clear();
69 69 this->ui->listWidget->addItems(sessions);
70 70 QDialog::show();
71 71 }
72 72
73 73 void SessionManagerDialog::newSession()
74 74 {
75 75 bool ok=true,exists=false;
76 76 QString text;
77 77 do
78 78 {
79 79 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
80 80 tr("Session name:"), QLineEdit::Normal,
81 81 "New Session", &ok);
82 82 exists = sessionExists(text);
83 83 if(exists && ok)
84 84 {
85 85 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
86 86 tr("The session ")+text+tr(" already exists."),
87 87 QMessageBox::Ok);
88 88 }
89 89 }while(ok && (text.isEmpty() || exists));
90 90
91 91 if (ok && !text.isEmpty())
92 92 {
93 93 this->newSession(text);
94 94 }
95 95 }
96 96
97 97 void SessionManagerDialog::newSession(QString session)
98 98 {
99 99 if (!session.isEmpty())
100 100 {
101 101 this->ui->listWidget->addItem(session);
102 102 updateSessionList();
103 103 }
104 104 }
105 105
106 106 void SessionManagerDialog::renameSession()
107 107 {
108 108 bool ok=true;
109 109 int exists=0;
110 110 QListWidgetItem* item = this->ui->listWidget->currentItem();
111 111 QString text= item->text();
112 QString OldText= item->text();
112 113 do
113 114 {
114 115 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
115 116 tr("New session name:"), QLineEdit::Normal,
116 117 text, &ok);
117 118 exists = sessionExists(text);
118 119 if(exists&& ok)
119 120 {
120 121 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
121 122 tr("The session ")+text+tr(" already exists."),
122 123 QMessageBox::Ok);
123 124 }
124 125 }while(ok && text.isEmpty());
125 126
126 127 if (ok && !text.isEmpty())
127 128 {
128 129 item->setText(text);
130 SocExplorerSettings::renameSession(text,OldText);
131 updateSessionList();
132 emit sessionListChanged();
129 133 }
130 134 }
131 135
132 136 void SessionManagerDialog::deleteSession()
133 137 {
134 138 if(this->ui->listWidget->selectedItems().count())
135 139 {
136 140 QListWidgetItem* item = this->ui->listWidget->currentItem();
137 141 if(item && item->text().compare("default"))
138 142 {
139 143 this->ui->listWidget->removeItemWidget(item);
140 144 SocExplorerSettings::deleteSession(item->text());
141 145 delete item;
142 146 updateSessionList();
143 147 }
144 148 }
145 149 }
146 150
147 151 void SessionManagerDialog::switchSession()
148 152 {
149 153 QListWidgetItem* item = this->ui->listWidget->currentItem();
150 154 if(item)
151 155 emit switchSession(item->text());
152 156 }
153 157
154 158 int SessionManagerDialog::sessionExists(QString session)
155 159 {
156 160 int exists=0;
157 161 for(int i=0;i< this->ui->listWidget->count();i++)
158 162 {
159 163 exists += (this->ui->listWidget->item(i)->text().compare(session)==0);
160 164 }
161 165 return exists;
162 166 }
163 167
164 168 void SessionManagerDialog::updateSessionList()
165 169 {
166 170 QList<QList<QVariant> > sessions;
167 171 for(int i=0;i< this->ui->listWidget->count();i++)
168 172 {
169 173 QList<QVariant> sess;
170 174 sess.append(this->ui->listWidget->item(i)->text());
171 175 sessions.append(sess);
172 176 }
173 177 SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME,sessions);
174 178 }
@@ -1,57 +1,58
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 42 void newSession(QString session);
43 43 int sessionExists(QString session);
44 44 private slots:
45 45 void newSession();
46 46 void renameSession();
47 47 void deleteSession();
48 48 void switchSession();
49 49 signals:
50 50 void switchSession(QString session);
51 void sessionListChanged();
51 52
52 53 private:
53 54 void updateSessionList();
54 55 Ui::SessionManagerDialog *ui;
55 56 };
56 57
57 58 #endif // SESSIONMANAGERDIALOG_H
@@ -1,121 +1,127
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 <property name="windowModality">
6 <enum>Qt::ApplicationModal</enum>
7 </property>
5 8 <property name="geometry">
6 9 <rect>
7 10 <x>0</x>
8 11 <y>0</y>
9 12 <width>553</width>
10 13 <height>275</height>
11 14 </rect>
12 15 </property>
13 16 <property name="windowTitle">
14 17 <string>SocExplorer Session Manager</string>
15 18 </property>
19 <property name="modal">
20 <bool>true</bool>
21 </property>
16 22 <layout class="QGridLayout" name="gridLayout">
17 23 <item row="0" column="0">
18 24 <widget class="QListWidget" name="listWidget"/>
19 25 </item>
20 26 <item row="0" column="1">
21 27 <widget class="QWidget" name="widget" native="true">
22 28 <layout class="QVBoxLayout" name="verticalLayout">
23 29 <item>
24 30 <widget class="QPushButton" name="NewQPB">
25 31 <property name="text">
26 32 <string>New</string>
27 33 </property>
28 34 </widget>
29 35 </item>
30 36 <item>
31 37 <widget class="QPushButton" name="RenameQPB">
32 38 <property name="text">
33 39 <string>Rename</string>
34 40 </property>
35 41 </widget>
36 42 </item>
37 43 <item>
38 44 <widget class="QPushButton" name="CloneQPB">
39 45 <property name="text">
40 46 <string>Clone</string>
41 47 </property>
42 48 </widget>
43 49 </item>
44 50 <item>
45 51 <widget class="QPushButton" name="DeleteQPB">
46 52 <property name="text">
47 53 <string>Delete</string>
48 54 </property>
49 55 </widget>
50 56 </item>
51 57 <item>
52 58 <widget class="QPushButton" name="SwitchToQPB">
53 59 <property name="text">
54 60 <string>Switch to</string>
55 61 </property>
56 62 </widget>
57 63 </item>
58 64 <item>
59 65 <spacer name="verticalSpacer">
60 66 <property name="orientation">
61 67 <enum>Qt::Vertical</enum>
62 68 </property>
63 69 <property name="sizeHint" stdset="0">
64 70 <size>
65 71 <width>20</width>
66 72 <height>40</height>
67 73 </size>
68 74 </property>
69 75 </spacer>
70 76 </item>
71 77 </layout>
72 78 </widget>
73 79 </item>
74 80 <item row="1" column="0" colspan="2">
75 81 <widget class="QDialogButtonBox" name="buttonBox">
76 82 <property name="orientation">
77 83 <enum>Qt::Horizontal</enum>
78 84 </property>
79 85 <property name="standardButtons">
80 86 <set>QDialogButtonBox::Close</set>
81 87 </property>
82 88 </widget>
83 89 </item>
84 90 </layout>
85 91 </widget>
86 92 <resources/>
87 93 <connections>
88 94 <connection>
89 95 <sender>buttonBox</sender>
90 96 <signal>accepted()</signal>
91 97 <receiver>SessionManagerDialog</receiver>
92 98 <slot>accept()</slot>
93 99 <hints>
94 100 <hint type="sourcelabel">
95 101 <x>248</x>
96 102 <y>254</y>
97 103 </hint>
98 104 <hint type="destinationlabel">
99 105 <x>157</x>
100 106 <y>274</y>
101 107 </hint>
102 108 </hints>
103 109 </connection>
104 110 <connection>
105 111 <sender>buttonBox</sender>
106 112 <signal>rejected()</signal>
107 113 <receiver>SessionManagerDialog</receiver>
108 114 <slot>reject()</slot>
109 115 <hints>
110 116 <hint type="sourcelabel">
111 117 <x>316</x>
112 118 <y>260</y>
113 119 </hint>
114 120 <hint type="destinationlabel">
115 121 <x>286</x>
116 122 <y>274</y>
117 123 </hint>
118 124 </hints>
119 125 </connection>
120 126 </connections>
121 127 </ui>
General Comments 0
You need to be logged in to leave comments. Login now