##// END OF EJS Templates
Working on session manager.
Jeandet Alexis -
r93:0dab228f7441 default
parent child
Show More
@@ -1,205 +1,248
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "socexplorersettings.h"
22 #include "socexplorersettings.h"
23
23
24 SocExplorerSettings* SocExplorerSettings::_self=NULL;
24 SocExplorerSettings* SocExplorerSettings::_self=NULL;
25 QSettings* SocExplorerSettings::m_settings=NULL;
25 QSettings* SocExplorerSettings::m_settings=NULL;
26 QSettings* SocExplorerSettings::m_sessionSettings=NULL;
26 QSettings* SocExplorerSettings::m_sessionSettings=NULL;
27 SocExplorerSettingsDialog* SocExplorerSettings::m_configDialog = NULL;
27 SocExplorerSettingsDialog* SocExplorerSettings::m_configDialog = NULL;
28 #include <socexplorergui.h>
28 #include <socexplorergui.h>
29 #include <QFile>
29 #include <QFile>
30 #include <QFileInfo>
30 #include <QFileInfo>
31 #include <QDir>
31 #include <QDir>
32 #include <QDebug>
32 #include <QDebug>
33
33
34 #define INIT() \
34 #define INIT() \
35 if(Q_UNLIKELY(_self==NULL))\
35 if(Q_UNLIKELY(_self==NULL))\
36 {\
36 {\
37 init();\
37 init();\
38 }
38 }
39
39
40
40
41 SocExplorerSettings::SocExplorerSettings(QObject *parent) : QObject(parent)
41 SocExplorerSettings::SocExplorerSettings(QObject *parent) : QObject(parent)
42 {
42 {
43 m_settings = new QSettings();
43 m_settings = new QSettings();
44 m_configDialog = new SocExplorerSettingsDialog();
44 m_configDialog = new SocExplorerSettingsDialog();
45 QAction* trigerGUI = new QAction(tr("Settings"),this);
45 QAction* trigerGUI = new QAction(tr("Settings"),this);
46 connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog()));
46 connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog()));
47 SocExplorerGUI::addSettingsAction(trigerGUI);
47 SocExplorerGUI::addSettingsAction(trigerGUI);
48 }
48 }
49
49
50 SocExplorerSettings::~SocExplorerSettings()
50 SocExplorerSettings::~SocExplorerSettings()
51 {
51 {
52 if(m_settings)
52 if(m_settings)
53 {
53 {
54 m_settings->sync();
54 m_settings->sync();
55 delete m_settings;
55 delete m_settings;
56 }
56 }
57 if(m_sessionSettings)
57 if(m_sessionSettings)
58 {
58 {
59 m_sessionSettings->sync();
59 m_sessionSettings->sync();
60 delete m_sessionSettings;
60 delete m_sessionSettings;
61 }
61 }
62 }
62 }
63
63
64 void SocExplorerSettings::init()
64 void SocExplorerSettings::init()
65 {
65 {
66 if(!_self)
66 if(!_self)
67 {
67 {
68 _self= new SocExplorerSettings();
68 _self= new SocExplorerSettings();
69 }
69 }
70 }
70 }
71
71
72 void SocExplorerSettings::setValue(QObject *object, const QString &key, const QVariant &value, SettingScope Sscope)
72 void SocExplorerSettings::setValue(QObject *object, const QString &key, const QVariant &value, SettingScope Sscope)
73 {
73 {
74 INIT();
74 INIT();
75 setValue(object->metaObject()->className(),key,value,Sscope);
75 setValue(object->metaObject()->className(),key,value,Sscope);
76 }
76 }
77
77
78 QVariant SocExplorerSettings::value(QObject *object, const QString &key, const QVariant &defaultValue, SettingScope Sscope)
78 QVariant SocExplorerSettings::value(QObject *object, const QString &key, const QVariant &defaultValue, SettingScope Sscope)
79 {
79 {
80 INIT();
80 INIT();
81 return value(object->metaObject()->className(),key,defaultValue,Sscope);
81 return value(object->metaObject()->className(),key,defaultValue,Sscope);
82 }
82 }
83
83
84 void SocExplorerSettings::setValue(const QString scope, const QString &key, const QVariant &value, SettingScope Sscope)
84 void SocExplorerSettings::setValue(const QString scope, const QString &key, const QVariant &value, SettingScope Sscope)
85 {
85 {
86 INIT();
86 INIT();
87 switch (Sscope)
87 switch (Sscope)
88 {
88 {
89 case SystemWide:
89 case SystemWide:
90 if(m_settings)
90 if(m_settings)
91 m_settings->setValue(scope+"/"+key,value);
91 m_settings->setValue(scope+"/"+key,value);
92 break;
92 break;
93 case Session:
93 case Session:
94 if(m_sessionSettings)
94 if(m_sessionSettings)
95 m_sessionSettings->setValue(scope+"/"+key,value);
95 m_sessionSettings->setValue(scope+"/"+key,value);
96 break;
96 break;
97 default:
97 default:
98 break;
98 break;
99 }
99 }
100 }
100 }
101
101
102 QVariant SocExplorerSettings::value(const QString scope, const QString &key, const QVariant &defaultValue, SettingScope Sscope)
102 QVariant SocExplorerSettings::value(const QString scope, const QString &key, const QVariant &defaultValue, SettingScope Sscope)
103 {
103 {
104 INIT();
104 INIT();
105 switch (Sscope)
105 switch (Sscope)
106 {
106 {
107 case SystemWide:
107 case SystemWide:
108 if(m_settings)
108 if(m_settings)
109 return m_settings->value(scope+"/"+key,defaultValue);
109 return m_settings->value(scope+"/"+key,defaultValue);
110 break;
110 break;
111 case Session:
111 case Session:
112 if(m_sessionSettings)
112 if(m_sessionSettings)
113 return m_sessionSettings->value(scope+"/"+key,defaultValue);
113 return m_sessionSettings->value(scope+"/"+key,defaultValue);
114 break;
114 break;
115 default:
115 default:
116 break;
116 break;
117 }
117 }
118 return defaultValue;
118 return defaultValue;
119 }
119 }
120
120
121 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, SocExplorerSettings::SettingScope Sscope)
121 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, SocExplorerSettings::SettingScope Sscope)
122 {
122 {
123 INIT();
123 INIT();
124 QList<QList<QVariant> > defaultValue;
124 QList<QList<QVariant> > defaultValue;
125 switch (Sscope)
125 switch (Sscope)
126 {
126 {
127 case SystemWide:
127 case SystemWide:
128 if(m_settings)
128 if(m_settings)
129 return arrays(prefix,keys,m_settings);
129 return arrays(prefix,keys,m_settings);
130 break;
130 break;
131 case Session:
131 case Session:
132 if(m_sessionSettings)
132 if(m_sessionSettings)
133 return arrays(prefix,keys,m_sessionSettings);
133 return arrays(prefix,keys,m_sessionSettings);
134 break;
134 break;
135 default:
135 default:
136 break;
136 break;
137 }
137 }
138 return defaultValue;
138 return defaultValue;
139 }
139 }
140
140
141 void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, SocExplorerSettings::SettingScope Sscope)
142 {
143 INIT();
144 switch (Sscope)
145 {
146 case SystemWide:
147 if(m_settings)
148 return setArrays(prefix,keys,values,m_settings);
149 break;
150 case Session:
151 if(m_sessionSettings)
152 return setArrays(prefix,keys,values,m_sessionSettings);
153 break;
154 default:
155 break;
156 }
157
158 }
159
141 void SocExplorerSettings::sync()
160 void SocExplorerSettings::sync()
142 {
161 {
143 INIT();
162 INIT();
144 if(m_settings)
163 if(m_settings)
145 {
164 {
146 m_settings->sync();
165 m_settings->sync();
147 }
166 }
148 if(m_sessionSettings)
167 if(m_sessionSettings)
149 {
168 {
150 m_sessionSettings->sync();
169 m_sessionSettings->sync();
151 }
170 }
152 }
171 }
153
172
154 bool SocExplorerSettings::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text)
173 bool SocExplorerSettings::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text)
155 {
174 {
156 INIT();
175 INIT();
157 return m_configDialog->registerConfigEntry(configEntry,icon,text);
176 return m_configDialog->registerConfigEntry(configEntry,icon,text);
158 }
177 }
159
178
160 bool SocExplorerSettings::loadSession(const QString &session)
179 bool SocExplorerSettings::loadSession(const QString &session)
161 {
180 {
162 INIT();
181 INIT();
163 QFileInfo sessionInfo(m_settings->fileName());
182 QFileInfo sessionInfo(m_settings->fileName());
164 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
183 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
165 if(m_sessionSettings)
184 if(m_sessionSettings)
166 {
185 {
167 delete m_sessionSettings;
186 delete m_sessionSettings;
168 m_sessionSettings = NULL;
187 m_sessionSettings = NULL;
169 }
188 }
170 m_sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self());
189 m_sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self());
171 qDebug()<< m_sessionSettings->fileName();
190 qDebug()<< m_sessionSettings->fileName();
172 if(m_sessionSettings->status()==QSettings::NoError)
191 if(m_sessionSettings->status()==QSettings::NoError)
173 {
192 {
174 return true;
193 return true;
175 }
194 }
176 delete m_sessionSettings;
195 delete m_sessionSettings;
177 m_sessionSettings = NULL;
196 m_sessionSettings = NULL;
178 return false;
197 return false;
179 }
198 }
180
199
181 void SocExplorerSettings::popConfigDialog()
200 void SocExplorerSettings::popConfigDialog()
182 {
201 {
183 m_configDialog->popConfigDialog(NULL);
202 m_configDialog->popConfigDialog(NULL);
184 }
203 }
185
204
186 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, QSettings *settings)
205 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, QSettings *settings)
187 {
206 {
188 QList<QList<QVariant> > result;
207 QList<QList<QVariant> > result;
189 if(settings)
208 if(settings)
190 {
209 {
191 int size = settings->beginReadArray(prefix);
210 int size = settings->beginReadArray(prefix);
192 for (int i = 0; i < size; ++i)
211 for (int i = 0; i < size; ++i)
193 {
212 {
194 result.append(QList<QVariant>());
213 result.append(QList<QVariant>());
195 settings->setArrayIndex(i);
214 settings->setArrayIndex(i);
196 for(int l=0;l<keys.count();l++)
215 for(int l=0;l<keys.count();l++)
197 {
216 {
198 result[i].append(settings->value(keys.at(i)));
217 result[i].append(settings->value(keys.at(l)));
199 }
218 }
200 }
219 }
201 settings->endArray();
220 settings->endArray();
202 }
221 }
203 return result;
222 return result;
204 }
223 }
205
224
225 void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, QSettings *settings)
226 {
227 if(settings)
228 {
229 QString key;
230 foreach (key, keys)
231 {
232
233 settings->remove(prefix+"/"+key);
234 }
235 settings->beginWriteArray(prefix);
236 for (int i = 0; i < values.size(); ++i)
237 {
238 settings->setArrayIndex(i);
239 for(int l=0;l<keys.count();l++)
240 {
241 settings->setValue(keys[l], values.at(i).at(l));
242 }
243 }
244 settings->endArray();
245
246 }
247 }
248
@@ -1,66 +1,68
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef SOCEXPLORERSETTINGS_H
22 #ifndef SOCEXPLORERSETTINGS_H
23 #define SOCEXPLORERSETTINGS_H
23 #define SOCEXPLORERSETTINGS_H
24
24
25 #include <QObject>
25 #include <QObject>
26 #include <QWidget>
26 #include <QWidget>
27 #include <QSettings>
27 #include <QSettings>
28 #include <socexplorersettingsdialog.h>
28 #include <socexplorersettingsdialog.h>
29
29
30 class SocExplorerSettings : public QObject
30 class SocExplorerSettings : public QObject
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 private:
33 private:
34 static SocExplorerSettings* _self;
34 static SocExplorerSettings* _self;
35 static QSettings* m_settings;
35 static QSettings* m_settings;
36 static QSettings* m_sessionSettings;
36 static QSettings* m_sessionSettings;
37 static SocExplorerSettingsDialog* m_configDialog;
37 static SocExplorerSettingsDialog* m_configDialog;
38 SocExplorerSettings(QObject *parent = 0);
38 SocExplorerSettings(QObject *parent = 0);
39 ~SocExplorerSettings();
39 ~SocExplorerSettings();
40 public:
40 public:
41 enum SettingScope {
41 enum SettingScope {
42 SystemWide = 0,
42 SystemWide = 0,
43 Session
43 Session
44 };
44 };
45 static void init();
45 static void init();
46 static SocExplorerSettings* self(){ if(!_self){_self= new SocExplorerSettings;}return _self;}
46 static SocExplorerSettings* self(){ if(!_self){_self= new SocExplorerSettings;}return _self;}
47 static void setValue(QObject* object,const QString & key, const QVariant & value,SettingScope Sscope =SystemWide);
47 static void setValue(QObject* object,const QString & key, const QVariant & value,SettingScope Sscope =SystemWide);
48 static QVariant value(QObject* object, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope=SystemWide);
48 static QVariant value(QObject* object, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope=SystemWide);
49 static void setValue(const QString scope,const QString & key, const QVariant & value,SettingScope Sscope= SystemWide);
49 static void setValue(const QString scope,const QString & key, const QVariant & value,SettingScope Sscope= SystemWide);
50 static QVariant value(const QString scope, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope =SystemWide);
50 static QVariant value(const QString scope, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope =SystemWide);
51 static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,SettingScope Sscope =SystemWide);
51 static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,SettingScope Sscope =SystemWide);
52 static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,SettingScope Sscope =SystemWide);
52 static void sync();
53 static void sync();
53 static bool registerConfigEntry(SocExplorerSettingsItem* configEntry,QIcon icon, QString text);
54 static bool registerConfigEntry(SocExplorerSettingsItem* configEntry,QIcon icon, QString text);
54 //! Loads the given session, or sreate it if doesn't exists.
55 //! Loads the given session, or sreate it if doesn't exists.
55 //! \param session Session name.
56 //! \param session Session name.
56 //! \return true if success or false if fails to create session config file.
57 //! \return true if success or false if fails to create session config file.
57 static bool loadSession(const QString& session);
58 static bool loadSession(const QString& session);
58 signals:
59 signals:
59
60
60 public slots:
61 public slots:
61 void popConfigDialog();
62 void popConfigDialog();
62 private:
63 private:
63 static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,QSettings* settings);
64 static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,QSettings* settings);
65 static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,QSettings* settings);
64 };
66 };
65
67
66 #endif // SOCEXPLORERSETTINGS_H
68 #endif // SOCEXPLORERSETTINGS_H
@@ -1,268 +1,258
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011-2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2011-2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "mainwindow.h"
22 #include "mainwindow.h"
23 #include <QDockWidget>
23 #include <QDockWidget>
24 #include <socexplorersettings.h>
24 #include <socexplorersettings.h>
25 #include <socexplorerconfigkeys.h>
25 #include <socexplorerconfigkeys.h>
26
26
27 SocExplorerMainWindow::SocExplorerMainWindow(QString ScriptToEval, QWidget *parent)
27 SocExplorerMainWindow::SocExplorerMainWindow(QString ScriptToEval, QWidget *parent)
28 : QMainWindow(parent)
28 : QMainWindow(parent)
29 {
29 {
30 QCoreApplication::setApplicationName("SocExplorer");
30 QCoreApplication::setApplicationName("SocExplorer");
31 QCoreApplication::setOrganizationName("LPP");
31 QCoreApplication::setOrganizationName("LPP");
32 QCoreApplication::setOrganizationDomain("lpp.fr");
32 QCoreApplication::setOrganizationDomain("lpp.fr");
33 this->makeObjects(ScriptToEval);
33 this->makeObjects(ScriptToEval);
34 this->makeLayout();
34 this->makeLayout();
35 this->makeMenu();
35 this->makeMenu();
36 SocExplorerSettings::init();
36 SocExplorerSettings::init();
37 SocExplorerSettings::loadSession("Session1");
37 SocExplorerSettings::loadSession("Session1");
38 this->makeConnections();
38 this->makeConnections();
39 this->setWindowIcon(QIcon(":/images/icon.png"));
39 this->setWindowIcon(QIcon(":/images/icon.png"));
40 this->setAcceptDrops(true);
40 this->setAcceptDrops(true);
41 this->pluginManager->setRootLoadable(true);
41 this->pluginManager->setRootLoadable(true);
42 this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval);
42 this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval);
43 QFile file(":/styles/SocExplorer.css");
43 QFile file(":/styles/SocExplorer.css");
44 if(file.open(QIODevice::ReadOnly | QIODevice::Text))
44 if(file.open(QIODevice::ReadOnly | QIODevice::Text))
45 {
45 {
46 qApp->setStyleSheet(file.readAll());
46 qApp->setStyleSheet(file.readAll());
47 file.close();
47 file.close();
48 }
48 }
49 }
49 }
50
50
51
51
52 void SocExplorerMainWindow::makeObjects(QString ScriptToEval)
52 void SocExplorerMainWindow::makeObjects(QString ScriptToEval)
53 {
53 {
54 Q_UNUSED(ScriptToEval)
54 Q_UNUSED(ScriptToEval)
55 this->p_pluginGUIlist = new QList<QDockWidget*>();
55 this->p_pluginGUIlist = new QList<QDockWidget*>();
56 pluginsDockContainer = new QMainWindow;
56 pluginsDockContainer = new QMainWindow;
57 pluginsDockContainer->setWindowFlags(Qt::Widget);
57 pluginsDockContainer->setWindowFlags(Qt::Widget);
58 pluginsDockContainer->setDockNestingEnabled(true);
58 pluginsDockContainer->setDockNestingEnabled(true);
59 this->mainWidget = new QSplitter(Qt::Vertical);
59 this->mainWidget = new QSplitter(Qt::Vertical);
60 this->appTranslator = new QTranslator;
60 this->appTranslator = new QTranslator;
61 this->Quit = new QAction(tr("&Quit"),this);
61 this->Quit = new QAction(tr("&Quit"),this);
62 this->Quit->setShortcut(tr("CTRL+Q"));
62 this->Quit->setShortcut(tr("CTRL+Q"));
63 this->ManagePlugins = new QAction(tr("&Manage Plugins"),this);
63 this->ManagePlugins = new QAction(tr("&Manage Plugins"),this);
64 this->ManagePlugins->setShortcut(tr("CTRL+P"));
64 this->ManagePlugins->setShortcut(tr("CTRL+P"));
65 this->regsManager = new QAction(tr("&Manage registers"),this);
65 this->regsManager = new QAction(tr("&Manage registers"),this);
66 this->exploreRegs = new QAction(tr("&Explore registers"),this);
66 this->exploreRegs = new QAction(tr("&Explore registers"),this);
67 this->help = new QAction(tr("&Help"),this);
67 this->help = new QAction(tr("&Help"),this);
68 this->help->setShortcut(tr("CTRL+H"));
68 this->help->setShortcut(tr("CTRL+H"));
69 this->about = new QAction(tr("&About"),this);
69 this->about = new QAction(tr("&About"),this);
70 this->p_SessionManagerDialog = new SessionManagerDialog();
70 this->p_SessionManagerDialog = new SessionManagerDialog();
71 socexplorerproxy::setMainWindow(this);
71 socexplorerproxy::setMainWindow(this);
72 SocExplorerEngine::setMainWindow(this);
72 SocExplorerEngine::setMainWindow(this);
73 SocExplorerEngine::xmlModel()->scanXmlFiles();
73 SocExplorerEngine::xmlModel()->scanXmlFiles();
74 this->regExplorer = new RegsExplorer();
74 this->regExplorer = new RegsExplorer();
75 this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas);
75 this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas);
76 this->addPluginInterface(this->regExplorer);
76 this->addPluginInterface(this->regExplorer);
77 this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self());
77 this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self());
78 this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self());
78 this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self());
79 this->pluginManager = new dockablePluginManager();
79 this->pluginManager = new dockablePluginManager();
80 this->toolpane = new toolBar;
80 this->toolpane = new toolBar;
81 this->p_about = new aboutsocexplorer();
81 this->p_about = new aboutsocexplorer();
82 }
82 }
83
83
84 void SocExplorerMainWindow::makeLayout()
84 void SocExplorerMainWindow::makeLayout()
85 {
85 {
86 this->mainWidget->addWidget(pluginsDockContainer);
86 this->mainWidget->addWidget(pluginsDockContainer);
87 this->mainWidget->addWidget(this->PythonConsoleInst);
87 this->mainWidget->addWidget(this->PythonConsoleInst);
88 this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
88 this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
89 this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane);
89 this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane);
90 this->toolpane->addTool(this->pluginManager);
90 this->toolpane->addTool(this->pluginManager);
91 this->setCentralWidget(this->mainWidget);
91 this->setCentralWidget(this->mainWidget);
92 }
92 }
93
93
94
94
95 void SocExplorerMainWindow::makeConnections()
95 void SocExplorerMainWindow::makeConnections()
96 {
96 {
97 connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu()));
97 connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu()));
98 connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText()));
98 connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText()));
99 connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*)));
99 connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*)));
100 connect(socexplorerproxy::self(),SIGNAL(removePluginGUI(QDockWidget*)),this,SLOT(removePluginInterface(QDockWidget*)));
100 connect(socexplorerproxy::self(),SIGNAL(removePluginGUI(QDockWidget*)),this,SLOT(removePluginInterface(QDockWidget*)));
101 connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager()));
101 connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager()));
102 connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit()));
102 connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit()));
103 connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString)));
103 connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString)));
104 connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString)));
104 connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString)));
105 connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree()));
105 connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree()));
106 connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
106 connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
107 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString)));
107 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString)));
108 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString)));
108 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString)));
109 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString)));
109 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString)));
110 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString)));
110 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString)));
111 connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString)));
111 connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString)));
112 connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox()));
112 connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox()));
113 connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show()));
113 connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show()));
114
114
115 connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this->p_SessionManagerDialog,SLOT(show()));
115 connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this->p_SessionManagerDialog,SLOT(show()));
116
116
117 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString)));
117 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString)));
118 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString)));
118 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString)));
119
119
120 }
120 }
121
121
122
122
123 void SocExplorerMainWindow::launchPluginManager()
123 void SocExplorerMainWindow::launchPluginManager()
124 {
124 {
125
125
126 if(this->pluginManager->isHidden())
126 if(this->pluginManager->isHidden())
127 {
127 {
128 this->pluginManager->setHidden(false);
128 this->pluginManager->setHidden(false);
129 }
129 }
130
130
131 }
131 }
132
132
133
133
134 void SocExplorerMainWindow::addPluginInterface(QDockWidget *plugin)
134 void SocExplorerMainWindow::addPluginInterface(QDockWidget *plugin)
135 {
135 {
136 plugin->setAllowedAreas(Qt::AllDockWidgetAreas);
136 plugin->setAllowedAreas(Qt::AllDockWidgetAreas);
137 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin);
137 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin);
138 if(p_pluginGUIlist->count()!=0)
138 if(p_pluginGUIlist->count()!=0)
139 this->pluginsDockContainer->tabifyDockWidget(p_pluginGUIlist->last(),plugin);
139 this->pluginsDockContainer->tabifyDockWidget(p_pluginGUIlist->last(),plugin);
140 p_pluginGUIlist->append(plugin);
140 p_pluginGUIlist->append(plugin);
141 }
141 }
142
142
143 void SocExplorerMainWindow::removePluginInterface(QDockWidget *plugin)
143 void SocExplorerMainWindow::removePluginInterface(QDockWidget *plugin)
144 {
144 {
145 p_pluginGUIlist->removeOne(plugin);
145 p_pluginGUIlist->removeOne(plugin);
146 this->pluginsDockContainer->removeDockWidget(plugin);
146 this->pluginsDockContainer->removeDockWidget(plugin);
147 }
147 }
148
148
149
149
150 void SocExplorerMainWindow::clearMenu()
150 void SocExplorerMainWindow::clearMenu()
151 {
151 {
152 this->menuBar()->clear();
152 this->menuBar()->clear();
153 this->makeMenu();
153 this->makeMenu();
154 }
154 }
155
155
156
156
157 void SocExplorerMainWindow::makeMenu()
157 void SocExplorerMainWindow::makeMenu()
158 {
158 {
159 this->FileMenu = menuBar()->addMenu(tr("&File"));
159 this->FileMenu = menuBar()->addMenu(tr("&File"));
160 this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions"));
160 this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions"));
161 this->sessionManagerAction = this->FileMenu->addAction(tr("&Session manager..."));
161 this->sessionManagerAction = this->FileMenu->addAction(tr("&Session manager..."));
162 this->SettingsMenu = menuBar()->addMenu(tr("&Settings"));
162 this->SettingsMenu = menuBar()->addMenu(tr("&Settings"));
163 SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu);
163 SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu);
164 this->PluginsMenu = menuBar()->addMenu(tr("&Plugins"));
164 this->PluginsMenu = menuBar()->addMenu(tr("&Plugins"));
165 this->ToolsMenu = menuBar()->addMenu(tr("&Tools"));
165 this->ToolsMenu = menuBar()->addMenu(tr("&Tools"));
166 this->ToolsMenu->addAction(this->exploreRegs);
166 this->ToolsMenu->addAction(this->exploreRegs);
167 this->FileMenu->addAction(this->Quit);
167 this->FileMenu->addAction(this->Quit);
168 socexplorerproxy::self()->makeMenu(this->PluginsMenu);
168 socexplorerproxy::self()->makeMenu(this->PluginsMenu);
169 this->PluginsMenu->addAction(this->ManagePlugins);
169 this->PluginsMenu->addAction(this->ManagePlugins);
170
170
171 this->helpMenu = menuBar()->addMenu(tr("Help"));
171 this->helpMenu = menuBar()->addMenu(tr("Help"));
172 this->helpMenu->addAction(this->help);
172 this->helpMenu->addAction(this->help);
173 this->helpMenu->addAction(this->about);
173 this->helpMenu->addAction(this->about);
174
174
175 }
175 }
176
176
177 void SocExplorerMainWindow::loadSessions()
177 void SocExplorerMainWindow::loadSessions()
178 {
178 {
179 // QStringList sessions = SocExplorerSettings::value();
179 p_Sessions=this->p_SessionManagerDialog->getSessionsList();
180 QList<QList<QVariant> > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME);
181 p_Sessions.clear();
182 for(int i=0;i<sessions.count();i++)
183 {
184 if(sessions.at(i).count()>=1)
185 {
186 p_Sessions.append(sessions.at(i).at(0).toString());
187 }
188 }
189
190 }
180 }
191
181
192
182
193 SocExplorerMainWindow::~SocExplorerMainWindow()
183 SocExplorerMainWindow::~SocExplorerMainWindow()
194 {
184 {
195 SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session);
185 SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session);
196 SocExplorerSettings::sync();
186 SocExplorerSettings::sync();
197 }
187 }
198
188
199
189
200 void SocExplorerMainWindow::setLangage(QAction *action)
190 void SocExplorerMainWindow::setLangage(QAction *action)
201 {
191 {
202 QString local = action->data().toString();
192 QString local = action->data().toString();
203 QString qmPath = QDir(QString("translations")).absolutePath();
193 QString qmPath = QDir(QString("translations")).absolutePath();
204 appTranslator->load(qmPath+"/socexplorer_"+local+".qm");
194 appTranslator->load(qmPath+"/socexplorer_"+local+".qm");
205 qApp->installTranslator(appTranslator);
195 qApp->installTranslator(appTranslator);
206 emit this->translateSig();
196 emit this->translateSig();
207 }
197 }
208
198
209
199
210 void SocExplorerMainWindow::createLangMenu()
200 void SocExplorerMainWindow::createLangMenu()
211 {
201 {
212 this->langMenu = menuBar()->addMenu(tr("&Langue"));
202 this->langMenu = menuBar()->addMenu(tr("&Langue"));
213 this->langActionGrp = new QActionGroup(this);
203 this->langActionGrp = new QActionGroup(this);
214 connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*)));
204 connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*)));
215 QDir* qmDir = new QDir(QString("translations"));
205 QDir* qmDir = new QDir(QString("translations"));
216 QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm"));
206 QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm"));
217 for(int i=0;i<LangFiles.size();++i)
207 for(int i=0;i<LangFiles.size();++i)
218 {
208 {
219 QString Local = LangFiles[i];
209 QString Local = LangFiles[i];
220 Local.remove(0,Local.indexOf('_')+1);
210 Local.remove(0,Local.indexOf('_')+1);
221 Local.chop(3);
211 Local.chop(3);
222 QTranslator translator;
212 QTranslator translator;
223 translator.load(LangFiles[i],qmDir->absolutePath());
213 translator.load(LangFiles[i],qmDir->absolutePath());
224 QString langage = translator.translate("MainWindow","English");
214 QString langage = translator.translate("MainWindow","English");
225 QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this);
215 QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this);
226 action->setCheckable(true);
216 action->setCheckable(true);
227 action->setData(Local);
217 action->setData(Local);
228 langMenu->addAction(action);
218 langMenu->addAction(action);
229 langActionGrp->addAction(action);
219 langActionGrp->addAction(action);
230 if(langage==tr("English"))
220 if(langage==tr("English"))
231 action->setChecked(true);
221 action->setChecked(true);
232 }
222 }
233 }
223 }
234
224
235
225
236 void SocExplorerMainWindow::updateText()
226 void SocExplorerMainWindow::updateText()
237 {
227 {
238 emit this->translateSig();
228 emit this->translateSig();
239 }
229 }
240
230
241
231
242
232
243 void SocExplorerMainWindow::showAboutBox()
233 void SocExplorerMainWindow::showAboutBox()
244 {
234 {
245 p_about->show();
235 p_about->show();
246 }
236 }
247
237
248 void SocExplorerMainWindow::pluginselected(const QString &instanceName)
238 void SocExplorerMainWindow::pluginselected(const QString &instanceName)
249 {
239 {
250 socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName);
240 socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName);
251 if(drv)
241 if(drv)
252 drv->raise();
242 drv->raise();
253 }
243 }
254
244
255
245
256
246
257 void SocExplorerMainWindow::closeEvent(QCloseEvent *event)
247 void SocExplorerMainWindow::closeEvent(QCloseEvent *event)
258 {
248 {
259 socexplorerproxy::self()->close();
249 socexplorerproxy::self()->close();
260 qApp->closeAllWindows();
250 qApp->closeAllWindows();
261 event->accept();
251 event->accept();
262 }
252 }
263
253
264
254
265
255
266
256
267
257
268
258
@@ -1,14 +1,143
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
1 #include "sessionmanagerdialog.h"
22 #include "sessionmanagerdialog.h"
2 #include "ui_sessionmanagerdialog.h"
23 #include "ui_sessionmanagerdialog.h"
24 #include <socexplorersettings.h>
25 #include <socexplorerconfigkeys.h>
26 #include <QInputDialog>
27 #include <QMessageBox>
3
28
4 SessionManagerDialog::SessionManagerDialog(QWidget *parent) :
29 SessionManagerDialog::SessionManagerDialog(QWidget *parent) :
5 QDialog(parent),
30 QDialog(parent),
6 ui(new Ui::SessionManagerDialog)
31 ui(new Ui::SessionManagerDialog)
7 {
32 {
8 ui->setupUi(this);
33 ui->setupUi(this);
34 connect(this->ui->NewQPB,SIGNAL(clicked(bool)),this,SLOT(newSession()));
35 connect(this->ui->DeleteQPB,SIGNAL(clicked(bool)),this,SLOT(deleteSession()));
9 }
36 }
10
37
11 SessionManagerDialog::~SessionManagerDialog()
38 SessionManagerDialog::~SessionManagerDialog()
12 {
39 {
13 delete ui;
40 delete ui;
14 }
41 }
42
43
44 QStringList SessionManagerDialog::getSessionsList()
45 {
46 QStringList result;
47 QList<QList<QVariant> > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME);
48 for(int i=0;i<sessions.count();i++)
49 {
50 if(sessions.at(i).count()>=1)
51 {
52 result.append(sessions.at(i).at(0).toString());
53 }
54 }
55 // May always return at least default session
56 if(result.count()==0)
57 {
58 result.append("default");
59 }
60 return result;
61 }
62
63 void SessionManagerDialog::show()
64 {
65 QStringList sessions = getSessionsList();
66 this->ui->listWidget->addItems(sessions);
67 QDialog::show();
68 }
69
70 void SessionManagerDialog::newSession()
71 {
72 bool ok=true,exists=false;
73 QString text;
74 do
75 {
76 text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
77 tr("Session name:"), QLineEdit::Normal,
78 "New Session", &ok);
79 exists = sessionExists(text);
80 if(exists && ok)
81 {
82 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
83 tr("The session ")+text+tr(" already exists."),
84 QMessageBox::Ok);
85 }
86 }while(ok && !text.isEmpty() && exists);
87
88 if (ok && !text.isEmpty())
89 {
90 this->newSession(text);
91 }
92 }
93
94 void SessionManagerDialog::newSession(QString session)
95 {
96 if (!session.isEmpty())
97 {
98 this->ui->listWidget->addItem(session);
99 updateSessionList();
100 }
101 }
102
103 void SessionManagerDialog::renameSession()
104 {
105
106 }
107
108 void SessionManagerDialog::deleteSession()
109 {
110 if(this->ui->listWidget->selectedItems().count())
111 {
112 QListWidgetItem* item = this->ui->listWidget->currentItem();
113 if(item && item->text().compare("default"))
114 {
115 this->ui->listWidget->removeItemWidget(item);
116 //TODO delete session FILE!
117 delete item;
118 updateSessionList();
119 }
120 }
121 }
122
123 bool SessionManagerDialog::sessionExists(QString session)
124 {
125 bool diff=true;
126 for(int i=0;i< this->ui->listWidget->count();i++)
127 {
128 diff &= (this->ui->listWidget->item(i)->text().compare(session)!=0);
129 }
130 return !diff;
131 }
132
133 void SessionManagerDialog::updateSessionList()
134 {
135 QList<QList<QVariant> > sessions;
136 for(int i=0;i< this->ui->listWidget->count();i++)
137 {
138 QList<QVariant> sess;
139 sess.append(this->ui->listWidget->item(i)->text());
140 sessions.append(sess);
141 }
142 SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME,sessions);
143 }
@@ -1,22 +1,53
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
1 #ifndef SESSIONMANAGERDIALOG_H
22 #ifndef SESSIONMANAGERDIALOG_H
2 #define SESSIONMANAGERDIALOG_H
23 #define SESSIONMANAGERDIALOG_H
3
24
4 #include <QDialog>
25 #include <QDialog>
5
26
6 namespace Ui {
27 namespace Ui {
7 class SessionManagerDialog;
28 class SessionManagerDialog;
8 }
29 }
9
30
10 class SessionManagerDialog : public QDialog
31 class SessionManagerDialog : public QDialog
11 {
32 {
12 Q_OBJECT
33 Q_OBJECT
13
34
14 public:
35 public:
15 explicit SessionManagerDialog(QWidget *parent = 0);
36 explicit SessionManagerDialog(QWidget *parent = 0);
16 ~SessionManagerDialog();
37 ~SessionManagerDialog();
17
38
39 QStringList getSessionsList();
40 public slots:
41 void show();
42 void newSession();
43 void newSession(QString session);
44 void renameSession();
45 void deleteSession();
46 bool sessionExists(QString session);
47
18 private:
48 private:
49 void updateSessionList();
19 Ui::SessionManagerDialog *ui;
50 Ui::SessionManagerDialog *ui;
20 };
51 };
21
52
22 #endif // SESSIONMANAGERDIALOG_H
53 #endif // SESSIONMANAGERDIALOG_H
General Comments 0
You need to be logged in to leave comments. Login now