@@ -138,6 +138,25 QList<QList<QVariant> > SocExplorerSetti | |||||
138 | return defaultValue; |
|
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 | void SocExplorerSettings::sync() |
|
160 | void SocExplorerSettings::sync() | |
142 | { |
|
161 | { | |
143 | INIT(); |
|
162 | INIT(); | |
@@ -195,7 +214,7 QList<QList<QVariant> > SocExplorerSetti | |||||
195 | settings->setArrayIndex(i); |
|
214 | settings->setArrayIndex(i); | |
196 | for(int l=0;l<keys.count();l++) |
|
215 | for(int l=0;l<keys.count();l++) | |
197 | { |
|
216 | { | |
198 |
result[i].append(settings->value(keys.at( |
|
217 | result[i].append(settings->value(keys.at(l))); | |
199 | } |
|
218 | } | |
200 | } |
|
219 | } | |
201 | settings->endArray(); |
|
220 | settings->endArray(); | |
@@ -203,3 +222,27 QList<QList<QVariant> > SocExplorerSetti | |||||
203 | return result; |
|
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 |
@@ -49,6 +49,7 public: | |||||
49 | static void setValue(const QString scope,const QString & key, const QVariant & value,SettingScope Sscope= SystemWide); |
|
49 | static void setValue(const QString scope,const QString & key, const QVariant & value,SettingScope Sscope= SystemWide); | |
50 | static QVariant value(const QString scope, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope =SystemWide); |
|
50 | static QVariant value(const QString scope, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope =SystemWide); | |
51 | static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,SettingScope Sscope =SystemWide); |
|
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 | static void sync(); |
|
53 | static void sync(); | |
53 | static bool registerConfigEntry(SocExplorerSettingsItem* configEntry,QIcon icon, QString text); |
|
54 | static bool registerConfigEntry(SocExplorerSettingsItem* configEntry,QIcon icon, QString text); | |
54 | //! Loads the given session, or sreate it if doesn't exists. |
|
55 | //! Loads the given session, or sreate it if doesn't exists. | |
@@ -61,6 +62,7 public slots: | |||||
61 | void popConfigDialog(); |
|
62 | void popConfigDialog(); | |
62 | private: |
|
63 | private: | |
63 | static QList<QList<QVariant> > arrays(const QString & prefix, QStringList keys,QSettings* settings); |
|
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 | #endif // SOCEXPLORERSETTINGS_H |
|
68 | #endif // SOCEXPLORERSETTINGS_H |
@@ -176,17 +176,7 void SocExplorerMainWindow::makeMenu() | |||||
176 |
|
176 | |||
177 | void SocExplorerMainWindow::loadSessions() |
|
177 | void SocExplorerMainWindow::loadSessions() | |
178 | { |
|
178 | { | |
179 | // QStringList sessions = SocExplorerSettings::value(); |
|
179 | p_Sessions=this->p_SessionManagerDialog->getSessionsList(); | |
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 |
|
||||
190 | } |
|
180 | } | |
191 |
|
181 | |||
192 |
|
182 |
@@ -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 | #include "sessionmanagerdialog.h" |
|
22 | #include "sessionmanagerdialog.h" | |
2 | #include "ui_sessionmanagerdialog.h" |
|
23 | #include "ui_sessionmanagerdialog.h" | |
|
24 | #include <socexplorersettings.h> | |||
|
25 | #include <socexplorerconfigkeys.h> | |||
|
26 | #include <QInputDialog> | |||
|
27 | #include <QMessageBox> | |||
3 |
|
28 | |||
4 | SessionManagerDialog::SessionManagerDialog(QWidget *parent) : |
|
29 | SessionManagerDialog::SessionManagerDialog(QWidget *parent) : | |
5 | QDialog(parent), |
|
30 | QDialog(parent), | |
6 | ui(new Ui::SessionManagerDialog) |
|
31 | ui(new Ui::SessionManagerDialog) | |
7 | { |
|
32 | { | |
8 | ui->setupUi(this); |
|
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 | SessionManagerDialog::~SessionManagerDialog() |
|
38 | SessionManagerDialog::~SessionManagerDialog() | |
12 | { |
|
39 | { | |
13 | delete ui; |
|
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,3 +1,24 | |||||
|
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 | #ifndef SESSIONMANAGERDIALOG_H |
|
22 | #ifndef SESSIONMANAGERDIALOG_H | |
2 | #define SESSIONMANAGERDIALOG_H |
|
23 | #define SESSIONMANAGERDIALOG_H | |
3 |
|
24 | |||
@@ -15,7 +36,17 public: | |||||
15 | explicit SessionManagerDialog(QWidget *parent = 0); |
|
36 | explicit SessionManagerDialog(QWidget *parent = 0); | |
16 | ~SessionManagerDialog(); |
|
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 | private: |
|
48 | private: | |
|
49 | void updateSessionList(); | |||
19 | Ui::SessionManagerDialog *ui; |
|
50 | Ui::SessionManagerDialog *ui; | |
20 | }; |
|
51 | }; | |
21 |
|
52 |
General Comments 0
You need to be logged in to leave comments.
Login now