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