Pre-0.7 merged
Alexis Jeandet -
r107:c459540a6dbd merge 0.6
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -0,0 +1,34
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, 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 ----------------------------------------------------------------------------*/
22 #ifndef SOCEXPLORERCONFIGKEYS
23 #define SOCEXPLORERCONFIGKEYS
24
25 #define SOCEXPLORERENGINE_SETTINGS_SCOPE "SocExplorerEngine"
26 #define SOCEXPLORERENGINE_SETTINGS_PLUGINS_LOOKUP_PATH "plugins-lookup-path"
27 #define SOCEXPLORERENGINE_SETTINGS_SOC_REGS_LOOKUP_PATH "soc-registers-lookup-path"
28
29 #define SOCEXPLORERGLOBAL_SETTINGS_SCOPE "GLOBAL"
30 #define SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE "SESSIONS"
31 #define SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME "NAME"
32
33 #endif // SOCEXPLORERCONFIGKEYS
34
@@ -0,0 +1,93
1 #include "socexplorergui.h"
2
3 SocExplorerGUI* SocExplorerGUI::_self=NULL;
4 QMenuBar* SocExplorerGUI::m_mainMenuBar=NULL;
5 QMenu* SocExplorerGUI::m_fileMenu=NULL;
6 QMenu* SocExplorerGUI::m_SettingsMenu=NULL;
7 QList<QAction*>* SocExplorerGUI::m_queuedSettingActions=NULL;
8 QList<QAction*>* SocExplorerGUI::m_queuedFileMenuActions=NULL;
9
10 #define INIT() \
11 if(Q_UNLIKELY(_self==NULL))\
12 {\
13 init();\
14 }
15
16 SocExplorerGUI::SocExplorerGUI(QObject *parent) : QObject(parent)
17 {
18 m_queuedFileMenuActions = new QList<QAction*>();
19 m_queuedSettingActions = new QList<QAction*>();
20 }
21
22 void SocExplorerGUI::init()
23 {
24 _self=new SocExplorerGUI();
25 }
26
27 void SocExplorerGUI::registerMenuBar(QMenuBar *menuBar, QMenu *fileMenu, QMenu *SettingsMenu)
28 {
29 INIT();
30 m_mainMenuBar = menuBar;
31 if(m_mainMenuBar)
32 {
33 if(fileMenu==NULL)
34 m_fileMenu = m_mainMenuBar->addMenu(tr("File"));
35 else
36 m_fileMenu = fileMenu;
37 if(SettingsMenu==NULL)
38 m_SettingsMenu = m_mainMenuBar->addMenu(tr("Settings"));
39 else
40 m_SettingsMenu = SettingsMenu;
41 }
42
43 QAction* action;
44 foreach (action, *m_queuedSettingActions)
45 {
46 m_SettingsMenu->addAction(action);
47 }
48 foreach (action, *m_queuedFileMenuActions)
49 {
50 m_fileMenu->addAction(action);
51 }
52 }
53
54 QMenu *SocExplorerGUI::addMenu(const QString &title)
55 {
56 INIT();
57 if(m_mainMenuBar)
58 {
59 return m_mainMenuBar->addMenu(title);
60 }
61 return NULL;
62 }
63
64 bool SocExplorerGUI::addFileAction(QAction *action)
65 {
66 INIT();
67 if(m_fileMenu)
68 {
69 m_fileMenu->addAction(action);
70 return true;
71 }
72 else
73 {
74 m_queuedFileMenuActions->append(action);
75 }
76 return false;
77 }
78
79 bool SocExplorerGUI::addSettingsAction(QAction *action)
80 {
81 INIT();
82 if(m_SettingsMenu)
83 {
84 m_SettingsMenu->addAction(action);
85 return true;
86 }
87 else
88 {
89 m_queuedSettingActions->append(action);
90 }
91 return false;
92 }
93
@@ -0,0 +1,32
1 #ifndef SOCEXPLORERGUI_H
2 #define SOCEXPLORERGUI_H
3
4 #include <QObject>
5 #include <QWidget>
6 #include <QMenu>
7 #include <QMenuBar>
8 #include <QAction>
9
10 class SocExplorerGUI : public QObject
11 {
12 Q_OBJECT
13 static SocExplorerGUI* _self;
14 static QMenuBar* m_mainMenuBar;
15 static QMenu* m_fileMenu;
16 static QMenu* m_SettingsMenu;
17 static QList<QAction*>* m_queuedSettingActions;
18 static QList<QAction*>* m_queuedFileMenuActions;
19 SocExplorerGUI(QObject *parent = 0);
20 static void init();
21 public:
22 static SocExplorerGUI* self(){ if(!_self){_self= new SocExplorerGUI;}return _self;}
23 static void registerMenuBar(QMenuBar* menuBar, QMenu* fileMenu=NULL, QMenu* SettingsMenu=NULL);
24 static QMenu* addMenu(const QString & title);
25 static bool addFileAction(QAction * action);
26 static bool addSettingsAction(QAction * action);
27 signals:
28
29 public slots:
30 };
31
32 #endif // SOCEXPLORERGUI_H
@@ -0,0 +1,321
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 ----------------------------------------------------------------------------*/
22 #include "socexplorersettings.h"
23
24 SocExplorerSettings* SocExplorerSettings::_self=NULL;
25 QSettings* SocExplorerSettings::m_settings=NULL;
26 QSettings* SocExplorerSettings::m_sessionSettings=NULL;
27 SocExplorerSettingsDialog* SocExplorerSettings::m_configDialog = NULL;
28 #include <socexplorergui.h>
29 #include <QFile>
30 #include <QFileInfo>
31 #include <QDir>
32 #include <QDebug>
33
34 #define INIT() \
35 if(Q_UNLIKELY(_self==NULL))\
36 {\
37 init();\
38 }
39
40
41 SocExplorerSettings::SocExplorerSettings(QObject *parent) : QObject(parent)
42 {
43 m_settings = new QSettings();
44 m_configDialog = new SocExplorerSettingsDialog();
45 QAction* trigerGUI = new QAction(tr("Settings"),this);
46 connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog()));
47 SocExplorerGUI::addSettingsAction(trigerGUI);
48 }
49
50 SocExplorerSettings::~SocExplorerSettings()
51 {
52 if(m_settings)
53 {
54 m_settings->sync();
55 delete m_settings;
56 }
57 if(m_sessionSettings)
58 {
59 m_sessionSettings->sync();
60 delete m_sessionSettings;
61 }
62 }
63
64 void SocExplorerSettings::init()
65 {
66 if(!_self)
67 {
68 _self= new SocExplorerSettings();
69 }
70 }
71
72 void SocExplorerSettings::setValue(QObject *object, const QString &key, const QVariant &value, SettingScope Sscope)
73 {
74 INIT();
75 setValue(object->metaObject()->className(),key,value,Sscope);
76 }
77
78 QVariant SocExplorerSettings::value(QObject *object, const QString &key, const QVariant &defaultValue, SettingScope Sscope)
79 {
80 INIT();
81 return value(object->metaObject()->className(),key,defaultValue,Sscope);
82 }
83
84 void SocExplorerSettings::setValue(const QString scope, const QString &key, const QVariant &value, SettingScope Sscope)
85 {
86 INIT();
87 switch (Sscope)
88 {
89 case SystemWide:
90 if(m_settings)
91 m_settings->setValue(scope+"/"+key,value);
92 break;
93 case Session:
94 if(m_sessionSettings)
95 m_sessionSettings->setValue(scope+"/"+key,value);
96 break;
97 default:
98 break;
99 }
100 }
101
102 QVariant SocExplorerSettings::value(const QString scope, const QString &key, const QVariant &defaultValue, SettingScope Sscope)
103 {
104 INIT();
105 switch (Sscope)
106 {
107 case SystemWide:
108 if(m_settings)
109 return m_settings->value(scope+"/"+key,defaultValue);
110 break;
111 case Session:
112 if(m_sessionSettings)
113 return m_sessionSettings->value(scope+"/"+key,defaultValue);
114 break;
115 default:
116 break;
117 }
118 return defaultValue;
119 }
120
121 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, SocExplorerSettings::SettingScope Sscope)
122 {
123 INIT();
124 QList<QList<QVariant> > defaultValue;
125 switch (Sscope)
126 {
127 case SystemWide:
128 if(m_settings)
129 return arrays(prefix,keys,m_settings);
130 break;
131 case Session:
132 if(m_sessionSettings)
133 return arrays(prefix,keys,m_sessionSettings);
134 break;
135 default:
136 break;
137 }
138 return defaultValue;
139 }
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
160 void SocExplorerSettings::sync()
161 {
162 INIT();
163 if(m_settings)
164 {
165 m_settings->sync();
166 }
167 if(m_sessionSettings)
168 {
169 m_sessionSettings->sync();
170 }
171 }
172
173 bool SocExplorerSettings::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text)
174 {
175 INIT();
176 return m_configDialog->registerConfigEntry(configEntry,icon,text);
177 }
178
179 bool SocExplorerSettings::loadSession(const QString &session)
180 {
181 INIT();
182 QFileInfo sessionInfo(m_settings->fileName());
183 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
184 if(m_sessionSettings)
185 {
186 delete m_sessionSettings;
187 m_sessionSettings = NULL;
188 }
189 m_sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self());
190 qDebug()<< m_sessionSettings->fileName();
191 if(m_sessionSettings->status()==QSettings::NoError)
192 {
193 return true;
194 }
195 delete m_sessionSettings;
196 m_sessionSettings = NULL;
197 return false;
198 }
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
220 bool SocExplorerSettings::deleteSession()
221 {
222 INIT();
223 if(m_sessionSettings)
224 {
225 m_sessionSettings->clear();
226 QString filename= m_sessionSettings->fileName();
227 if(QFile::exists(filename))
228 {
229 delete m_sessionSettings;
230 QFile::remove(filename);
231 }
232 else
233 delete m_sessionSettings;
234 m_sessionSettings = NULL;
235 return true;
236 }
237 return false;
238 }
239
240 bool SocExplorerSettings::deleteSession(const QString &session)
241 {
242 QFileInfo sessionInfo(m_settings->fileName());
243 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
244 if(m_sessionSettings)
245 {
246 if(m_sessionSettings->fileName()==fullpath)
247 {
248 deleteSession();
249 return true;
250 }
251 }
252 QSettings* sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self());
253 if(sessionSettings)
254 {
255 if(sessionSettings->status()==QSettings::NoError)
256 {
257 sessionSettings->clear();
258 QString filename= m_sessionSettings->fileName();
259 if(QFile::exists(filename))
260 {
261 delete sessionSettings;
262 QFile::remove(filename);
263 }
264 else
265 delete sessionSettings;
266 return true;
267 }
268 delete sessionSettings;
269 }
270 return false;
271 }
272
273 void SocExplorerSettings::popConfigDialog()
274 {
275 m_configDialog->popConfigDialog(NULL);
276 }
277
278 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, QSettings *settings)
279 {
280 QList<QList<QVariant> > result;
281 if(settings)
282 {
283 int size = settings->beginReadArray(prefix);
284 for (int i = 0; i < size; ++i)
285 {
286 result.append(QList<QVariant>());
287 settings->setArrayIndex(i);
288 for(int l=0;l<keys.count();l++)
289 {
290 result[i].append(settings->value(keys.at(l)));
291 }
292 }
293 settings->endArray();
294 }
295 return result;
296 }
297
298 void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, QSettings *settings)
299 {
300 if(settings)
301 {
302 QString key;
303 foreach (key, keys)
304 {
305
306 settings->remove(prefix+"/"+key);
307 }
308 settings->beginWriteArray(prefix);
309 for (int i = 0; i < values.size(); ++i)
310 {
311 settings->setArrayIndex(i);
312 for(int l=0;l<keys.count();l++)
313 {
314 settings->setValue(keys[l], values.at(i).at(l));
315 }
316 }
317 settings->endArray();
318
319 }
320 }
321
@@ -0,0 +1,71
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, 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 ----------------------------------------------------------------------------*/
22 #ifndef SOCEXPLORERSETTINGS_H
23 #define SOCEXPLORERSETTINGS_H
24
25 #include <QObject>
26 #include <QWidget>
27 #include <QSettings>
28 #include <socexplorersettingsdialog.h>
29
30 class SocExplorerSettings : public QObject
31 {
32 Q_OBJECT
33 private:
34 static SocExplorerSettings* _self;
35 static QSettings* m_settings;
36 static QSettings* m_sessionSettings;
37 static SocExplorerSettingsDialog* m_configDialog;
38 SocExplorerSettings(QObject *parent = 0);
39 ~SocExplorerSettings();
40 public:
41 enum SettingScope {
42 SystemWide = 0,
43 Session
44 };
45 static void init();
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);
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);
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);
52 static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,SettingScope Sscope =SystemWide);
53 static void sync();
54 static bool registerConfigEntry(SocExplorerSettingsItem* configEntry,QIcon icon, QString text);
55 //! Loads the given session, or sreate it if doesn't exists.
56 //! \param session Session name.
57 //! \return true if success or false if fails to create session config file.
58 static bool loadSession(const QString& session);
59 static bool renameSession(const QString& session,const QString& newName);
60 static bool deleteSession();
61 static bool deleteSession(const QString& session);
62 signals:
63
64 public slots:
65 void popConfigDialog();
66 private:
67 static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,QSettings* settings);
68 static void setArrays(const QString & prefix, QStringList keys,QList<QList<QVariant> > values,QSettings* settings);
69 };
70
71 #endif // SOCEXPLORERSETTINGS_H
@@ -0,0 +1,69
1 #include "socexplorersettingsdialog.h"
2 #include "ui_socexplorersettingsdialog.h"
3
4 SocExplorerSettingsDialog::SocExplorerSettingsDialog(QWidget *parent) :
5 QDialog(parent),
6 ui(new Ui::SocExplorerSettingsDialog)
7 {
8 ui->setupUi(this);
9 connect(ui->contentsWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*)));
10 ui->contentsWidget->setViewMode(QListView::IconMode);
11 ui->contentsWidget->setIconSize(QSize(96, 84));
12 ui->contentsWidget->setMovement(QListView::Static);
13 ui->contentsWidget->setSpacing(12);
14 }
15
16 SocExplorerSettingsDialog::~SocExplorerSettingsDialog()
17 {
18 delete ui;
19 }
20
21 void SocExplorerSettingsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
22 {
23 if (!current)
24 current = previous;
25 ui->pagesWidget->setCurrentIndex(ui->contentsWidget->row(current));
26 }
27
28 bool SocExplorerSettingsDialog::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text)
29 {
30 if(configEntry!=NULL)
31 {
32 ui->pagesWidget->addWidget(configEntry);
33 QListWidgetItem *configButton = new QListWidgetItem(ui->contentsWidget);
34 configButton->setIcon(icon);
35 configButton->setText(text);
36 configButton->setTextAlignment(Qt::AlignHCenter);
37 configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
38 connect(this,SIGNAL(accepted()),configEntry,SLOT(accept()));
39 return true;
40 }
41 return false;
42 }
43
44 void SocExplorerSettingsDialog::popConfigDialog(SocExplorerSettingsItem *selectedConfigEntry)
45 {
46 if(selectedConfigEntry!=NULL)
47 {
48 for(int i=0;i<ui->pagesWidget->count();i++)
49 {
50 if(ui->pagesWidget->widget(i)==selectedConfigEntry)
51 {
52 ui->pagesWidget->setCurrentIndex(i);
53 }
54 }
55 }
56 this->show();
57 }
58
59 void SocExplorerSettingsDialog::changeEvent(QEvent *e)
60 {
61 QDialog::changeEvent(e);
62 switch (e->type()) {
63 case QEvent::LanguageChange:
64 ui->retranslateUi(this);
65 break;
66 default:
67 break;
68 }
69 }
@@ -0,0 +1,41
1 #ifndef SOCEXPLORERSETTINGSDIALOG_H
2 #define SOCEXPLORERSETTINGSDIALOG_H
3
4 #include <QDialog>
5
6 namespace Ui {
7 class SocExplorerSettingsDialog;
8 }
9 #include <QListWidgetItem>
10
11 class SocExplorerSettingsItem : public QWidget
12 {
13 Q_OBJECT
14 public:
15 SocExplorerSettingsItem(QWidget *parent = 0):QWidget(parent) {}
16 ~SocExplorerSettingsItem() {}
17 public slots:
18 virtual void accept()=0;
19 };
20
21 class SocExplorerSettingsDialog : public QDialog
22 {
23 Q_OBJECT
24
25 public:
26 explicit SocExplorerSettingsDialog(QWidget *parent = 0);
27 ~SocExplorerSettingsDialog();
28
29 public slots:
30 void changePage(QListWidgetItem *current, QListWidgetItem *previous);
31 bool registerConfigEntry(SocExplorerSettingsItem* configEntry, QIcon icon, QString text);
32 void popConfigDialog(SocExplorerSettingsItem* selectedConfigEntry=0);
33
34 protected:
35 void changeEvent(QEvent *e);
36
37 private:
38 Ui::SocExplorerSettingsDialog *ui;
39 };
40
41 #endif // SOCEXPLORERSETTINGSDIALOG_H
@@ -0,0 +1,102
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>SocExplorerSettingsDialog</class>
4 <widget class="QDialog" name="SocExplorerSettingsDialog">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>555</width>
10 <height>329</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>Dialog</string>
15 </property>
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="1">
18 <widget class="QListWidget" name="contentsWidget">
19 <property name="sizePolicy">
20 <sizepolicy hsizetype="Maximum" vsizetype="Expanding">
21 <horstretch>0</horstretch>
22 <verstretch>0</verstretch>
23 </sizepolicy>
24 </property>