Linux multi-monitor fullscreen support
[ryzomcore.git] / studio / src / plugins / ovqt_sheet_builder / sheetbuilderdialog.cpp
blob1e1f8378259b024ae2d7eeb3286ebcc60ffff3a9
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010-2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
6 //
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 "sheetbuilderdialog.h"
21 #include "sheetbuilder.h"
22 #include "sheetbuilderconfgdialog.h"
23 #include "../core/icore.h"
24 #include "../core/core_constants.h"
26 #include <QCheckBox>
27 #include <QPushButton>
28 #include <QLayout>
29 #include <QTextEdit>
30 #include <QSettings>
31 #include <QTreeWidget>
32 #include <QDebug>
34 SheetBuilderDialog::SheetBuilderDialog(QWidget *parent)
35 : QDialog(parent)
37 QPushButton *btnOk = new QPushButton(tr("Make sheet"));
38 connect(btnOk, SIGNAL(clicked()), SLOT(buildSheet()));
40 QPushButton *btnCancel = new QPushButton(tr("Close"));
41 connect(btnCancel, SIGNAL(clicked()), SLOT(reject()));
43 chckClean = new QCheckBox(tr("Clean unwanted types from input"));
45 txtOutput = new QTextEdit;
46 txtOutput->setMinimumHeight(300);
47 txtOutput->setMinimumWidth(500);
48 txtOutput->setReadOnly(true);
49 txtOutput->setFontFamily("Monospace, Courier New, monospace");
51 QPushButton *btnDetails = new QPushButton(tr("Show/Hide details..."));
52 connect(btnDetails, SIGNAL(clicked()), SLOT(detailsShowHide()));
54 QPushButton *btnConfig = new QPushButton(tr("Settings"));
55 connect(btnConfig, SIGNAL(clicked()), SLOT(showConfig()));
57 QHBoxLayout *ltButtons = new QHBoxLayout;
58 ltButtons->addWidget(btnConfig);
59 ltButtons->addWidget(btnDetails);
60 ltButtons->addStretch(1);
61 ltButtons->addWidget(btnOk);
62 ltButtons->addWidget(btnCancel);
64 QVBoxLayout *ltMain = new QVBoxLayout;
65 ltMain->addWidget(chckClean);
66 ltMain->addWidget(txtOutput, 1);
67 ltMain->addLayout(ltButtons);
68 ltMain->addStretch();
70 txtOutput->hide();
71 detailsVisible = false;
73 setLayout(ltMain);
74 defHeight = height();
75 defWidth = 500;
76 resize(defWidth, defHeight);
77 setWindowTitle(tr("Sheet builder"));
80 void SheetBuilderDialog::showConfig()
82 SheetBuilderConfigDialog dlg(this);
83 dlg.exec();
86 void SheetBuilderDialog::detailsShowHide()
88 if (!detailsVisible)
90 defHeight = height();
91 defWidth = width();
94 detailsVisible = !detailsVisible;
95 txtOutput->setVisible(detailsVisible);
97 if (!detailsVisible)
99 adjustSize();
100 resize(defWidth, defHeight);
104 void SheetBuilderDialog::displayInfo(QString str)
106 txtOutput->append(str);
109 void SheetBuilderDialog::buildSheet()
111 QStringList paths;
112 QString outputFile;
113 QStringList extensions;
115 // read settings
116 QSettings *settings = Core::ICore::instance()->settings();
117 settings->beginGroup("SheetBuilder");
118 paths = settings->value("SheetPaths").toStringList();
119 outputFile = settings->value("SheetOutputFile").toString();
120 extensions = settings->value("ExtensionsAllowed").toStringList();
121 settings->endGroup();
123 bool clean = chckClean->isChecked();
125 string outputFileName(outputFile.toUtf8());
127 if (outputFileName.empty())
129 displayInfo("Error: Output file is not specified");
130 return;
133 list<string> inputDirs;
134 Q_FOREACH (QString str, paths)
135 inputDirs.push_back(str.toUtf8().constData());
137 Q_FOREACH (QString str, extensions)
139 ExtensionsAllowed.insert(str.toUtf8().constData());
142 // get the current associations (read the sheet_id and fill the working structures)
143 readFormId( outputFileName );
145 // output path
146 sint lastSeparator = CFile::getLastSeparator(outputFileName);
147 string outputPath;
148 if( lastSeparator != -1 )
150 outputPath = outputFileName.substr(0,lastSeparator+1);
153 // erase the unwanted extensions from map (modify the map, save it, and quit)
154 if( clean )
156 if( ExtensionsAllowed.empty() )
157 displayInfo(tr("None extension list provided, the input will not be cleaned"));
158 else
160 map<TFormId,string>::iterator itSheets;
161 for( itSheets = IdToForm.begin(); itSheets != IdToForm.end(); )
163 string extStr = CFile::getExtension( (*itSheets).second );
164 if( !extStr.empty() )
166 if( ExtensionsAllowed.find(extStr) == ExtensionsAllowed.end() )
168 map<TFormId,string>::iterator itDel = itSheets++;
169 IdToForm.erase( itDel );
171 else
172 ++itSheets;
175 COFile f( outputFileName );
176 f.serialCont( IdToForm );
178 displayInfo("The file has been cleaned");
179 return;
181 setCursor(Qt::WaitCursor);
182 // make the ids
183 makeId( inputDirs );
184 setCursor(Qt::ArrowCursor);
186 // save the new map
187 COFile f( outputFileName );
188 f.serialCont( IdToForm );
190 string sheetListFileName = outputPath + "sheets.txt";
191 COFile output;
192 if( !output.open(sheetListFileName,false,true) )
194 displayInfo(tr("Can't open output file %1").arg(sheetListFileName.c_str()));
195 return;
197 map<TFormId,string>::iterator it1;
198 for( it1 = IdToForm.begin(); it1 != IdToForm.end(); ++it1 )
200 string outputLine = " id: " + toString((*it1).first.Id) + " file: " + (*it1).second +"\n";
201 output.serialBuffer((uint8 *)(const_cast<char *>(outputLine.data())),(uint)outputLine.size());
204 displayInfo (tr("------------- results ----------------"));
205 displayInfo (tr("%1 files added in '%2'").arg(NbFilesAdded).arg(outputFileName.c_str()));
206 displayInfo (tr("%1 files discarded because they are empty, begin with .# _ and so on").arg(NbFilesDiscarded));
207 displayInfo (tr("%1 files skipped because don't have extension").arg(NbFilesUnknownType));
208 displayInfo (tr("%1 types added in '%1'").arg(NbTypesAdded).arg(outputFileName.c_str()));
210 displayInfo (tr("%1 supported file types :").arg(FileTypeToId.size()));
211 for ( map<string,uint8>::iterator it = FileTypeToId.begin(); it != FileTypeToId.end(); ++it )
213 displayInfo(QString("%1").arg((*it).first.c_str()));