1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010-2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program 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 Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "sheetbuilderconfgdialog.h"
21 #include "../core/icore.h"
23 #include <QListWidget>
24 #include <QPushButton>
29 #include <QCloseEvent>
30 #include <QFileDialog>
32 SheetBuilderConfigDialog::SheetBuilderConfigDialog(QWidget
*parent
)
38 QLabel
*lblPaths
= new QLabel(tr("Paths:"));
39 lstPaths
= new QListWidget
;
40 lstPaths
->addItem("");
42 QPushButton
*btnAddPath
= new QPushButton(tr("Add"));
43 connect(btnAddPath
, SIGNAL(clicked()), SLOT(addPath()));
44 QPushButton
*btnDeletePath
= new QPushButton(tr("Delete"));
45 connect(btnDeletePath
, SIGNAL(clicked()), SLOT(deletePath()));
47 QVBoxLayout
*ltButtonsPaths
= new QVBoxLayout();
48 ltButtonsPaths
->addWidget(btnAddPath
);
49 ltButtonsPaths
->addWidget(btnDeletePath
);
50 ltButtonsPaths
->addStretch(1);
52 QHBoxLayout
*ltPaths
= new QHBoxLayout
;
53 ltPaths
->addWidget(lstPaths
);
54 ltPaths
->addLayout(ltButtonsPaths
);
59 QLabel
*lblOutputFile
= new QLabel(tr("Output file:"));
60 txtOutputFile
= new QLineEdit();
61 QPushButton
*btnBrowse
= new QPushButton(tr("Browse..."));
62 connect(btnBrowse
, SIGNAL(clicked()), SLOT(browseOutput()));
64 QHBoxLayout
*ltOutput
= new QHBoxLayout();
65 ltOutput
->addWidget(txtOutputFile
);
66 ltOutput
->addWidget(btnBrowse
);
71 QLabel
*lblExtensions
= new QLabel(tr("Allowed extensions:"));
72 lstExtensionsAllowed
= new QListWidget();
74 QPushButton
*btnAddExtension
= new QPushButton(tr("Add"));
75 connect(btnAddExtension
, SIGNAL(clicked()), SLOT(addExtension()));
76 QPushButton
*btnDeleteExtension
= new QPushButton(tr("Delete"));
77 connect(btnDeleteExtension
, SIGNAL(clicked()), SLOT(deleteExtension()));
79 QVBoxLayout
*ltButtonsExtensions
= new QVBoxLayout();
80 ltButtonsExtensions
->addWidget(btnAddExtension
);
81 ltButtonsExtensions
->addWidget(btnDeleteExtension
);
82 ltButtonsExtensions
->addStretch(1);
84 QHBoxLayout
*ltExtensions
= new QHBoxLayout();
85 ltExtensions
->addWidget(lstExtensionsAllowed
);
86 ltExtensions
->addLayout(ltButtonsExtensions
);
91 QPushButton
*btnOk
= new QPushButton(tr("OK"));
92 connect(btnOk
, SIGNAL(clicked()), SLOT(accept()));
93 connect(btnOk
, SIGNAL(clicked()), SLOT(writeSettings()));
95 QPushButton
*btnCancel
= new QPushButton(tr("Cancel"));
96 connect(btnCancel
, SIGNAL(clicked()), SLOT(reject()));
98 QHBoxLayout
*ltButtons
= new QHBoxLayout
;
99 ltButtons
->addStretch(1);
100 ltButtons
->addWidget(btnOk
);
101 ltButtons
->addWidget(btnCancel
);
106 QVBoxLayout
*ltMain
= new QVBoxLayout
;
107 ltMain
->addWidget(lblPaths
);
108 ltMain
->addLayout(ltPaths
);
109 ltMain
->addWidget(lblOutputFile
);
110 ltMain
->addLayout(ltOutput
);
111 ltMain
->addWidget(lblExtensions
);
112 ltMain
->addLayout(ltExtensions
);
113 ltMain
->addLayout(ltButtons
);
116 setWindowTitle(tr("Sheet builder configuration"));
121 void SheetBuilderConfigDialog::addPath()
124 QFileDialog::getExistingDirectory(this, tr("Choose path"));
127 QListWidgetItem
*newItem
= new QListWidgetItem
;
128 newItem
->setText(path
);
129 newItem
->setFlags(Qt::ItemIsEditable
| Qt::ItemIsEnabled
| Qt::ItemIsSelectable
);
130 lstPaths
->addItem(newItem
);
131 lstPaths
->setCurrentItem(newItem
);
135 void SheetBuilderConfigDialog::addExtension()
137 QListWidgetItem
*newItem
= new QListWidgetItem
;
138 newItem
->setFlags(Qt::ItemIsEditable
| Qt::ItemIsEnabled
| Qt::ItemIsSelectable
);
139 lstExtensionsAllowed
->addItem(newItem
);
140 lstExtensionsAllowed
->setCurrentItem(newItem
);
143 void SheetBuilderConfigDialog::deletePath()
145 QListWidgetItem
*removeItem
= lstPaths
->takeItem(lstPaths
->currentRow());
150 void SheetBuilderConfigDialog::deleteExtension()
152 QListWidgetItem
*removeItem
153 = lstExtensionsAllowed
->takeItem(lstExtensionsAllowed
->currentRow());
158 void SheetBuilderConfigDialog::browseOutput()
161 QFileDialog::getSaveFileName(this, tr("Choose output file"), "");
162 if (!fileName
.isEmpty())
163 txtOutputFile
->setText(fileName
);
166 void SheetBuilderConfigDialog::readSettings()
170 QStringList extensions
;
172 QSettings
*settings
= Core::ICore::instance()->settings();
173 settings
->beginGroup("SheetBuilder");
174 paths
= settings
->value("SheetPaths").toStringList();
175 outputFile
= settings
->value("SheetOutputFile").toString();
176 extensions
= settings
->value("ExtensionsAllowed").toStringList();
177 settings
->endGroup();
180 lstExtensionsAllowed
->clear();
182 QListWidgetItem
*newItem
;
184 Q_FOREACH (QString path
, paths
)
186 newItem
= new QListWidgetItem
;
187 newItem
->setText(path
);
188 newItem
->setFlags(Qt::ItemIsEditable
| Qt::ItemIsEnabled
| Qt::ItemIsSelectable
);
189 lstPaths
->addItem(newItem
);
192 txtOutputFile
->setText(outputFile
);
194 Q_FOREACH (QString extension
, extensions
)
196 newItem
= new QListWidgetItem
;
197 newItem
->setText(extension
);
198 newItem
->setFlags(Qt::ItemIsEditable
| Qt::ItemIsEnabled
| Qt::ItemIsSelectable
);
199 lstExtensionsAllowed
->addItem(newItem
);
203 void SheetBuilderConfigDialog::writeSettings()
206 for (int i
= 0; i
< lstPaths
->count(); i
++)
207 paths
.push_back(lstPaths
->item(i
)->text());
209 QString outputFile
= txtOutputFile
->text();
211 QStringList extensions
;
212 for (int i
= 0; i
< lstExtensionsAllowed
->count(); i
++)
213 extensions
.push_back(lstExtensionsAllowed
->item(i
)->text());
215 QSettings
*settings
= Core::ICore::instance()->settings();
216 settings
->beginGroup("SheetBuilder");
217 settings
->setValue("SheetPaths", paths
);
218 settings
->setValue("SheetOutputFile", outputFile
);
219 settings
->setValue("ExtensionsAllowed", extensions
);
220 settings
->endGroup();
222 // Forced save settings