1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "guisettingsviewer.h"
24 #include "guisettingstab.h"
26 #include <QTextStream>
29 /* Here is how we we get QTextStreams that look like iostreams */
30 QTextStream
cin(stdin
, QIODevice::ReadOnly
);
31 QTextStream
cout(stdout
, QIODevice::WriteOnly
);
32 QTextStream
cerr(stderr
, QIODevice::WriteOnly
);
34 GuiSettingsViewer::GuiSettingsViewer(QSettings
* Set
, QWidget
*parent
) : QDialog(parent
)
37 organization
= Set
->organizationName();
38 application
= Set
->applicationName();
42 GuiSettingsViewer::GuiSettingsViewer(QString org
, QString app
, QWidget
*parent
) : QDialog(parent
)
46 m_settings
= new QSettings(org
, app
);
50 void GuiSettingsViewer::CreateViewer()
52 closeButton
= new QPushButton(tr("Close"));
53 saveButton
= new QPushButton(tr("Save"));
55 connect(closeButton
, SIGNAL(clicked()), this, SLOT(close()));
56 connect(saveButton
, SIGNAL(clicked()), this, SLOT(save()));
58 QHBoxLayout
*bottomLayout
= new QHBoxLayout
;
59 bottomLayout
->addStretch();
60 bottomLayout
->addWidget(saveButton
);
61 bottomLayout
->addWidget(closeButton
);
63 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
64 mainLayout
->addWidget(&tabWidget
);
65 mainLayout
->addLayout(bottomLayout
);
66 setLayout(mainLayout
);
68 setWindowTitle(tr("Settings Viewer"));
72 void GuiSettingsViewer::save()
74 for (int i
= 0; i
< tabWidget
.count(); i
++) {
75 QString group
= tabWidget
.tabText(i
);
76 GuiSettingsTab
* ST
= (GuiSettingsTab
*)(tabWidget
.widget(i
));
81 if (group
!= QObject::tr("General")) m_settings
->beginGroup(group
);
83 N
= (ST
->spinbox_name
).size();
84 for (int i
= 0; i
< N
; i
++) {
85 m_settings
->beginGroup(QObject::tr("int"));
86 key
= ST
->spinbox_name
[i
];
87 int value
= ST
->spinbox
[i
]->value();
88 m_settings
->setValue(key
, value
);
89 m_settings
->endGroup();
92 N
= (ST
->checkbox_name
).size();
93 for (int i
= 0; i
< N
; i
++) {
94 m_settings
->beginGroup(QObject::tr("bool"));
95 key
= ST
->checkbox_name
[i
];
96 Qt::CheckState value
= ST
->checkbox
[i
]->checkState();
97 m_settings
->setValue(key
, value
);
98 m_settings
->endGroup();
101 N
= (ST
->double_lineedit_name
).size();
102 for (int i
= 0; i
< N
; i
++) {
103 m_settings
->beginGroup(QObject::tr("double"));
104 key
= ST
->double_lineedit_name
[i
];
105 double value
= (ST
->double_lineedit
[i
]->text()).toDouble();
106 m_settings
->setValue(key
, value
);
107 m_settings
->endGroup();
110 N
= (ST
->string_lineedit_name
).size();
111 for (int i
= 0; i
< N
; i
++) {
112 m_settings
->beginGroup(QObject::tr("QString"));
113 key
= ST
->string_lineedit_name
[i
];
114 QString value
= ST
->string_lineedit
[i
]->text();
115 m_settings
->setValue(key
, value
);
116 m_settings
->endGroup();
119 N
= (ST
->filename_dialoglineedit_name
).size();
120 for (int i
= 0; i
< N
; i
++) {
121 m_settings
->beginGroup(QObject::tr("Filename"));
122 key
= ST
->filename_dialoglineedit_name
[i
];
123 QString value
= ST
->filename_dialoglineedit
[i
]->text();
124 m_settings
->setValue(key
, value
);
125 m_settings
->endGroup();
128 N
= (ST
->directory_dialoglineedit_name
).size();
129 for (int i
= 0; i
< N
; i
++) {
130 m_settings
->beginGroup(QObject::tr("Directory"));
131 key
= ST
->directory_dialoglineedit_name
[i
];
132 QString value
= ST
->directory_dialoglineedit
[i
]->text();
133 m_settings
->setValue(key
, value
);
134 m_settings
->endGroup();
137 if (group
!= QObject::tr("General")) m_settings
->endGroup();
144 void GuiSettingsViewer::open()
146 QDialog
dialog(this);
148 QLabel
*orgLabel
= new QLabel(tr("&Organization:"));
149 QLineEdit
*orgLineEdit
= new QLineEdit(organization
);
150 orgLabel
->setBuddy(orgLineEdit
);
152 QLabel
*appLabel
= new QLabel(tr("&Application:"));
153 QLineEdit
*appLineEdit
= new QLineEdit(application
);
154 appLabel
->setBuddy(appLineEdit
);
156 QPushButton
*okButton
= new QPushButton(tr("OK"));
157 okButton
->setDefault(true);
158 QPushButton
*cancelButton
= new QPushButton(tr("Cancel"));
160 connect(okButton
, SIGNAL(clicked()), &dialog
, SLOT(accept()));
161 connect(cancelButton
, SIGNAL(clicked()), &dialog
, SLOT(reject()));
163 QHBoxLayout
*buttonLayout
= new QHBoxLayout
;
164 buttonLayout
->addStretch();
165 buttonLayout
->addWidget(okButton
);
166 buttonLayout
->addWidget(cancelButton
);
168 QGridLayout
*gridLayout
= new QGridLayout
;
169 gridLayout
->addWidget(orgLabel
, 0, 0);
170 gridLayout
->addWidget(orgLineEdit
, 0, 1);
171 gridLayout
->addWidget(appLabel
, 1, 0);
172 gridLayout
->addWidget(appLineEdit
, 1, 1);
174 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
175 mainLayout
->addLayout(gridLayout
);
176 mainLayout
->addLayout(buttonLayout
);
177 dialog
.setLayout(mainLayout
);
179 dialog
.setWindowTitle(tr("Choose Settings"));
182 organization
= orgLineEdit
->text();
183 application
= appLineEdit
->text();
188 void GuiSettingsViewer::readSettings()
191 setWindowTitle(tr("Settings Viewer - %1 by %2").arg(application
).arg(organization
));
194 void GuiSettingsViewer::addChildSettings()
196 ///\todo Delete for real
197 //This only removes the tabs, but does not delete them!!!
200 tabWidget
.addTab(new GuiSettingsTab(organization
, application
, tr("General")), tr("General"));
201 foreach(QString group
, m_settings
->childGroups()) {
202 if ((group
!= tr("int"))
203 && (group
!= tr("bool"))
204 && (group
!= tr("double"))
205 && (group
!= tr("QString"))
206 && (group
!= tr("Filename"))
207 && (group
!= tr("Directory"))) {
208 tabWidget
.addTab(new GuiSettingsTab(organization
, application
, group
), group
);
213 int GuiSettingsViewer::getSet(QString group
, QString key
, int value
)
215 QString typed_key
= tr("int/") + key
;
216 if (group
!= tr("General")) m_settings
->beginGroup(group
);
217 //if key=value pair not found in m_settings file, write it
218 if (!m_settings
->contains(typed_key
)) m_settings
->setValue(typed_key
, value
);
219 //read key value from m_settings file and assign it to variable
220 int variable
= (m_settings
->value(typed_key
)).toInt();
221 if (group
!= tr("General")) m_settings
->endGroup();
225 double GuiSettingsViewer::getSet(QString group
, QString key
, double value
)
227 QString typed_key
= tr("double/") + key
;
228 if (group
!= tr("General")) m_settings
->beginGroup(group
);
229 //if key=value pair not found in m_settings file, write it
230 if (!m_settings
->contains(typed_key
)) m_settings
->setValue(typed_key
, value
);
231 //read key value from m_settings file and assign it to variable
232 double variable
= (m_settings
->value(typed_key
)).toDouble();
233 if (group
!= tr("General")) m_settings
->endGroup();
237 bool GuiSettingsViewer::getSet(QString group
, QString key
, bool value
)
239 QString typed_key
= tr("bool/") + key
;
240 if (group
!= tr("General")) m_settings
->beginGroup(group
);
241 Qt::CheckState state
= (Qt::CheckState
)(value
? 2 : 0);
242 //if key=value pair not found in m_settings file, write it
243 if (!m_settings
->contains(typed_key
)) m_settings
->setValue(typed_key
, state
);
244 //read key value from m_settings file and assign it to variable
245 bool variable
= (m_settings
->value(typed_key
)).toBool();
246 if (group
!= tr("General")) m_settings
->endGroup();
250 QString
GuiSettingsViewer::getSet(QString group
, QString key
, QString value
, int type
)
254 typed_key
= tr("QString/") + key
;
256 else if (type
== 1) {
257 typed_key
= tr("Filename/") + key
;
260 typed_key
= tr("Directory/") + key
;
262 if (group
!= tr("General")) m_settings
->beginGroup(group
);
263 //if key=value pair not found in m_settings file, write it
264 if (!m_settings
->contains(typed_key
)) m_settings
->setValue(typed_key
, value
);
265 //read key value from m_settings file and assign it to variable
266 QString variable
= (m_settings
->value(typed_key
)).toString();
267 if (group
!= tr("General")) m_settings
->endGroup();