##// END OF EJS Templates
Session manager ready for release.
jeandet -
r97:9f8fee223cb9 default
parent child
Show More
@@ -1,339 +1,367
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 this->makeConnections();
37 this->makeConnections();
38 this->setWindowIcon(QIcon(":/images/icon.png"));
38 this->setWindowIcon(QIcon(":/images/icon.png"));
39 this->setAcceptDrops(true);
39 this->setAcceptDrops(true);
40 this->pluginManager->setRootLoadable(true);
40 this->pluginManager->setRootLoadable(true);
41 this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval);
41 this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval);
42 QFile file(":/styles/SocExplorer.css");
42 QFile file(":/styles/SocExplorer.css");
43 if(file.open(QIODevice::ReadOnly | QIODevice::Text))
43 if(file.open(QIODevice::ReadOnly | QIODevice::Text))
44 {
44 {
45 qApp->setStyleSheet(file.readAll());
45 qApp->setStyleSheet(file.readAll());
46 file.close();
46 file.close();
47 }
47 }
48 }
48 }
49
49
50
50
51 void SocExplorerMainWindow::makeObjects(QString ScriptToEval)
51 void SocExplorerMainWindow::makeObjects(QString ScriptToEval)
52 {
52 {
53 Q_UNUSED(ScriptToEval)
53 Q_UNUSED(ScriptToEval)
54 this->p_pluginGUIlist = new QList<QDockWidget*>();
54 this->p_pluginGUIlist = new QList<QDockWidget*>();
55 pluginsDockContainer = new QMainWindow;
55 pluginsDockContainer = new QMainWindow;
56 pluginsDockContainer->setObjectName("pluginsDockContainer");
56 pluginsDockContainer->setObjectName("pluginsDockContainer");
57 pluginsDockContainer->setWindowFlags(Qt::Widget);
57 pluginsDockContainer->setWindowFlags(Qt::Widget);
58 pluginsDockContainer->setDockNestingEnabled(true);
58 pluginsDockContainer->setDockNestingEnabled(true);
59 this->sessionsActions = new QActionGroup(this);
59 this->sessionsActions = new QActionGroup(this);
60 this->sessionManagerAction =new QAction(tr("&Session manager"),this);
60 this->sessionManagerAction =new QAction(tr("&Session manager"),this);
61 this->mainWidget = new QSplitter(Qt::Vertical);
61 this->mainWidget = new QSplitter(Qt::Vertical);
62 this->appTranslator = new QTranslator;
62 this->appTranslator = new QTranslator;
63 this->Quit = new QAction(tr("&Quit"),this);
63 this->Quit = new QAction(tr("&Quit"),this);
64 this->Quit->setShortcut(tr("CTRL+Q"));
64 this->Quit->setShortcut(tr("CTRL+Q"));
65 this->ManagePlugins = new QAction(tr("&Manage Plugins"),this);
65 this->ManagePlugins = new QAction(tr("&Manage Plugins"),this);
66 this->ManagePlugins->setShortcut(tr("CTRL+P"));
66 this->ManagePlugins->setShortcut(tr("CTRL+P"));
67 this->regsManager = new QAction(tr("&Manage registers"),this);
67 this->regsManager = new QAction(tr("&Manage registers"),this);
68 this->exploreRegs = new QAction(tr("&Explore registers"),this);
68 this->exploreRegs = new QAction(tr("&Explore registers"),this);
69 this->help = new QAction(tr("&Help"),this);
69 this->help = new QAction(tr("&Help"),this);
70 this->help->setShortcut(tr("CTRL+H"));
70 this->help->setShortcut(tr("CTRL+H"));
71 this->about = new QAction(tr("&About"),this);
71 this->about = new QAction(tr("&About"),this);
72 this->p_SessionManagerDialog = new SessionManagerDialog();
72 this->p_SessionManagerDialog = new SessionManagerDialog();
73 socexplorerproxy::setMainWindow(this);
73 socexplorerproxy::setMainWindow(this);
74 SocExplorerEngine::setMainWindow(this);
74 SocExplorerEngine::setMainWindow(this);
75 SocExplorerEngine::xmlModel()->scanXmlFiles();
75 SocExplorerEngine::xmlModel()->scanXmlFiles();
76 this->regExplorer = new RegsExplorer();
76 this->regExplorer = new RegsExplorer();
77 this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas);
77 this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas);
78 this->regExplorer->setObjectName("regExplorer");
78 this->regExplorer->setObjectName("regExplorer");
79 this->addPluginInterface(this->regExplorer);
79 this->addPluginInterface(this->regExplorer);
80 this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self());
80 this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self());
81 this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self());
81 this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self());
82 this->pluginManager = new dockablePluginManager();
82 this->pluginManager = new dockablePluginManager();
83 this->toolpane = new toolBar;
83 this->toolpane = new toolBar;
84 this->toolpane->setObjectName("toolpane");
84 this->toolpane->setObjectName("toolpane");
85 this->p_about = new aboutsocexplorer();
85 this->p_about = new aboutsocexplorer();
86 }
86 }
87
87
88 void SocExplorerMainWindow::makeLayout()
88 void SocExplorerMainWindow::makeLayout()
89 {
89 {
90 this->mainWidget->addWidget(pluginsDockContainer);
90 this->mainWidget->addWidget(pluginsDockContainer);
91 this->mainWidget->addWidget(this->PythonConsoleInst);
91 this->mainWidget->addWidget(this->PythonConsoleInst);
92 this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
92 this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
93 this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane);
93 this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane);
94 this->toolpane->addTool(this->pluginManager);
94 this->toolpane->addTool(this->pluginManager);
95 this->setCentralWidget(this->mainWidget);
95 this->setCentralWidget(this->mainWidget);
96 }
96 }
97
97
98
98
99 void SocExplorerMainWindow::makeConnections()
99 void SocExplorerMainWindow::makeConnections()
100 {
100 {
101 connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu()));
101 connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu()));
102 connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText()));
102 connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText()));
103 connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*)));
103 connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*)));
104 connect(socexplorerproxy::self(),SIGNAL(removePluginGUI(QDockWidget*)),this,SLOT(removePluginInterface(QDockWidget*)));
104 connect(socexplorerproxy::self(),SIGNAL(removePluginGUI(QDockWidget*)),this,SLOT(removePluginInterface(QDockWidget*)));
105 connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager()));
105 connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager()));
106 connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit()));
106 connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit()));
107 connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString)));
107 connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString)));
108 connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString)));
108 connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString)));
109 connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree()));
109 connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree()));
110 connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
110 connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
111 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString)));
111 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString)));
112 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString)));
112 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString)));
113 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString)));
113 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString)));
114 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString)));
114 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString)));
115 connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString)));
115 connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString)));
116 connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox()));
116 connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox()));
117 connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show()));
117 connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show()));
118
118
119 connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this,SLOT(showSessionManager(bool)));
119 connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this,SLOT(showSessionManager(bool)));
120 connect(this->p_SessionManagerDialog, SIGNAL(switchSession(QString)),this,SLOT(setActiveSession(QString)));
120 connect(this->p_SessionManagerDialog, SIGNAL(switchSession(QString)),this,SLOT(setActiveSession(QString)));
121 connect(this->p_SessionManagerDialog, SIGNAL(sessionRenamed(QString,QString)),this,SLOT(renameSession(QString,QString)));
122 connect(this->p_SessionManagerDialog, SIGNAL(sessionAdded(QString)),this,SLOT(addSession(QString)));
123 connect(this->p_SessionManagerDialog, SIGNAL(sessionRemoved(QString)),this,SLOT(removeSession(QString)));
121 connect(this->sessionsActions,SIGNAL(triggered(QAction*)),this,SLOT(setActiveSession(QAction*)));
124 connect(this->sessionsActions,SIGNAL(triggered(QAction*)),this,SLOT(setActiveSession(QAction*)));
122
125
123 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString)));
126 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString)));
124 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString)));
127 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString)));
125
128
126 }
129 }
127
130
128
131
129 void SocExplorerMainWindow::launchPluginManager()
132 void SocExplorerMainWindow::launchPluginManager()
130 {
133 {
131 if(this->pluginManager->isHidden())
134 if(this->pluginManager->isHidden())
132 {
135 {
133 this->pluginManager->setHidden(false);
136 this->pluginManager->setHidden(false);
134 }
137 }
135 }
138 }
136
139
137
140
138 void SocExplorerMainWindow::addPluginInterface(QDockWidget *plugin)
141 void SocExplorerMainWindow::addPluginInterface(QDockWidget *plugin)
139 {
142 {
140 plugin->setAllowedAreas(Qt::AllDockWidgetAreas);
143 plugin->setAllowedAreas(Qt::AllDockWidgetAreas);
141 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin);
144 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin);
142 if(p_pluginGUIlist->count()!=0)
145 if(p_pluginGUIlist->count()!=0)
143 this->pluginsDockContainer->tabifyDockWidget(p_pluginGUIlist->last(),plugin);
146 this->pluginsDockContainer->tabifyDockWidget(p_pluginGUIlist->last(),plugin);
144 p_pluginGUIlist->append(plugin);
147 p_pluginGUIlist->append(plugin);
145 }
148 }
146
149
147 void SocExplorerMainWindow::removePluginInterface(QDockWidget *plugin)
150 void SocExplorerMainWindow::removePluginInterface(QDockWidget *plugin)
148 {
151 {
149 p_pluginGUIlist->removeOne(plugin);
152 p_pluginGUIlist->removeOne(plugin);
150 this->pluginsDockContainer->removeDockWidget(plugin);
153 this->pluginsDockContainer->removeDockWidget(plugin);
151 }
154 }
152
155
153
156
154 void SocExplorerMainWindow::clearMenu()
157 void SocExplorerMainWindow::clearMenu()
155 {
158 {
156 this->menuBar()->clear();
159 this->menuBar()->clear();
157 this->makeMenu();
160 this->makeMenu();
158 }
161 }
159
162
160
163
161 void SocExplorerMainWindow::makeMenu()
164 void SocExplorerMainWindow::makeMenu()
162 {
165 {
163 this->FileMenu = menuBar()->addMenu(tr("&File"));
166 this->FileMenu = menuBar()->addMenu(tr("&File"));
164 this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions"));
167 this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions"));
165 this->loadSessions();
168 this->loadSessions();
166 this->FileMenu->addAction(this->sessionManagerAction);
169 this->FileMenu->addAction(this->sessionManagerAction);
167 this->SettingsMenu = menuBar()->addMenu(tr("&Settings"));
170 this->SettingsMenu = menuBar()->addMenu(tr("&Settings"));
168 SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu);
171 SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu);
169 this->PluginsMenu = menuBar()->addMenu(tr("&Plugins"));
172 this->PluginsMenu = menuBar()->addMenu(tr("&Plugins"));
170 this->ToolsMenu = menuBar()->addMenu(tr("&Tools"));
173 this->ToolsMenu = menuBar()->addMenu(tr("&Tools"));
171 this->ToolsMenu->addAction(this->exploreRegs);
174 this->ToolsMenu->addAction(this->exploreRegs);
172 this->FileMenu->addAction(this->Quit);
175 this->FileMenu->addAction(this->Quit);
173 socexplorerproxy::self()->makeMenu(this->PluginsMenu);
176 socexplorerproxy::self()->makeMenu(this->PluginsMenu);
174 this->PluginsMenu->addAction(this->ManagePlugins);
177 this->PluginsMenu->addAction(this->ManagePlugins);
175
178
176 this->helpMenu = menuBar()->addMenu(tr("Help"));
179 this->helpMenu = menuBar()->addMenu(tr("Help"));
177 this->helpMenu->addAction(this->help);
180 this->helpMenu->addAction(this->help);
178 this->helpMenu->addAction(this->about);
181 this->helpMenu->addAction(this->about);
179
182
180 }
183 }
181
184
182 void SocExplorerMainWindow::loadSessions()
185 void SocExplorerMainWindow::loadSessions()
183 {
186 {
184 p_Sessions=this->p_SessionManagerDialog->getSessionsList();
187 p_Sessions=this->p_SessionManagerDialog->getSessionsList();
185 QAction* sact;
188 QAction* sact;
186 QString stext;
189 QString stext;
187 QList<QAction*> sessions=sessionsActions->actions();
190 QList<QAction*> sessions=sessionsActions->actions();
188 foreach (sact, sessions)
191 foreach (sact, sessions)
189 {
192 {
190 sessionsActions->removeAction(sact);
193 sessionsActions->removeAction(sact);
191 SessionsMenu->removeAction(sact);
194 SessionsMenu->removeAction(sact);
192 delete sact;
195 delete sact;
193 }
196 }
194 foreach (stext, p_Sessions)
197 foreach (stext, p_Sessions)
195 {
198 {
196 sact = new QAction(stext,this);
199 addSession(stext);
197 sact->setCheckable(true);
198 sact->setData(stext);
199 if(p_currentSession==stext)
200 sact->setChecked(true);
201 sessionsActions->addAction(sact);
202 SessionsMenu->addAction(sact);
203 }
200 }
204 }
201 }
205
202
206 void SocExplorerMainWindow::savePlugins()
203 void SocExplorerMainWindow::savePlugins()
207 {
204 {
208
205
209 }
206 }
210
207
211 void SocExplorerMainWindow::saveCurrentSession()
208 void SocExplorerMainWindow::saveCurrentSession()
212 {
209 {
213 if(p_currentSession.isEmpty())
210 if(p_currentSession.isEmpty())
214 {
211 {
215 SocExplorerSettings::loadSession("default");
212 SocExplorerSettings::loadSession("default");
216 }
213 }
217 SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session);
214 SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session);
218 SocExplorerSettings::setValue(this,"DOCK_LOCATIONS",this->saveState(0),SocExplorerSettings::Session);
215 SocExplorerSettings::setValue(this,"DOCK_LOCATIONS",this->saveState(0),SocExplorerSettings::Session);
219 SocExplorerSettings::setValue(this,"PLUGINS_DOCK_LOCATIONS",this->pluginsDockContainer->saveState(0),SocExplorerSettings::Session);
216 SocExplorerSettings::setValue(this,"PLUGINS_DOCK_LOCATIONS",this->pluginsDockContainer->saveState(0),SocExplorerSettings::Session);
220 SocExplorerSettings::setValue(this,"MAIN_WINDOW_GEOMETRY",this->saveGeometry(),SocExplorerSettings::Session);
217 SocExplorerSettings::setValue(this,"MAIN_WINDOW_GEOMETRY",this->saveGeometry(),SocExplorerSettings::Session);
221 QStringList plugins = socexplorerproxy::getPluginsList();
218 QStringList plugins = socexplorerproxy::getPluginsList();
222 SocExplorerSettings::setValue(this,"LOADED_PLUGINS",QVariant(plugins),SocExplorerSettings::Session);
219 SocExplorerSettings::setValue(this,"LOADED_PLUGINS",QVariant(plugins),SocExplorerSettings::Session);
223 SocExplorerSettings::sync();
220 SocExplorerSettings::sync();
224 }
221 }
225
222
226 void SocExplorerMainWindow::loadCurrentSession()
223 void SocExplorerMainWindow::loadCurrentSession()
227 {
224 {
228
225
229 QStringList plugins = SocExplorerSettings::value(this,"LOADED_PLUGINS",QVariant(),SocExplorerSettings::Session).toStringList();
226 QStringList plugins = SocExplorerSettings::value(this,"LOADED_PLUGINS",QVariant(),SocExplorerSettings::Session).toStringList();
230 socexplorerproxy::loadPluginsList(plugins);
227 socexplorerproxy::loadPluginsList(plugins);
231 this->restoreGeometry(SocExplorerSettings::value(this,"MAIN_WINDOW_GEOMETRY",QVariant(),SocExplorerSettings::Session).toByteArray());
228 this->restoreGeometry(SocExplorerSettings::value(this,"MAIN_WINDOW_GEOMETRY",QVariant(),SocExplorerSettings::Session).toByteArray());
232 this->restoreState(SocExplorerSettings::value(this,"DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray());
229 this->restoreState(SocExplorerSettings::value(this,"DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray());
233 this->pluginsDockContainer->restoreState(SocExplorerSettings::value(this,"PLUGINS_DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray());
230 this->pluginsDockContainer->restoreState(SocExplorerSettings::value(this,"PLUGINS_DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray());
234 }
231 }
235
232
236
233
237 SocExplorerMainWindow::~SocExplorerMainWindow()
234 SocExplorerMainWindow::~SocExplorerMainWindow()
238 {
235 {
239
236
240 }
237 }
241
238
242
239
243 void SocExplorerMainWindow::setLangage(QAction *action)
240 void SocExplorerMainWindow::setLangage(QAction *action)
244 {
241 {
245 QString local = action->data().toString();
242 QString local = action->data().toString();
246 QString qmPath = QDir(QString("translations")).absolutePath();
243 QString qmPath = QDir(QString("translations")).absolutePath();
247 appTranslator->load(qmPath+"/socexplorer_"+local+".qm");
244 appTranslator->load(qmPath+"/socexplorer_"+local+".qm");
248 qApp->installTranslator(appTranslator);
245 qApp->installTranslator(appTranslator);
249 emit this->translateSig();
246 emit this->translateSig();
250 }
247 }
251
248
252
249
253 void SocExplorerMainWindow::createLangMenu()
250 void SocExplorerMainWindow::createLangMenu()
254 {
251 {
255 this->langMenu = menuBar()->addMenu(tr("&Langue"));
252 this->langMenu = menuBar()->addMenu(tr("&Langue"));
256 this->langActionGrp = new QActionGroup(this);
253 this->langActionGrp = new QActionGroup(this);
257 connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*)));
254 connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*)));
258 QDir* qmDir = new QDir(QString("translations"));
255 QDir* qmDir = new QDir(QString("translations"));
259 QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm"));
256 QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm"));
260 for(int i=0;i<LangFiles.size();++i)
257 for(int i=0;i<LangFiles.size();++i)
261 {
258 {
262 QString Local = LangFiles[i];
259 QString Local = LangFiles[i];
263 Local.remove(0,Local.indexOf('_')+1);
260 Local.remove(0,Local.indexOf('_')+1);
264 Local.chop(3);
261 Local.chop(3);
265 QTranslator translator;
262 QTranslator translator;
266 translator.load(LangFiles[i],qmDir->absolutePath());
263 translator.load(LangFiles[i],qmDir->absolutePath());
267 QString langage = translator.translate("MainWindow","English");
264 QString langage = translator.translate("MainWindow","English");
268 QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this);
265 QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this);
269 action->setCheckable(true);
266 action->setCheckable(true);
270 action->setData(Local);
267 action->setData(Local);
271 langMenu->addAction(action);
268 langMenu->addAction(action);
272 langActionGrp->addAction(action);
269 langActionGrp->addAction(action);
273 if(langage==tr("English"))
270 if(langage==tr("English"))
274 action->setChecked(true);
271 action->setChecked(true);
275 }
272 }
276 }
273 }
277
274
278
275
279 void SocExplorerMainWindow::updateText()
276 void SocExplorerMainWindow::updateText()
280 {
277 {
281 emit this->translateSig();
278 emit this->translateSig();
282 }
279 }
283
280
284
281
285
282
286 void SocExplorerMainWindow::showAboutBox()
283 void SocExplorerMainWindow::showAboutBox()
287 {
284 {
288 p_about->show();
285 p_about->show();
289 }
286 }
290
287
291 void SocExplorerMainWindow::pluginselected(const QString &instanceName)
288 void SocExplorerMainWindow::pluginselected(const QString &instanceName)
292 {
289 {
293 socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName);
290 socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName);
294 if(drv)
291 if(drv)
295 drv->raise();
292 drv->raise();
296 }
293 }
297
294
298 void SocExplorerMainWindow::setActiveSession(const QString &session)
295 void SocExplorerMainWindow::setActiveSession(const QString &session)
299 {
296 {
300 if(!(p_currentSession.isNull() && session=="default"))
297 if(!(p_currentSession.isNull() && session=="default"))
301 saveCurrentSession();
298 saveCurrentSession();
302 socexplorerproxy::self()->close();
299 socexplorerproxy::self()->close();
303 this->p_currentSession = session;
300 this->p_currentSession = session;
304 SocExplorerSettings::loadSession(session);
301 SocExplorerSettings::loadSession(session);
305 loadCurrentSession();
302 loadCurrentSession();
306
303
307 }
304 }
308
305
309 void SocExplorerMainWindow::setActiveSession(QAction *session)
306 void SocExplorerMainWindow::setActiveSession(QAction *session)
310 {
307 {
311 this->setActiveSession(session->text());
308 this->setActiveSession(session->text());
312 }
309 }
313
310
314 void SocExplorerMainWindow::showSessionManager(bool)
311 void SocExplorerMainWindow::showSessionManager(bool)
315 {
312 {
316 this->p_SessionManagerDialog->show();
313 this->p_SessionManagerDialog->show();
317 }
314 }
318
315
319 //TODO handle rename
316 void SocExplorerMainWindow::renameSession(const QString &oldName, const QString &newName)
320 void SocExplorerMainWindow::sessionListChanged()
317 {
318 for(int i=0;i<sessionsActions->actions().count();i++)
319 {
320 if(Q_UNLIKELY(sessionsActions->actions().at(i)->text()==oldName))
321 {
322 sessionsActions->actions().at(i)->setText(newName);
323 }
324 }
325 }
326
327 void SocExplorerMainWindow::addSession(const QString &newSession)
321 {
328 {
329 QAction* sact = new QAction(newSession,this);
330 sact->setCheckable(true);
331 sact->setData(newSession);
332 if(Q_UNLIKELY(p_currentSession==newSession))
333 sact->setChecked(true);
334 sessionsActions->addAction(sact);
335 SessionsMenu->addAction(sact);
336 }
322
337
338 void SocExplorerMainWindow::removeSession(const QString &session)
339 {
340 QAction* sact;
341 foreach (sact, sessionsActions->actions())
342 {
343 if(Q_UNLIKELY(sact->text()==session))
344 {
345 sessionsActions->removeAction(sact);
346 SessionsMenu->removeAction(sact);
347 delete sact;
348 }
349 }
323 }
350 }
324
351
325
352
326
353
354
327 void SocExplorerMainWindow::closeEvent(QCloseEvent *event)
355 void SocExplorerMainWindow::closeEvent(QCloseEvent *event)
328 {
356 {
329 saveCurrentSession();
357 saveCurrentSession();
330 socexplorerproxy::self()->close();
358 socexplorerproxy::self()->close();
331 qApp->closeAllWindows();
359 qApp->closeAllWindows();
332 event->accept();
360 event->accept();
333 }
361 }
334
362
335
363
336
364
337
365
338
366
339
367
@@ -1,100 +1,102
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, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2011, 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 MAINWINDOW_H
22 #ifndef MAINWINDOW_H
23 #define MAINWINDOW_H
23 #define MAINWINDOW_H
24
24
25 #include <QMainWindow>
25 #include <QMainWindow>
26 #include <QApplication>
26 #include <QApplication>
27 #include <QVBoxLayout>
27 #include <QVBoxLayout>
28 #include <QIcon>
28 #include <QIcon>
29 #include <QMenuBar>
29 #include <QMenuBar>
30 #include <QMenu>
30 #include <QMenu>
31 #include <QAction>
31 #include <QAction>
32 #include <QDockWidget>
32 #include <QDockWidget>
33 #include <QTranslator>
33 #include <QTranslator>
34 #include <QSplitter>
34 #include <QSplitter>
35 #include "dockablepluginmanager.h"
35 #include "dockablepluginmanager.h"
36 #include <socexplorerproxy.h>
36 #include <socexplorerproxy.h>
37 #include "PyWdgt/pythonconsole.h"
37 #include "PyWdgt/pythonconsole.h"
38 #include "aboutsocexplorer.h"
38 #include "aboutsocexplorer.h"
39 #include "toolbar.h"
39 #include "toolbar.h"
40 #include "regsExplorer/regsexplorer.h"
40 #include "regsExplorer/regsexplorer.h"
41 #include "socexplorergui.h"
41 #include "socexplorergui.h"
42 #include "sessionmanagerdialog.h"
42 #include "sessionmanagerdialog.h"
43
43
44 class SocExplorerMainWindow : public QMainWindow
44 class SocExplorerMainWindow : public QMainWindow
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47
47
48
48
49 public:
49 public:
50 SocExplorerMainWindow(QString ScriptToEval,QWidget *parent = 0);
50 SocExplorerMainWindow(QString ScriptToEval,QWidget *parent = 0);
51 ~SocExplorerMainWindow();
51 ~SocExplorerMainWindow();
52 QAction* Quit,*LoadPlugin,*ManagePlugins,*help,*regsManager,*exploreRegs,*about,*translateAction,*sessionManagerAction;
52 QAction* Quit,*LoadPlugin,*ManagePlugins,*help,*regsManager,*exploreRegs,*about,*translateAction,*sessionManagerAction;
53 QActionGroup*sessionsActions;
53 QActionGroup*sessionsActions;
54 QActionGroup*langActionGrp;
54 QActionGroup*langActionGrp;
55 QMenu* FileMenu,*SettingsMenu,*PluginsMenu,*ToolsMenu,*langMenu,*helpMenu,*SessionsMenu;
55 QMenu* FileMenu,*SettingsMenu,*PluginsMenu,*ToolsMenu,*langMenu,*helpMenu,*SessionsMenu;
56 QTranslator* appTranslator;
56 QTranslator* appTranslator;
57 void createLangMenu();
57 void createLangMenu();
58 void closeEvent(QCloseEvent *event);
58 void closeEvent(QCloseEvent *event);
59 toolBar* toolpane;
59 toolBar* toolpane;
60
60
61
61
62 public slots:
62 public slots:
63 void launchPluginManager();
63 void launchPluginManager();
64 void addPluginInterface(QDockWidget* plugin);
64 void addPluginInterface(QDockWidget* plugin);
65 void removePluginInterface(QDockWidget* plugin);
65 void removePluginInterface(QDockWidget* plugin);
66 void clearMenu();
66 void clearMenu();
67 void updateText();
67 void updateText();
68 void setLangage(QAction* action);
68 void setLangage(QAction* action);
69 void showAboutBox();
69 void showAboutBox();
70 void pluginselected(const QString& instanceName);
70 void pluginselected(const QString& instanceName);
71 void setActiveSession(const QString & session);
71 void setActiveSession(const QString & session);
72 void setActiveSession(QAction* session);
72 void setActiveSession(QAction* session);
73 void showSessionManager(bool);
73 void showSessionManager(bool);
74 void sessionListChanged();
74 void renameSession(const QString& oldName,const QString& newName);
75 void addSession(const QString& newSession);
76 void removeSession(const QString& session);
75 signals:
77 signals:
76 void translateSig();
78 void translateSig();
77 void registerObject(QObject* object,const QString& instanceName);
79 void registerObject(QObject* object,const QString& instanceName);
78
80
79 private:
81 private:
80 void makeObjects(QString ScriptToEval);
82 void makeObjects(QString ScriptToEval);
81 void makeLayout();
83 void makeLayout();
82 void makeConnections();
84 void makeConnections();
83 void makeMenu();
85 void makeMenu();
84 void loadSessions();
86 void loadSessions();
85 void savePlugins();
87 void savePlugins();
86 void saveCurrentSession();
88 void saveCurrentSession();
87 void loadCurrentSession();
89 void loadCurrentSession();
88 QMainWindow* pluginsDockContainer;
90 QMainWindow* pluginsDockContainer;
89 QSplitter* mainWidget;
91 QSplitter* mainWidget;
90 PythonConsole* PythonConsoleInst;
92 PythonConsole* PythonConsoleInst;
91 dockablePluginManager* pluginManager;
93 dockablePluginManager* pluginManager;
92 RegsExplorer* regExplorer;
94 RegsExplorer* regExplorer;
93 aboutsocexplorer* p_about;
95 aboutsocexplorer* p_about;
94 QList<QDockWidget*>* p_pluginGUIlist;
96 QList<QDockWidget*>* p_pluginGUIlist;
95 QStringList p_Sessions;
97 QStringList p_Sessions;
96 QString p_currentSession;
98 QString p_currentSession;
97 SessionManagerDialog* p_SessionManagerDialog;
99 SessionManagerDialog* p_SessionManagerDialog;
98 };
100 };
99
101
100 #endif // MAINWINDOW_H
102 #endif // MAINWINDOW_H
@@ -1,178 +1,181
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) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 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 "sessionmanagerdialog.h"
22 #include "sessionmanagerdialog.h"
23 #include "ui_sessionmanagerdialog.h"
23 #include "ui_sessionmanagerdialog.h"
24 #include <socexplorersettings.h>
24 #include <socexplorersettings.h>
25 #include <socexplorerconfigkeys.h>
25 #include <socexplorerconfigkeys.h>
26 #include <QInputDialog>
26 #include <QInputDialog>
27 #include <QMessageBox>
27 #include <QMessageBox>
28
28
29 SessionManagerDialog::SessionManagerDialog(QWidget *parent) :
29 SessionManagerDialog::SessionManagerDialog(QWidget *parent) :
30 QDialog(parent),
30 QDialog(parent),
31 ui(new Ui::SessionManagerDialog)
31 ui(new Ui::SessionManagerDialog)
32 {
32 {
33 ui->setupUi(this);
33 ui->setupUi(this);
34 connect(this->ui->NewQPB,SIGNAL(clicked(bool)),this,SLOT(newSession()));
34 connect(this->ui->NewQPB,SIGNAL(clicked(bool)),this,SLOT(newSession()));
35 connect(this->ui->DeleteQPB,SIGNAL(clicked(bool)),this,SLOT(deleteSession()));
35 connect(this->ui->DeleteQPB,SIGNAL(clicked(bool)),this,SLOT(deleteSession()));
36 connect(this->ui->RenameQPB,SIGNAL(clicked(bool)),this,SLOT(renameSession()));
36 connect(this->ui->RenameQPB,SIGNAL(clicked(bool)),this,SLOT(renameSession()));
37 connect(this->ui->SwitchToQPB,SIGNAL(clicked(bool)),this,SLOT(switchSession()));
37 connect(this->ui->SwitchToQPB,SIGNAL(clicked(bool)),this,SLOT(switchSession()));
38 }
38 }
39
39
40 SessionManagerDialog::~SessionManagerDialog()
40 SessionManagerDialog::~SessionManagerDialog()
41 {
41 {
42 delete ui;
42 delete ui;
43 }
43 }
44
44
45
45
46 QStringList SessionManagerDialog::getSessionsList()
46 QStringList SessionManagerDialog::getSessionsList()
47 {
47 {
48 QStringList result;
48 QStringList result;
49 QList<QList<QVariant> > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME);
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++)
50 for(int i=0;i<sessions.count();i++)
51 {
51 {
52 if(sessions.at(i).count()>=1)
52 if(sessions.at(i).count()>=1)
53 {
53 {
54 result.append(sessions.at(i).at(0).toString());
54 result.append(sessions.at(i).at(0).toString());
55 }
55 }
56 }
56 }
57 // May always return at least default session
57 // May always return at least default session
58 if(result.count()==0)
58 if(result.count()==0)
59 {
59 {
60 result.append("default");
60 result.append("default");
61 }
61 }
62 return result;
62 return result;
63 }
63 }
64
64
65 void SessionManagerDialog::show()
65 void SessionManagerDialog::show()
66 {
66 {
67 QStringList sessions = getSessionsList();
67 QStringList sessions = getSessionsList();
68 this->ui->listWidget->clear();
68 this->ui->listWidget->clear();
69 this->ui->listWidget->addItems(sessions);
69 this->ui->listWidget->addItems(sessions);
70 QDialog::show();
70 QDialog::show();
71 }
71 }
72
72
73 void SessionManagerDialog::newSession()
73 void SessionManagerDialog::newSession()
74 {
74 {
75 bool ok=true,exists=false;
75 bool ok=true,exists=false;
76 QString text;
76 QString text;
77 do
77 do
78 {
78 {
79 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
79 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
80 tr("Session name:"), QLineEdit::Normal,
80 tr("Session name:"), QLineEdit::Normal,
81 "New Session", &ok);
81 "New Session", &ok);
82 exists = sessionExists(text);
82 exists = sessionExists(text);
83 if(exists && ok)
83 if(exists && ok)
84 {
84 {
85 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
85 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
86 tr("The session ")+text+tr(" already exists."),
86 tr("The session ")+text+tr(" already exists."),
87 QMessageBox::Ok);
87 QMessageBox::Ok);
88 }
88 }
89 }while(ok && (text.isEmpty() || exists));
89 }while(ok && (text.isEmpty() || exists));
90
90
91 if (ok && !text.isEmpty())
91 if (ok && !text.isEmpty())
92 {
92 {
93 this->newSession(text);
93 this->newSession(text);
94 }
94 }
95 }
95 }
96
96
97 void SessionManagerDialog::newSession(QString session)
97 void SessionManagerDialog::newSession(QString session)
98 {
98 {
99 if (!session.isEmpty())
99 if (!session.isEmpty())
100 {
100 {
101 this->ui->listWidget->addItem(session);
101 this->ui->listWidget->addItem(session);
102 updateSessionList();
102 updateSessionList();
103 emit sessionAdded(session);
103 }
104 }
104 }
105 }
105
106
106 void SessionManagerDialog::renameSession()
107 void SessionManagerDialog::renameSession()
107 {
108 {
108 bool ok=true;
109 bool ok=true;
109 int exists=0;
110 int exists=0;
110 QListWidgetItem* item = this->ui->listWidget->currentItem();
111 QListWidgetItem* item = this->ui->listWidget->currentItem();
111 QString text= item->text();
112 QString text= item->text();
112 QString OldText= item->text();
113 QString OldText= item->text();
113 do
114 do
114 {
115 {
115 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
116 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
116 tr("New session name:"), QLineEdit::Normal,
117 tr("New session name:"), QLineEdit::Normal,
117 text, &ok);
118 text, &ok);
118 exists = sessionExists(text);
119 exists = sessionExists(text);
119 if(exists&& ok)
120 if(exists&& ok)
120 {
121 {
121 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
122 QMessageBox::warning(this, tr("SocExplorer Session Manager"),
122 tr("The session ")+text+tr(" already exists."),
123 tr("The session ")+text+tr(" already exists."),
123 QMessageBox::Ok);
124 QMessageBox::Ok);
124 }
125 }
125 }while(ok && text.isEmpty());
126 }while(ok && text.isEmpty());
126
127
127 if (ok && !text.isEmpty())
128 if (ok && !text.isEmpty())
128 {
129 {
129 item->setText(text);
130 item->setText(text);
130 SocExplorerSettings::renameSession(text,OldText);
131 SocExplorerSettings::renameSession(OldText,text);
132 emit sessionRenamed(OldText,text);
131 updateSessionList();
133 updateSessionList();
132 emit sessionListChanged();
134 emit sessionListChanged();
133 }
135 }
134 }
136 }
135
137
136 void SessionManagerDialog::deleteSession()
138 void SessionManagerDialog::deleteSession()
137 {
139 {
138 if(this->ui->listWidget->selectedItems().count())
140 if(this->ui->listWidget->selectedItems().count())
139 {
141 {
140 QListWidgetItem* item = this->ui->listWidget->currentItem();
142 QListWidgetItem* item = this->ui->listWidget->currentItem();
141 if(item && item->text().compare("default"))
143 if(item && item->text().compare("default"))
142 {
144 {
143 this->ui->listWidget->removeItemWidget(item);
145 this->ui->listWidget->removeItemWidget(item);
144 SocExplorerSettings::deleteSession(item->text());
146 SocExplorerSettings::deleteSession(item->text());
147 emit sessionRemoved(item->text());
145 delete item;
148 delete item;
146 updateSessionList();
149 updateSessionList();
147 }
150 }
148 }
151 }
149 }
152 }
150
153
151 void SessionManagerDialog::switchSession()
154 void SessionManagerDialog::switchSession()
152 {
155 {
153 QListWidgetItem* item = this->ui->listWidget->currentItem();
156 QListWidgetItem* item = this->ui->listWidget->currentItem();
154 if(item)
157 if(item)
155 emit switchSession(item->text());
158 emit switchSession(item->text());
156 }
159 }
157
160
158 int SessionManagerDialog::sessionExists(QString session)
161 int SessionManagerDialog::sessionExists(QString session)
159 {
162 {
160 int exists=0;
163 int exists=0;
161 for(int i=0;i< this->ui->listWidget->count();i++)
164 for(int i=0;i< this->ui->listWidget->count();i++)
162 {
165 {
163 exists += (this->ui->listWidget->item(i)->text().compare(session)==0);
166 exists += (this->ui->listWidget->item(i)->text().compare(session)==0);
164 }
167 }
165 return exists;
168 return exists;
166 }
169 }
167
170
168 void SessionManagerDialog::updateSessionList()
171 void SessionManagerDialog::updateSessionList()
169 {
172 {
170 QList<QList<QVariant> > sessions;
173 QList<QList<QVariant> > sessions;
171 for(int i=0;i< this->ui->listWidget->count();i++)
174 for(int i=0;i< this->ui->listWidget->count();i++)
172 {
175 {
173 QList<QVariant> sess;
176 QList<QVariant> sess;
174 sess.append(this->ui->listWidget->item(i)->text());
177 sess.append(this->ui->listWidget->item(i)->text());
175 sessions.append(sess);
178 sessions.append(sess);
176 }
179 }
177 SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME,sessions);
180 SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME,sessions);
178 }
181 }
@@ -1,58 +1,60
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) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 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 #ifndef SESSIONMANAGERDIALOG_H
22 #ifndef SESSIONMANAGERDIALOG_H
23 #define SESSIONMANAGERDIALOG_H
23 #define SESSIONMANAGERDIALOG_H
24
24
25 #include <QDialog>
25 #include <QDialog>
26
26
27 namespace Ui {
27 namespace Ui {
28 class SessionManagerDialog;
28 class SessionManagerDialog;
29 }
29 }
30
30
31 class SessionManagerDialog : public QDialog
31 class SessionManagerDialog : public QDialog
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34
34
35 public:
35 public:
36 explicit SessionManagerDialog(QWidget *parent = 0);
36 explicit SessionManagerDialog(QWidget *parent = 0);
37 ~SessionManagerDialog();
37 ~SessionManagerDialog();
38
38
39 QStringList getSessionsList();
39 QStringList getSessionsList();
40 public slots:
40 public slots:
41 void show();
41 void show();
42 void newSession(QString session);
42 void newSession(QString session);
43 int sessionExists(QString session);
43 int sessionExists(QString session);
44 private slots:
44 private slots:
45 void newSession();
45 void newSession();
46 void renameSession();
46 void renameSession();
47 void deleteSession();
47 void deleteSession();
48 void switchSession();
48 void switchSession();
49 signals:
49 signals:
50 void switchSession(QString session);
50 void switchSession(QString session);
51 void sessionListChanged();
51 void sessionListChanged();
52
52 void sessionRenamed(const QString& oldName,const QString& newName);
53 void sessionRemoved(const QString& session);
54 void sessionAdded(const QString& newSession);
53 private:
55 private:
54 void updateSessionList();
56 void updateSessionList();
55 Ui::SessionManagerDialog *ui;
57 Ui::SessionManagerDialog *ui;
56 };
58 };
57
59
58 #endif // SESSIONMANAGERDIALOG_H
60 #endif // SESSIONMANAGERDIALOG_H
General Comments 0
You need to be logged in to leave comments. Login now