##// END OF EJS Templates
Pre-0.7 merged
Alexis Jeandet -
r107:c459540a6dbd merge 0.6
parent child
Show More
@@ -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>
25 <property name="minimumSize">
26 <size>
27 <width>100</width>
28 <height>0</height>
29 </size>
30 </property>
31 <property name="maximumSize">
32 <size>
33 <width>16777215</width>
34 <height>16777215</height>
35 </size>
36 </property>
37 </widget>
38 </item>
39 <item row="0" column="2">
40 <widget class="QStackedWidget" name="pagesWidget">
41 <property name="sizePolicy">
42 <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
43 <horstretch>0</horstretch>
44 <verstretch>0</verstretch>
45 </sizepolicy>
46 </property>
47 <property name="minimumSize">
48 <size>
49 <width>100</width>
50 <height>0</height>
51 </size>
52 </property>
53 </widget>
54 </item>
55 <item row="2" column="1" colspan="2">
56 <widget class="QDialogButtonBox" name="buttonBox">
57 <property name="orientation">
58 <enum>Qt::Horizontal</enum>
59 </property>
60 <property name="standardButtons">
61 <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
62 </property>
63 </widget>
64 </item>
65 </layout>
66 </widget>
67 <resources/>
68 <connections>
69 <connection>
70 <sender>buttonBox</sender>
71 <signal>accepted()</signal>
72 <receiver>SocExplorerSettingsDialog</receiver>
73 <slot>accept()</slot>
74 <hints>
75 <hint type="sourcelabel">
76 <x>277</x>
77 <y>304</y>
78 </hint>
79 <hint type="destinationlabel">
80 <x>277</x>
81 <y>164</y>
82 </hint>
83 </hints>
84 </connection>
85 <connection>
86 <sender>buttonBox</sender>
87 <signal>rejected()</signal>
88 <receiver>SocExplorerSettingsDialog</receiver>
89 <slot>reject()</slot>
90 <hints>
91 <hint type="sourcelabel">
92 <x>277</x>
93 <y>304</y>
94 </hint>
95 <hint type="destinationlabel">
96 <x>277</x>
97 <y>164</y>
98 </hint>
99 </hints>
100 </connection>
101 </connections>
102 </ui>
@@ -0,0 +1,181
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 "sessionmanagerdialog.h"
23 #include "ui_sessionmanagerdialog.h"
24 #include <socexplorersettings.h>
25 #include <socexplorerconfigkeys.h>
26 #include <QInputDialog>
27 #include <QMessageBox>
28
29 SessionManagerDialog::SessionManagerDialog(QWidget *parent) :
30 QDialog(parent),
31 ui(new Ui::SessionManagerDialog)
32 {
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()));
36 connect(this->ui->RenameQPB,SIGNAL(clicked(bool)),this,SLOT(renameSession()));
37 connect(this->ui->SwitchToQPB,SIGNAL(clicked(bool)),this,SLOT(switchSession()));
38 }
39
40 SessionManagerDialog::~SessionManagerDialog()
41 {
42 delete ui;
43 }
44
45
46 QStringList SessionManagerDialog::getSessionsList()
47 {
48 QStringList result;
49 QList<QList<QVariant> > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME);
50 for(int i=0;i<sessions.count();i++)
51 {
52 if(sessions.at(i).count()>=1)
53 {
54 result.append(sessions.at(i).at(0).toString());
55 }
56 }
57 // May always return at least default session
58 if(result.count()==0)
59 {
60 result.append("default");
61 }
62 return result;
63 }
64
65 void SessionManagerDialog::show()
66 {
67 QStringList sessions = getSessionsList();
68 this->ui->listWidget->clear();
69 this->ui->listWidget->addItems(sessions);
70 QDialog::show();
71 }
72
73 void SessionManagerDialog::newSession()
74 {
75 bool ok=true,exists=false;
76 QString text;
77 do
78 {
79 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
80 tr("Session name:"), QLineEdit::Normal,
81 "New Session", &ok);
82 exists = sessionExists(text);
83 if(exists && ok)
84 {
85 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
86 tr("The session ")+text+tr(" already exists."),
87 QMessageBox::Ok);
88 }
89 }while(ok && (text.isEmpty() || exists));
90
91 if (ok && !text.isEmpty())
92 {
93 this->newSession(text);
94 }
95 }
96
97 void SessionManagerDialog::newSession(QString session)
98 {
99 if (!session.isEmpty())
100 {
101 this->ui->listWidget->addItem(session);
102 updateSessionList();
103 emit sessionAdded(session);
104 }
105 }
106
107 void SessionManagerDialog::renameSession()
108 {
109 bool ok=true;
110 int exists=0;
111 QListWidgetItem* item = this->ui->listWidget->currentItem();
112 QString text= item->text();
113 QString OldText= item->text();
114 do
115 {
116 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
117 tr("New session name:"), QLineEdit::Normal,
118 text, &ok);
119 exists = sessionExists(text);
120 if(exists&& ok)
121 {
122 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
123 tr("The session ")+text+tr(" already exists."),
124 QMessageBox::Ok);
125 }
126 }while(ok && text.isEmpty());
127
128 if (ok && !text.isEmpty())
129 {
130 item->setText(text);
131 SocExplorerSettings::renameSession(OldText,text);
132 emit sessionRenamed(OldText,text);
133 updateSessionList();
134 emit sessionListChanged();
135 }
136 }
137
138 void SessionManagerDialog::deleteSession()
139 {
140 if(this->ui->listWidget->selectedItems().count())
141 {
142 QListWidgetItem* item = this->ui->listWidget->currentItem();
143 if(item && item->text().compare("default"))
144 {
145 this->ui->listWidget->removeItemWidget(item);
146 SocExplorerSettings::deleteSession(item->text());
147 emit sessionRemoved(item->text());
148 delete item;
149 updateSessionList();
150 }
151 }
152 }
153
154 void SessionManagerDialog::switchSession()
155 {
156 QListWidgetItem* item = this->ui->listWidget->currentItem();
157 if(item)
158 emit switchSession(item->text());
159 }
160
161 int SessionManagerDialog::sessionExists(QString session)
162 {
163 int exists=0;
164 for(int i=0;i< this->ui->listWidget->count();i++)
165 {
166 exists += (this->ui->listWidget->item(i)->text().compare(session)==0);
167 }
168 return exists;
169 }
170
171 void SessionManagerDialog::updateSessionList()
172 {
173 QList<QList<QVariant> > sessions;
174 for(int i=0;i< this->ui->listWidget->count();i++)
175 {
176 QList<QVariant> sess;
177 sess.append(this->ui->listWidget->item(i)->text());
178 sessions.append(sess);
179 }
180 SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME,sessions);
181 }
@@ -0,0 +1,60
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 #ifndef SESSIONMANAGERDIALOG_H
23 #define SESSIONMANAGERDIALOG_H
24
25 #include <QDialog>
26
27 namespace Ui {
28 class SessionManagerDialog;
29 }
30
31 class SessionManagerDialog : public QDialog
32 {
33 Q_OBJECT
34
35 public:
36 explicit SessionManagerDialog(QWidget *parent = 0);
37 ~SessionManagerDialog();
38
39 QStringList getSessionsList();
40 public slots:
41 void show();
42 void newSession(QString session);
43 int sessionExists(QString session);
44 private slots:
45 void newSession();
46 void renameSession();
47 void deleteSession();
48 void switchSession();
49 signals:
50 void switchSession(QString session);
51 void sessionListChanged();
52 void sessionRenamed(const QString& oldName,const QString& newName);
53 void sessionRemoved(const QString& session);
54 void sessionAdded(const QString& newSession);
55 private:
56 void updateSessionList();
57 Ui::SessionManagerDialog *ui;
58 };
59
60 #endif // SESSIONMANAGERDIALOG_H
@@ -0,0 +1,127
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>SessionManagerDialog</class>
4 <widget class="QDialog" name="SessionManagerDialog">
5 <property name="windowModality">
6 <enum>Qt::ApplicationModal</enum>
7 </property>
8 <property name="geometry">
9 <rect>
10 <x>0</x>
11 <y>0</y>
12 <width>553</width>
13 <height>275</height>
14 </rect>
15 </property>
16 <property name="windowTitle">
17 <string>SocExplorer Session Manager</string>
18 </property>
19 <property name="modal">
20 <bool>true</bool>
21 </property>
22 <layout class="QGridLayout" name="gridLayout">
23 <item row="0" column="0">
24 <widget class="QListWidget" name="listWidget"/>
25 </item>
26 <item row="0" column="1">
27 <widget class="QWidget" name="widget" native="true">
28 <layout class="QVBoxLayout" name="verticalLayout">
29 <item>
30 <widget class="QPushButton" name="NewQPB">
31 <property name="text">
32 <string>New</string>
33 </property>
34 </widget>
35 </item>
36 <item>
37 <widget class="QPushButton" name="RenameQPB">
38 <property name="text">
39 <string>Rename</string>
40 </property>
41 </widget>
42 </item>
43 <item>
44 <widget class="QPushButton" name="CloneQPB">
45 <property name="text">
46 <string>Clone</string>
47 </property>
48 </widget>
49 </item>
50 <item>
51 <widget class="QPushButton" name="DeleteQPB">
52 <property name="text">
53 <string>Delete</string>
54 </property>
55 </widget>
56 </item>
57 <item>
58 <widget class="QPushButton" name="SwitchToQPB">
59 <property name="text">
60 <string>Switch to</string>
61 </property>
62 </widget>
63 </item>
64 <item>
65 <spacer name="verticalSpacer">
66 <property name="orientation">
67 <enum>Qt::Vertical</enum>
68 </property>
69 <property name="sizeHint" stdset="0">
70 <size>
71 <width>20</width>
72 <height>40</height>
73 </size>
74 </property>
75 </spacer>
76 </item>
77 </layout>
78 </widget>
79 </item>
80 <item row="1" column="0" colspan="2">
81 <widget class="QDialogButtonBox" name="buttonBox">
82 <property name="orientation">
83 <enum>Qt::Horizontal</enum>
84 </property>
85 <property name="standardButtons">
86 <set>QDialogButtonBox::Close</set>
87 </property>
88 </widget>
89 </item>
90 </layout>
91 </widget>
92 <resources/>
93 <connections>
94 <connection>
95 <sender>buttonBox</sender>
96 <signal>accepted()</signal>
97 <receiver>SessionManagerDialog</receiver>
98 <slot>accept()</slot>
99 <hints>
100 <hint type="sourcelabel">
101 <x>248</x>
102 <y>254</y>
103 </hint>
104 <hint type="destinationlabel">
105 <x>157</x>
106 <y>274</y>
107 </hint>
108 </hints>
109 </connection>
110 <connection>
111 <sender>buttonBox</sender>
112 <signal>rejected()</signal>
113 <receiver>SessionManagerDialog</receiver>
114 <slot>reject()</slot>
115 <hints>
116 <hint type="sourcelabel">
117 <x>316</x>
118 <y>260</y>
119 </hint>
120 <hint type="destinationlabel">
121 <x>286</x>
122 <y>274</y>
123 </hint>
124 </hints>
125 </connection>
126 </connections>
127 </ui>
@@ -0,0 +1,37
1 #include "socexplorercoresettingsgui.h"
2 #include "ui_socexplorercoresettingsgui.h"
3 #include <socexplorersettings.h>
4 #include <socexplorerengine.h>
5 #include <socexplorerconfigkeys.h>
6
7 SocExplorerCoreSettingsGUI::SocExplorerCoreSettingsGUI(QWidget *parent) :
8 SocExplorerSettingsItem(parent),
9 ui(new Ui::SocExplorerCoreSettingsGUI)
10 {
11 ui->setupUi(this);
12 this->ui->PluginsLookupPath->setText(SocExplorerSettings::value(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_PLUGINS_LOOKUP_PATH,"").toString());
13 this->ui->SOCregsLookupPath->setText(SocExplorerSettings::value(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_SOC_REGS_LOOKUP_PATH,"").toString());
14 }
15
16 SocExplorerCoreSettingsGUI::~SocExplorerCoreSettingsGUI()
17 {
18 delete ui;
19 }
20
21 void SocExplorerCoreSettingsGUI::changeEvent(QEvent *e)
22 {
23 QWidget::changeEvent(e);
24 switch (e->type()) {
25 case QEvent::LanguageChange:
26 ui->retranslateUi(this);
27 break;
28 default:
29 break;
30 }
31 }
32
33 void SocExplorerCoreSettingsGUI::accept()
34 {
35 SocExplorerSettings::setValue(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_PLUGINS_LOOKUP_PATH,this->ui->PluginsLookupPath->text());
36 SocExplorerSettings::setValue(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_SOC_REGS_LOOKUP_PATH,this->ui->SOCregsLookupPath->text());
37 }
@@ -0,0 +1,27
1 #ifndef SOCEXPLORERCORESETTINGSGUI_H
2 #define SOCEXPLORERCORESETTINGSGUI_H
3
4 #include <QWidget>
5 #include <socexplorersettingsdialog.h>
6
7 namespace Ui {
8 class SocExplorerCoreSettingsGUI;
9 }
10
11 class SocExplorerCoreSettingsGUI : public SocExplorerSettingsItem
12 {
13 Q_OBJECT
14
15 public:
16 explicit SocExplorerCoreSettingsGUI(QWidget *parent = 0);
17 ~SocExplorerCoreSettingsGUI();
18
19 protected:
20 void changeEvent(QEvent *e);
21 public slots:
22 void accept();
23 private:
24 Ui::SocExplorerCoreSettingsGUI *ui;
25 };
26
27 #endif // SOCEXPLORERCORESETTINGSGUI_H
@@ -0,0 +1,80
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>SocExplorerCoreSettingsGUI</class>
4 <widget class="QWidget" name="SocExplorerCoreSettingsGUI">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>573</width>
10 <height>274</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>Form</string>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <item>
18 <widget class="QGroupBox" name="groupBox">
19 <property name="title">
20 <string>Plugins</string>
21 </property>
22 <layout class="QFormLayout" name="formLayout">
23 <item row="0" column="0">
24 <widget class="QLabel" name="label">
25 <property name="text">
26 <string>Lookup path</string>
27 </property>
28 </widget>
29 </item>
30 <item row="0" column="1">
31 <widget class="QLineEdit" name="PluginsLookupPath">
32 <property name="toolTip">
33 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Semicolon &lt;/span&gt;separated list of path.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
34 </property>
35 </widget>
36 </item>
37 </layout>
38 </widget>
39 </item>
40 <item>
41 <widget class="QGroupBox" name="groupBox_2">
42 <property name="title">
43 <string>SOC registers description</string>
44 </property>
45 <layout class="QFormLayout" name="formLayout_2">
46 <item row="0" column="0">
47 <widget class="QLabel" name="label_2">
48 <property name="text">
49 <string>Lookup path</string>
50 </property>
51 </widget>
52 </item>
53 <item row="0" column="1">
54 <widget class="QLineEdit" name="SOCregsLookupPath">
55 <property name="toolTip">
56 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Semicolon &lt;/span&gt;separated list of path.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
57 </property>
58 </widget>
59 </item>
60 </layout>
61 </widget>
62 </item>
63 <item>
64 <spacer name="verticalSpacer">
65 <property name="orientation">
66 <enum>Qt::Vertical</enum>
67 </property>
68 <property name="sizeHint" stdset="0">
69 <size>
70 <width>20</width>
71 <height>40</height>
72 </size>
73 </property>
74 </spacer>
75 </item>
76 </layout>
77 </widget>
78 <resources/>
79 <connections/>
80 </ui>
@@ -1,17 +1,17
1 [Desktop Entry]
1 [Desktop Entry]
2 Version=1.0
2 Version=1.0
3 Name=SocExplorer
3 Name=SocExplorer
4 Name[en_US]=SocExplorer
4 Name[en_US]=SocExplorer
5
5
6 Type=Application
6 Type=Application
7 GenericName=Soc Explorer
7 GenericName=Soc Explorer
8
8
9 Comment=Software to monitor and explore Soc devices.
9 Comment=Software to monitor and explore Soc devices.
10
10
11 Exec=socexplorer %U
11 Exec=socexplorer %U
12 Icon=/usr/share/SocExplorer/icon.png
12 Icon=/usr/share/SocExplorer/icon.png
13 Terminal=false
13 Terminal=false
14
14
15 Categories=Electronics;Engineering;
15 Categories=Development;Engineering;
16
16
17 MimeType=text/x-python;
17 MimeType=text/x-python;
General Comments 0
You need to be logged in to leave comments. Login now