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