ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/mainwindow.cpp
Revision: 791
Committed: Sat Apr 6 21:08:35 2013 UTC (12 years, 6 months ago) by s10k
Content type: text/x-c++src
Original Path: Vago/trunk/Vago/mainwindow.cpp
File size: 58592 byte(s)
Log Message:
First export from MacOS

File Contents

# Content
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3
4 const QString MainWindow::VagoSettingsName = "settingsVago.ini";
5
6 MainWindow::MainWindow(QWidget *parent) :
7 QMainWindow(parent),
8 ui(new Ui::MainWindow)
9 {
10 ui->setupUi(this);
11
12 ui->pbConvertGeneral->setMinimumSize(ui->pbConvertGeneral->minimumSizeHint());
13 ui->pbConvertGeneral->setMinimumWidth(50);
14 ui->pbConvertGeneral->setMinimumHeight(ui->pbConvertGeneral->minimumHeight()*1.4);
15
16 qDebug() << ui->pbConvertGeneral->minimumHeight() << ui->pbConvertGeneral->minimumHeight();
17
18 this->setWindowTitle("Vago v"+GlobalVars::AppVersion);
19
20 if(!QFile::exists(QDir::currentPath()+"/"+GlobalVars::OniSplitString)){
21 Util::showErrorPopUp("OniSplit not found. Please download it at "+GlobalVars::ModsDomain+" and put it in the same folder of Vago. \n\nProgram will now exit.");
22 exit(1);
23 }
24
25 if(!QFile::exists(QDir::currentPath()+"/"+GlobalVars::XmlToolsString)){
26 Util::showErrorPopUp("xmlTools not found. Please download it at "+GlobalVars::ModsDomain+" and put it in the same folder of Vago. \n\nProgram will now exit.");
27 exit(1);
28 }
29
30 this->vagoSettings = new QSettings(QDir::currentPath() + "/" + this->VagoSettingsName, QSettings::IniFormat);
31
32 //First Execution? Old configuration? Settings missed?
33 bool iniChanged=false;
34 if(!this->vagoSettings->contains("VagoVersion") || this->vagoSettings->value("VagoVersion")!=GlobalVars::AppVersion){
35 this->vagoSettings->setValue("VagoVersion", GlobalVars::AppVersion);
36 iniChanged=true;
37 }
38 if(!this->vagoSettings->contains("Workspace")){
39 this->vagoSettings->setValue("Workspace", QDir::currentPath()+"/VagoWorkspace");
40 iniChanged=true;
41 }
42 if(!this->vagoSettings->contains("AeFolder")){
43
44 Util::showPopUp("Seems it's the first time you are executing Vago. \n\nPlease input your Anniversary Edition (AE) Folder.");
45 QString aefolder=Util::normalizePath(QFileDialog::getExistingDirectory(this,"Choose Anniversary Edition (AE) folder..."));
46
47 if(aefolder.isEmpty()){
48 Util::showErrorPopUp("AE folder is mandatory. Application will now exit.");
49 exit(1);
50 }
51
52 if(!aefolder.endsWith("AE")){
53 Util::showWarningPopUp("Seems the folder you selected isn't called 'AE'. \n\nIf you run in any problems you can always change it in Vago preferences window.");
54 }
55
56 this->vagoSettings->setValue("AeFolder", aefolder);
57 iniChanged=true;
58 }
59 if(!this->vagoSettings->contains("OniWindow")){
60 this->vagoSettings->setValue("OniWindow", true);
61 iniChanged=true;
62 }
63 if(!this->vagoSettings->contains("SeparateInWorkspace")){
64 this->vagoSettings->setValue("SeparateInWorkspace",true);
65 iniChanged=true;
66 }
67 if(!this->vagoSettings->contains("ConfirmExit")){
68 this->vagoSettings->setValue("ConfirmExit", false);
69 iniChanged=true;
70 }
71
72 if(iniChanged){
73 this->vagoSettings->sync();
74 }
75 ///
76
77 this->workspaceLocation=this->vagoSettings->value("Workspace").toString();
78 this->workspaceWizardsLocation=this->workspaceLocation+"/Wizards";
79 this->AeLocation=this->vagoSettings->value("AeFolder").toString();
80 this->outputFolder=this->workspaceLocation;
81
82 //Create our workspace if it doesn't exists yet
83 if(!QDir(this->workspaceLocation).exists()){
84 QDir().mkdir(this->workspaceLocation);
85 }
86 this->itemsLoaded=new QLabel(this);
87 ui->statusBar->addWidget(this->itemsLoaded);
88 this->myBar = new QProgressBar(this);
89 this->myBar->setTextVisible(false); //hides text
90
91 this->myBar->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed);
92 this->myBar->setMinimumWidth(150);
93 this->myBar->hide(); //hide while not being used
94
95 ui->statusBar->addPermanentWidget(myBar); //this adds automatically in right
96
97 this->myLogger = new Logger(); //start logger
98
99 //Initialize list pointers
100 this->listToProccess = new QStringList;
101
102 //Create a thread for do the conversion in background
103 this->myConverter = new Converter(this->myLogger,this->listToProccess);
104
105 // User interface
106 ui->mainToolBar->addWidget(ui->tbAE); //add ae installer launch button
107 ui->mainToolBar->addWidget(ui->emptySpacerLabel); //trick, we can't add directly a space so we add an empty
108 ui->mainToolBar->addWidget(ui->tbOni); //add oni launch buttonlabel
109 ui->mainToolBar->addWidget(ui->emptySpacerLabel2); //same as before
110 ui->mainToolBar->addWidget(ui->tbCommand); //add option to manual onisplit commands
111 ui->mainToolBar->addWidget(ui->emptySpacerLabel3); //same as before
112 ui->mainToolBar->addWidget(ui->tbOpenFolder); //add option to open folder with files converted etc
113
114 ui->mainToolBar->setLayoutDirection(Qt::RightToLeft);
115
116 #ifdef Q_WS_MAC
117 // setUnifiedTitleAndToolBarOnMac(true); // Qt suggests to use it on mac | http://www.slideshare.net/qtbynokia/how-to-make-your-qt-app-look-native // align on left doesn't work if active
118 ui->tbOni->setIcon(QIcon(":/new/icons/oni_icon_mac.png")); // Oni executable on mac have a different icon than windows
119 // Set mac platform the first one in the menu, and also make it checkable by default
120 ui->menuTarget_Platform->removeAction(ui->actionWindows);
121 ui->menuTarget_Platform->addAction(ui->actionWindows);
122 ui->actionWindows->setChecked(false);
123 ui->actionMac_Windows_demo->setChecked(true);
124 // Hide file menu on mac (not needed)
125 ui->menuFile->hide();
126 ui->menuFile->close();
127 //ui->menuBar->macMenu();
128 #endif
129
130 connectSlots();
131
132 //Commands Mapping
133 this->commandMap = QHash<QString, QString>();
134 mapCommands();
135
136 updateItemsLoaded(ui->twSourcesGeneral);
137
138 this->myLogger->writeString("Application started.");
139 }
140
141 MainWindow::~MainWindow()
142 {
143 delete ui;
144 this->myLogger->writeString("Application Exited.");
145 }
146
147 void MainWindow::on_actionExit_triggered()
148 {
149 close();
150 }
151
152 void MainWindow::on_actionAbout_triggered()
153 {
154 //Show preferences
155 About *aboutWindow = new About(this);
156 aboutWindow->show(); //it destroys itself when finished.
157 }
158
159 void MainWindow::on_actionAE_Package_Creator_triggered()
160 {
161 PackageWizard myWizard = PackageWizard(this->workspaceWizardsLocation, this->vagoSettings, this->myLogger);
162 myWizard.exec();
163 }
164
165 void MainWindow::on_actionSound_Wizard_triggered()
166 {
167 SoundWizard myWizard (this->workspaceWizardsLocation, this->myLogger, &this->commandMap);
168 myWizard.exec();
169 }
170
171 void MainWindow::on_tbOni_clicked()
172 {
173 QStringList arguments;
174
175 if(this->vagoSettings->value("OniWindow").toBool()){ // Run in a window?
176 arguments << "-noswitch";
177 }
178 #ifdef Q_WS_WIN
179 else{
180 arguments << "-switch"; // only supported on windows. Was added by daodan dll.
181 }
182 #endif
183
184 arguments << "-debugfiles";
185
186 if(!QProcess::startDetached(this->AeLocation+"/"+GlobalVars::OniExe,arguments,this->AeLocation)){
187 showErrStatusMessage("Oni could not be started!");
188 }
189 }
190
191 void MainWindow::on_tbAE_clicked()
192 {
193 // If the app turn out someday to a native app use QProcess::startDetached instead...
194
195 if(!QDesktopServices::openUrl("file:///"+this->AeLocation+"/AEInstaller/bin/AEInstaller2.jar")){
196 showErrStatusMessage("Could not start AE Installer!");
197 }
198 }
199
200 void MainWindow::on_tbOpenFolder_clicked()
201 {
202 QDesktopServices::openUrl(QUrl("file:///"+this->outputFolder));
203 }
204
205 void MainWindow::on_cbEnvMap_toggled(bool checked)
206 {
207 ui->leEnvMapTexture->setEnabled(checked);
208 }
209
210 void MainWindow::on_cbTexture_toggled(bool checked)
211 {
212 ui->leTextureName->setEnabled(checked);
213 }
214
215 void MainWindow::on_cbWithAnimation_toggled(bool checked)
216 {
217 ui->leAnimationName->setEnabled(checked);
218 }
219
220 void MainWindow::on_cbCamera_toggled(bool checked)
221 {
222 if(checked){
223 ui->cbGeometry->setChecked(false);
224 }
225 }
226
227 void MainWindow::on_cbGeometry_toggled(bool checked)
228 {
229 ui->leGeometryName->setEnabled(checked);
230 if(checked){
231 ui->cbCamera->setChecked(false);
232 }
233 }
234
235 void MainWindow::on_actionCheck_For_Updates_triggered()
236 {
237
238 //let's check in the web if this version is the latest
239 QNetworkAccessManager *manager = new QNetworkAccessManager(this);
240 connect(manager, SIGNAL(finished(QNetworkReply*)),
241 this, SLOT(checkVagoLastVersion(QNetworkReply*)));
242
243 manager->get(QNetworkRequest(QUrl(GlobalVars::VagoCheckUpdatesUrl)));
244
245 }
246
247 void MainWindow::checkVagoLastVersion(QNetworkReply *result){
248
249 if(result->error()==QNetworkReply::NoError){
250 QScriptEngine engine;
251 QScriptValue sc = engine.evaluate("(" + QString(result->readAll()) + ")");
252
253 // "field_version":{"und":[{"value":"0.6a","format":null,"safe_value":"0.6a"}]} //Note the use of [{}] which means it's a array of 1 element with one object inside (so the use of [0] bellow
254
255 QString newVersion = sc.property("field_version").toObject().property("und").toObject().property("0").toObject().property("value").toString();
256
257 if(newVersion!=GlobalVars::AppVersion){
258 Util::showRichPopUp("There's a new version of Vago! (v"+newVersion+")<br/><br/>"+
259 "You can download it <a href='"+GlobalVars::VagoWebUrl+"'>here</a>.");
260 }
261 else{
262 Util::showPopUp("You are using last version.");
263 }
264 }
265 else{
266 Util::showErrorPopUp("An error occurred checking last version:\n\n"+result->errorString());
267 }
268 result->deleteLater();
269 }
270
271 void MainWindow::on_pbAddSourceGeneral_clicked()
272 {
273 if(QString::compare(ui->cbFromGeneral->currentText(),"ONI",Qt::CaseSensitive)==0 && QString::compare(ui->cbToGeneral->currentText(),"DAT",Qt::CaseSensitive)==0){ //CaseSensitive is faster)
274 addFilesSource(ui->twSourcesGeneral,Util::multipleDirDialog("Choose folders with ONIs..."));
275 }
276 else{
277 addFilesSource( ui->twSourcesGeneral,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)"));
278 }
279 }
280
281 void MainWindow::on_pbAddSourceTextures_clicked()
282 {
283 addFilesSource( ui->twSourcesTextures, QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)"));
284 }
285
286 void MainWindow::on_pbAddSourceModels_clicked()
287 {
288 addFilesSource( ui->twSourcesModels,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)"));
289 }
290
291 void MainWindow::on_pbAddSourceAnimations_clicked()
292 {
293 addFilesSource( ui->twSourcesAnimations,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)"));
294 }
295
296 void MainWindow::on_pbAddSourceLevels_clicked()
297 {
298 addFilesSource( ui->twSourcesLevels,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)"));
299 }
300
301 void MainWindow::on_pbAddSourceMisc_clicked()
302 {
303 addFilesSource( ui->twSourcesMisc,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)"));
304 }
305
306 QString MainWindow::getFileOutputFolder(QString fromTo, QString myOutputFolder){
307
308 if(myOutputFolder==""){ //We may want to change to a non standart location with context menu
309 myOutputFolder=this->outputFolder;
310 }
311
312 if(this->vagoSettings->value("SeparateInWorkspace").toBool() && myOutputFolder==this->workspaceLocation){
313 myOutputFolder+="/"+ui->tabWidget->tabText(ui->tabWidget->currentIndex());
314 myOutputFolder+="/"+QString(fromTo).replace(" / ","_").replace(" > "," - ");
315 }
316 return Util::insertQuotes(myOutputFolder+"/");
317 }
318
319 void MainWindow::addFilesSource(DropTableWidget *myTable, QStringList files){
320
321 //Get Conversion pretended
322 QString from,to;
323
324 QString fromTo = getTypeConversion(myTable);
325
326 from = QString(fromTo).remove(fromTo.indexOf(" >"),fromTo.size()-1); //parse the string to get the from, only 1 time parsed by each group of files = very fast
327 to = QString(fromTo).remove(0,fromTo.lastIndexOf("> ")+2); //+2 to start after "> "
328
329 //Pre-processing (check if the files/folders received are valid), e.g. check for ONI->DAT if are only given folders and not files
330 if(QString::compare(from,"ONI",Qt::CaseSensitive)==0 && QString::compare(to,"DAT",Qt::CaseSensitive)==0){
331 //check if it's a folder
332 foreach(QString myFile, files){
333 if(!QDir(myFile).exists()){
334 showErrStatusMessage("Only folders are allowed for this operation.");
335 return;
336 }
337 }
338
339 }
340 else{
341 foreach(QString myFile, files){
342 //check if it's a file
343 if(QDir(myFile).exists()){
344 showErrStatusMessage("Only files are allowed for this operation.");
345 return;
346 }
347 }
348 }
349
350 //Build command
351 QString command, lastFileName;
352
353 QString myOutputFolder=getFileOutputFolder(fromTo);
354
355 //if folder doesn't exist onisplit will create it for us :)
356 foreach(QString currentFile, files){
357
358 currentFile=Util::normalizeAndQuote(currentFile); //insert quotes ("") in file
359
360 if(lastFileName.isEmpty()){ //Optimization: all commands are the same for each file, just replace the filename
361
362 command=getCommand(myTable,myOutputFolder,from,to,currentFile);
363
364 if(command.isEmpty()){ //something wrong was happening (not inputted a texture name?)
365 return; //stop adding files
366 }
367 currentFile=Util::cutName(currentFile);
368 }else{ //one parsing was already made just replace the filename by the old one in the command
369
370 currentFile=Util::cutName(currentFile);
371
372 command.replace(lastFileName,currentFile,Qt::CaseSensitive); //case sentive is faster
373 }
374
375 lastFileName=currentFile;
376
377 addRowTable(myTable,lastFileName,fromTo,command);
378 }
379 updateItemsLoaded(myTable);
380 }
381
382 QString MainWindow::fileParsingGeneral(QString myOutputFolder, QString from, QString to , QString file){
383
384 QString command;
385
386 if(QString::compare(from,"ONI",Qt::CaseSensitive)==0 && QString::compare(to,"DAT",Qt::CaseSensitive)==0){ //CaseSensitive is faster
387
388 QString datName;
389
390 if(ui->cbDatGeneral->isChecked()){
391 if(ui->leTargetDatGeneral->text().isEmpty()){
392 showErrStatusMessage("Checkbox '"+ui->cbDatGeneral->text()+"' is selected. The name cannot be empty.");
393 return "";
394 }
395 datName+=QString(myOutputFolder).insert(myOutputFolder.size()-1,ui->leTargetDatGeneral->text()); //set name inputted by user
396 if(!ui->leTargetDatGeneral->text().toUpper().endsWith(".DAT")){
397 datName.insert(datName.size()-1,".dat"); //append extension if necessary (-1 to maintain final quote)
398 }
399 }
400 else{
401 datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::cutName(file).remove("/")+".dat"); //if none iputted set the same name of input file
402 }
403
404 if(ui->actionWindows->isChecked()){ //is target plataform select windows?
405 return command=this->commandMap.value("general->"+from+"->"+to+"(PC)")+" "+ file + " "+datName;
406 }
407 else{
408 return command=this->commandMap.value("general->"+from+"->"+to+"(demoPCMAC)")+" "+ file + " "+datName;
409 }
410 }
411 else if(QString::compare(from,"ONI",Qt::CaseSensitive)==0 && QString::compare(to,"XML",Qt::CaseSensitive)==0 && ui->cbTRAMGeneral->isChecked()){
412 if(ui->leTRAMGeneral->text().isEmpty()){
413 showErrStatusMessage("Checkbox '"+ui->cbTRAMGeneral->text()+"' is selected. The source cannot be empty.");
414 return "";
415 }
416 return command=this->commandMap.value("general->"+from+"->"+to)+" "+myOutputFolder+" "+this->commandMap.value("general->"+ui->cbTRAMGeneral->text())+file + " "+ Util::normalizeAndQuote(ui->leTRAMGeneral->text());
417 }
418 else{
419 return command=this->commandMap.value("general->"+from+"->"+to)+" "+myOutputFolder+" "+file;
420 }
421
422 }
423
424 QString MainWindow::fileParsingTextures(QString myOutputFolder, QString from, QString to , QString file){
425
426 QString command=this->commandMap.value("textures->"+from+"->"+to)+" "+myOutputFolder;
427
428 if(ui->gbTextures->isEnabled()){ //faster than compare strings (if is DAT/ONI)
429
430 if(ui->cbMipMapsTextures->isChecked()){
431 command+=" "+this->commandMap.value("textures->"+ui->cbMipMapsTextures->text());
432 }
433
434 if(ui->cbNoUwrap->isChecked()){
435 command+=" "+this->commandMap.value("textures->"+ui->cbNoUwrap->text());
436 }
437
438 if(ui->cbNoVwrap->isChecked()){
439 command+=" "+this->commandMap.value("textures->"+ui->cbNoVwrap->text());
440 }
441
442 if(ui->cbLarge->isChecked()){
443 command+=" "+this->commandMap.value("textures->"+ui->cbLarge->text());
444 }
445
446 if(ui->rbBGR32->isChecked()){
447 command+=" "+this->commandMap.value("textures->"+ui->rbBGR32->text());
448 }
449 else if(ui->rbBGRA32->isChecked()){
450 command+=" "+this->commandMap.value("textures->"+ui->rbBGRA32->text());
451 }
452 else if(ui->rbBGR555->isChecked()){
453 command+=" "+this->commandMap.value("textures->"+ui->rbBGR555->text());
454 }
455 else if(ui->rbBGRA5551->isChecked()){
456 command+=" "+this->commandMap.value("textures->"+ui->rbBGRA5551->text());
457 }
458 else if(ui->rbBGRA444->isChecked()){
459 command+=" "+this->commandMap.value("textures->"+ui->rbBGRA444->text());
460 }
461 else{ //dxt1 checked
462 command+=" "+this->commandMap.value("textures->"+ui->rbDxt1->text());
463 }
464
465 if(ui->cbEnvMap->isChecked()){
466 if(ui->leEnvMapTexture->text().isEmpty()){
467 showErrStatusMessage("Checkbox '"+ui->cbEnvMap->text()+"' is selected. The name texture name cannot be empty.");
468 return "";
469 }
470 command+=" "+this->commandMap.value("textures->"+ui->cbEnvMap->text()) + ui->leEnvMapTexture->text().remove(".oni",Qt::CaseInsensitive);
471 }
472 }
473
474 return command+=" "+file; //add source
475 }
476
477 QString MainWindow::fileParsingModels(QString myOutputFolder, QString from, QString to , QString file){
478
479 QString command=this->commandMap.value("models->"+from+"->"+to)+" "+myOutputFolder;
480
481 //TODO: This can be optimized. When some are not enable others are.
482 if(ui->cbTexture->isChecked()){
483 if(ui->leTextureName->text().isEmpty()){
484 showErrStatusMessage("Checkbox '"+ui->cbTexture->text()+"' is selected. The name cannot be empty.");
485 return "";
486 }
487 command+=" "+this->commandMap.value("models->"+ui->cbTexture->text()) + ui->leTextureName->text().remove(".oni",Qt::CaseInsensitive);
488 }
489
490 if(ui->cbCellShading->isChecked()){
491 command+=" "+this->commandMap.value("models->"+ui->cbCellShading->text());
492 }
493
494 if(ui->cbNormals->isChecked()){
495 command+=" "+this->commandMap.value("models->"+ui->cbNormals->text());
496 }
497
498 if(ui->cbWithAnimation->isEnabled()){
499 if(ui->cbWithAnimation->isChecked()){
500 command+=" "+this->commandMap.value("models->"+ui->cbWithAnimation->text())+ui->leAnimationName->text().remove(".oni",Qt::CaseInsensitive);
501 }
502 else{
503 command+=" "+this->commandMap.value("models->No Animation");
504 }
505 }
506
507
508 return command+=" "+file; //add source
509 }
510
511 QString MainWindow::fileParsingAnimations(QString myOutputFolder, QString from, QString to , QString file){
512
513 QString command=this->commandMap.value("animations->"+from+"->"+to)+" "+myOutputFolder + " " + file ;
514
515 if(ui->cbCamera->isChecked()){
516 command+=" "+this->commandMap.value("animations->"+ui->cbCamera->text());
517 }
518 else if(ui->cbGeometry->isChecked()){
519 if(ui->leGeometryName->text().isEmpty()){
520 showErrStatusMessage("Checkbox '"+ui->cbGeometry->text()+"' is selected. The geometry file path cannot be empty.");
521 return "";
522 }
523 command+=" "+this->commandMap.value("animations->"+ui->cbGeometry->text()) + (ui->leGeometryName->text().startsWith('"')?ui->leGeometryName->text():Util::insertQuotes(ui->leGeometryName->text()));
524 }
525
526 return command;
527 }
528
529 QString MainWindow::fileParsingLevels(QString myOutputFolder, QString from, QString to , QString file){
530
531 QString datName, command;
532
533 command=this->commandMap.value("levels->"+from+"->"+to)+" "+myOutputFolder+" "+file;
534
535 if(from=="MASTER XML" && to=="DAT"){
536 command+=GlobalVars::OniSplitProcSeparator; //insert mark so we know this action will take 2 commands
537
538 QString datName;
539 if(ui->cbDatLevels->isChecked()){
540 if(ui->leTargetDatLevels->text().isEmpty()){
541 showErrStatusMessage("Checkbox '"+ui->cbDatLevels->text()+"' is selected. The name cannot be empty.");
542 return "";
543 }
544 datName+=QString(myOutputFolder).insert(myOutputFolder.size()-1,ui->leTargetDatLevels->text()); //set name inputted by user
545 if(!ui->leTargetDatLevels->text().toUpper().endsWith(".DAT")){
546 datName.insert(datName.size()-1,".dat"); //append extension if necessary (-1 to maintain final quote)
547 }
548 }
549 else{
550 datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::cutName(file).remove("/").replace(".xml",".dat",Qt::CaseInsensitive)); //if none iputted set the same name of input file
551 }
552
553 if(ui->actionWindows->isChecked()){ //is target plataform select windows?
554 command+=this->commandMap.value("general->ONI->"+to+"(PC)")+" "+myOutputFolder+" "+datName; //add second command
555 }
556 else{
557 command+=this->commandMap.value("general->ONI->"+to+"(demoPCMAC)")+" "+myOutputFolder+" "+datName; //add second command
558 }
559 }
560
561 if(ui->cbBnvLevels->isChecked()){
562
563 if(ui->leBnvLevels->text().isEmpty()){
564 showErrStatusMessage("Checkbox '"+ui->cbBnvLevels->text()+"' is selected. The BNV file cannot be empty.");
565 return "";
566 }
567 command+=" "+Util::normalizeAndQuote(ui->leBnvLevels->text());
568 }
569
570 if(ui->cbAdditionalSourcesLevels->isChecked()){
571
572 if(ui->leAdditSourcesLevels->text().isEmpty()){
573 showErrStatusMessage("Checkbox '"+ui->cbAdditionalSourcesLevels->text()+"' is selected. The source files cannot be empty.");
574 return "";
575 }
576
577 QString additionalFiles=ui->leAdditSourcesLevels->text();
578
579 int currentIndex=0, nextIndex=0;
580
581 //parse all files (separated by spaces)
582 while(true){
583 nextIndex=additionalFiles.indexOf(" ",currentIndex+1);
584
585 command += " "+Util::normalizeAndQuote(additionalFiles.mid(currentIndex,(nextIndex-currentIndex)));
586
587 if(nextIndex==-1){ //we got to the end, stop parsing
588 break;
589 }
590 currentIndex=nextIndex+1; //update currentIndex +1 for start after the separator
591 }
592 }
593
594 if(ui->cbGridsLevels->isChecked()){
595 command+=GlobalVars::OniSplitProcSeparator+this->commandMap.value("levels->"+ui->cbGridsLevels->text())+" "+Util::normalizeAndQuote(ui->leBnvLevels->text())+" "+file+" -out:"+myOutputFolder;
596 }
597
598 return command;
599 }
600
601 QString MainWindow::fileParsingMisc(QString myOutputFolder, QString from, QString to , QString file){
602 return this->commandMap.value("misc->"+from+"->"+to)+" "+myOutputFolder+" "+file;
603 }
604
605 void MainWindow::addRowTable(DropTableWidget *myTable, QString fileName, QString fromTo, QString command){
606 //Get actual number rows
607 int twSize=myTable->rowCount();
608
609 //increase the rows for the new item
610 myTable->setRowCount(twSize+1);
611
612 //Add to table and list to
613 QTableWidgetItem *newFile = new QTableWidgetItem(fileName);
614 QTableWidgetItem *newConversion = new QTableWidgetItem(fromTo);
615 QTableWidgetItem *newCommand = new QTableWidgetItem(command);
616
617 myTable->setItem(twSize,0,newFile);
618 myTable->setItem(twSize,1,newConversion);
619 myTable->setItem(twSize,2,newCommand);
620
621 myTable->updateTableToolTips(twSize); //Update tool tips
622 }
623
624 void MainWindow::on_pbConvertGeneral_clicked()
625 {
626 startConversion(ui->twSourcesGeneral);
627 }
628
629 void MainWindow::on_pbConvertTextures_clicked()
630 {
631 startConversion(ui->twSourcesTextures);
632 }
633
634 void MainWindow::on_pbConvertModels_clicked()
635 {
636 startConversion(ui->twSourcesModels);
637 }
638
639 void MainWindow::on_pbConvertAnimations_clicked()
640 {
641 startConversion(ui->twSourcesAnimations);
642 }
643
644 void MainWindow::on_pbConvertLevels_clicked()
645 {
646 startConversion(ui->twSourcesLevels);
647 }
648
649 void MainWindow::on_pbConvertMisc_clicked()
650 {
651 startConversion(ui->twSourcesMisc);
652 }
653
654 void MainWindow::startConversion(DropTableWidget *myTable){
655
656 bool ready=false;
657 for(int i=0; i<myTable->rowCount(); i++){ //There are items to process?
658 if(myTable->item(i,2)->background()!=myTable->disabledBackStyle){
659 ready=true;
660 break;
661 }
662 }
663
664 if(!ready){
665 showErrStatusMessage("Please add sources to convert first.");
666 return;
667 }
668
669 if(myBar->isVisible()){
670 Util::showErrorPopUp("Another conversion is progress. Please wait until it finishes.");
671 return;
672 }
673
674 for(int i=0; i<myTable->rowCount(); i++){
675 //Only process enabled items
676 if(myTable->item(i,2)->background()!=myTable->disabledBackStyle){
677 this->listToProccess->append(myTable->item(i,2)->text());
678 }
679 }
680
681 this->myConverter->start();
682 }
683
684 void MainWindow::TsetupProgressBar(int max){
685 this->myBar->setValue(0);
686 this->myBar->show();
687 this->myBar->setMaximum(max);
688 }
689
690 void MainWindow::TupdateProgressBar(){
691 this->myBar->setValue(this->myBar->value()+1); //more one task done
692 }
693
694 void MainWindow::TresultConversion(QString result, int numErrors){
695 QApplication::alert(this); //Show a notification if window is not active
696 this->myBar->hide();
697
698 if(numErrors!=0){
699 QString sNumErrors=QString::number(numErrors);
700 if(numErrors>1){
701 Util::showErrorLogPopUp(result+"\n This is the last of "+sNumErrors+" Errors.");
702 showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" Errors).");
703 }
704 else{
705 Util::showErrorLogPopUp(result);
706 showErrStatusMessage("Something gone wrong. Check log file.");
707 }
708
709 }
710 else{
711 showSuccessStatusMessage("Everything went well!");
712 }
713 }
714
715 void MainWindow::showErrStatusMessage(QString message){
716
717 QPalette myPalete = QPalette();
718 myPalete.setColor( QPalette::WindowText, QColor(255,0,0));
719 statusBar()->setPalette( myPalete );
720 ui->statusBar->showMessage(message,10000); //display by 10 seconds
721
722 }
723
724 void MainWindow::showSuccessStatusMessage(QString message){
725
726 QPalette myPalete = QPalette();
727 myPalete.setColor( QPalette::WindowText, QColor(0,150,0));
728 statusBar()->setPalette( myPalete );
729 ui->statusBar->showMessage(message,10000); //display by 10 seconds
730
731 }
732
733 void MainWindow::mapCommands(){
734 ////////////////////////////////////////////////////////////////////////General Commands
735 this->commandMap.insert("general->DAT->ONI","-export");
736 //this->commandMap.insert("general->ONI->DAT","-import"); //Not used.
737 this->commandMap.insert("general->ONI->DAT(PC)","-import:nosep");
738 this->commandMap.insert("general->ONI->DAT(demoPCMAC)","-import:sep");
739 this->commandMap.insert("general->ONI->XML","-extract:xml");
740 this->commandMap.insert("general->XML->ONI","-create");
741 //######################General Options
742 this->commandMap.insert("general->"+ui->cbTRAMGeneral->text(),"-anim-body:");
743 //Possible Combinations
744 this->commandMap.insertMulti("general->DAT","ONI");
745 this->commandMap.insertMulti("general->ONI","DAT");
746 this->commandMap.insertMulti("general->ONI","XML");
747 this->commandMap.insertMulti("general->XML","ONI");
748
749 ////////////////////////////////////////////////////////////////////////Textures Commands
750 this->commandMap.insert("textures->DAT / ONI->DDS","-extract:dds");
751 this->commandMap.insert("textures->DAT / ONI->TGA","-extract:tga");
752 this->commandMap.insert("textures->DAT / ONI->PNG","-extract:png");
753 this->commandMap.insert("textures->DAT / ONI->JPG","-extract:jpg");
754 this->commandMap.insert("textures->DDS / TGA / PNG / JPG->ONI","-create:txmp");
755 //######################Textures Options
756 this->commandMap.insert("textures->"+ui->rbBGR32->text(),"-format:bgr32");
757 this->commandMap.insert("textures->"+ui->rbBGRA32->text(),"-format:bgra32");
758 this->commandMap.insert("textures->"+ui->rbBGR555->text(),"-format:bgr555");
759 this->commandMap.insert("textures->"+ui->rbBGRA5551->text(),"-format:bgra5551");
760 this->commandMap.insert("textures->"+ui->rbBGRA444->text(),"-format:bgra4444");
761 this->commandMap.insert("textures->"+ui->rbDxt1->text(),"-format:dxt1");
762 this->commandMap.insert("textures->"+ui->cbMipMapsTextures->text(),"-genmipmaps");
763 this->commandMap.insert("textures->"+ui->cbNoUwrap->text(),"-nouwrap");
764 this->commandMap.insert("textures->"+ui->cbNoVwrap->text(),"-novwrap");
765 this->commandMap.insert("textures->"+ui->cbLarge->text(),"-large");
766 this->commandMap.insert("textures->"+ui->cbEnvMap->text(),"-envmap:");
767 //Possible Combinations
768 this->commandMap.insertMulti("textures->DAT / ONI","DDS");
769 this->commandMap.insertMulti("textures->DAT / ONI","TGA");
770 this->commandMap.insertMulti("textures->DAT / ONI","PNG");
771 this->commandMap.insertMulti("textures->DAT / ONI","JPG");
772 this->commandMap.insertMulti("textures->DDS / TGA / PNG / JPG","ONI");
773
774 ////////////////////////////////////////////////////////////////////////Models Commands
775 this->commandMap.insert("models->ONI->OBJ","-extract:obj");
776 this->commandMap.insert("models->ONI->DAE","-extract:dae -search "+Util::insertQuotes(this->AeLocation+"/GameDataFolder/level0_Final"));
777 this->commandMap.insert("models->OBJ->ONI","-create:m3gm");
778 this->commandMap.insert("models->DAE->ONI","-create:trbs");
779 //######################Models Options
780 this->commandMap.insert("models->"+ui->cbCellShading->text(),"-cel");
781 this->commandMap.insert("models->"+ui->cbNormals->text(),"-normals");
782 this->commandMap.insert("models->"+ui->cbTexture->text(),"-tex:");
783 this->commandMap.insert("models->"+ui->cbWithAnimation->text(),"-anim:");
784 this->commandMap.insert("models->No Animation","-noanim"); //No label with this name so can't be dynamic
785 //Possible Combinations
786 this->commandMap.insertMulti("models->ONI","OBJ");
787 this->commandMap.insertMulti("models->ONI","DAE");
788 this->commandMap.insertMulti("models->OBJ","ONI");
789 this->commandMap.insertMulti("models->DAE","ONI");
790
791 ////////////////////////////////////////////////////////////////////////Animations Commands
792 this->commandMap.insert("animations->ONI->DAE","-extract:dae");
793 this->commandMap.insert("animations->FILM DAT->XML","film2xml");
794 //######################Animations Options
795 this->commandMap.insert("animations->"+ui->cbCamera->text(),"-geom:camera");
796 this->commandMap.insert("animations->"+ui->cbGeometry->text(),"-geom:");
797 //Possible Combinations
798 this->commandMap.insertMulti("animations->ONI","DAE");
799 this->commandMap.insertMulti("animations->DAE","ONI");
800 this->commandMap.insertMulti("animations->FILM DAT","XML");
801
802 ////////////////////////////////////////////////////////////////////////Levels Commands
803 this->commandMap.insert("levels->ONI->DAE","-extract:dae -search "+Util::insertQuotes(this->AeLocation+"/GameDataFolder/level0_Final"));
804 this->commandMap.insert("levels->DAE->ONI","-create:akev");
805 this->commandMap.insert("levels->MASTER XML->DAT","-create:level");
806 this->commandMap.insert("levels->MASTER XML->ONI FILES","-create:level");
807 //######################Levels Options
808 this->commandMap.insert("levels->"+ui->cbGridsLevels->text(),"-grid:create");
809 //Possible Combinations
810 this->commandMap.insertMulti("levels->ONI","DAE");
811 this->commandMap.insertMulti("levels->DAE","ONI");
812 this->commandMap.insertMulti("levels->MASTER XML","DAT");
813 this->commandMap.insertMulti("levels->MASTER XML","ONI FILES");
814
815 ////////////////////////////////////////////////////////////////////////Misc Commands
816 this->commandMap.insert("misc->DAT / ONI->WAV","-extract:wav");
817 this->commandMap.insert("misc->DAT / ONI->AIF","-extract:aif");
818 this->commandMap.insert("misc->DAT / ONI->TXT","-extract:txt");
819 this->commandMap.insert("misc->WAV / AIF->ONI","-create");
820 this->commandMap.insert("misc->TXT->ONI","-create:subt");
821 //Possible Combinations
822 this->commandMap.insertMulti("misc->DAT / ONI","WAV");
823 this->commandMap.insertMulti("misc->DAT / ONI","AIF");
824 this->commandMap.insertMulti("misc->DAT / ONI","TXT");
825 this->commandMap.insertMulti("misc->WAV / AIF","ONI");
826 this->commandMap.insertMulti("misc->TXT","ONI");
827
828 }
829
830 void MainWindow::on_cbFromGeneral_currentIndexChanged(const QString &arg1)
831 {
832 updateComboBox(arg1, ui->cbToGeneral, "general");
833 }
834
835 void MainWindow::on_cbFromTextures_currentIndexChanged(const QString &arg1)
836 {
837 //Options are only used for DAT/ONI -> Image
838 if(QString::compare(arg1,"DAT / ONI",Qt::CaseSensitive)==0){ //case sensitive is faster
839 ui->gbTextures->setEnabled(false);
840 }
841 else{
842 ui->gbTextures->setEnabled(true);
843 }
844
845 updateComboBox(arg1, ui->cbToTextures, "textures");
846 }
847
848 void MainWindow::on_cbFromModels_currentIndexChanged(const QString &arg1)
849 {
850
851 ui->cbCellShading->setEnabled(false);
852 ui->cbCellShading->setChecked(false);
853 ui->cbNormals->setEnabled(false);
854 ui->cbNormals->setChecked(false);
855 ui->cbTexture->setEnabled(false);
856 ui->cbTexture->setChecked(false);
857 ui->cbWithAnimation->setEnabled(false);
858 ui->cbWithAnimation->setChecked(false);
859
860 if(QString::compare(arg1,"OBJ",Qt::CaseSensitive)==0){ //case sensitive is faster
861 ui->cbTexture->setEnabled(true);
862 }
863 else if(QString::compare(arg1,"DAE",Qt::CaseSensitive)==0){
864 ui->cbCellShading->setEnabled(true);
865 ui->cbNormals->setEnabled(true);
866 }
867
868 updateComboBox(arg1, ui->cbToModels, "models");
869 }
870
871 void MainWindow::on_cbFromAnimations_currentIndexChanged(const QString &arg1)
872 {
873 ui->cbCamera->setEnabled(false);
874 ui->cbCamera->setChecked(false);
875 ui->cbGeometry->setEnabled(false);
876 ui->cbGeometry->setChecked(false);
877
878 if(QString::compare(arg1,"ONI",Qt::CaseSensitive)==0){ //case sensitive is faster
879 ui->cbCamera->setEnabled(true);
880 ui->cbGeometry->setEnabled(true);
881 }
882
883 updateComboBox(arg1, ui->cbToAnimations, "animations");
884 }
885
886 void MainWindow::on_cbFromLevels_currentIndexChanged(const QString &arg1)
887 {
888 updateComboBox(arg1, ui->cbToLevels, "levels");
889 }
890
891 void MainWindow::on_cbFromMisc_currentIndexChanged(const QString &arg1)
892 {
893 updateComboBox(arg1, ui->cbToMisc, "misc");
894 }
895
896 void MainWindow::updateComboBox(const QString &arg1, QComboBox *comboBox, const QString &identifier){
897 comboBox->clear();
898
899 QStringList toUpdate=QStringList();
900
901 QStringList values=commandMap.values(identifier+"->"+arg1);
902
903 for (int i = values.size()-1; i >= 0; i--){ //By defaut MultiItems have the inversed order (http://qt-project.org/doc/qt-4.8/qhash.html#insertMulti)
904 toUpdate << values.at(i);
905 }
906
907 comboBox->addItems(toUpdate);
908 }
909
910
911 void MainWindow::on_actionWindows_triggered()
912 {
913 ui->actionWindows->setChecked(true);
914 ui->actionMac_Windows_demo->setChecked(false);
915 }
916
917 void MainWindow::on_actionMac_Windows_demo_triggered()
918 {
919 ui->actionMac_Windows_demo->setChecked(true);
920 ui->actionWindows->setChecked(false);
921 }
922
923 void MainWindow::on_pbRemoveSourceGeneral_clicked()
924 {
925 removeTableContents( ui->twSourcesGeneral);
926 }
927
928 void MainWindow::on_pbRemoveSourceTextures_clicked()
929 {
930 removeTableContents(ui->twSourcesTextures);
931 }
932
933 void MainWindow::on_pbRemoveSourceModels_clicked()
934 {
935 removeTableContents(ui->twSourcesModels);
936 }
937
938 void MainWindow::on_pbRemoveSourceAnimations_clicked()
939 {
940 removeTableContents(ui->twSourcesAnimations);
941 }
942
943 void MainWindow::on_pbRemoveSourceLevels_clicked()
944 {
945 removeTableContents(ui->twSourcesLevels);
946 }
947
948 void MainWindow::on_pbRemoveSourceMisc_clicked()
949 {
950 removeTableContents(ui->twSourcesMisc);
951 }
952
953 void MainWindow::on_pbClearSourcesGeneral_clicked()
954 {
955 clearTableContents(ui->twSourcesGeneral);
956 }
957
958 void MainWindow::on_pbClearSourcesTextures_clicked()
959 {
960 clearTableContents(ui->twSourcesTextures);
961 }
962
963 void MainWindow::on_pbClearSourcesModels_clicked()
964 {
965 clearTableContents(ui->twSourcesModels);
966 }
967
968 void MainWindow::on_pbClearSourcesAnimations_clicked()
969 {
970 clearTableContents(ui->twSourcesAnimations);
971 }
972
973 void MainWindow::on_pbClearSourcesLevels_clicked()
974 {
975 clearTableContents(ui->twSourcesLevels);
976 }
977
978 void MainWindow::on_pbClearSourcesMisc_clicked()
979 {
980 clearTableContents(ui->twSourcesMisc);
981 }
982
983 void MainWindow::removeTableContents(DropTableWidget *myTable){
984 int size = myTable->selectionModel()->selectedRows().size();
985
986 if(size==0){
987 Util::showPopUp("Select a row first.");
988 return;
989 }
990
991 if(Util::showQuestionPopUp(this,"Are you sure you want to delete the selected rows?")){
992 for(int i=0; i<size; i++){
993 //myTable->removeRow(myTable->selectedItems().at(size-i-1)->row());
994 myTable->removeRow(myTable->selectionModel()->selectedRows().at(size-i-1).row());
995 }
996 updateItemsLoaded(myTable);
997 }
998 }
999
1000 void MainWindow::clearTableContents(DropTableWidget *myTable){
1001 if(myTable->rowCount()==0){
1002 Util::showPopUp("Nothing to clear.");
1003 return;
1004 }
1005
1006 if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?")){
1007 myTable->clearContents();
1008 myTable->setRowCount(0);
1009 }
1010 updateItemsLoaded(myTable);
1011 }
1012
1013
1014 void MainWindow::on_actionPreferences_triggered()
1015 {
1016 //Show preferences
1017 Preferences *preferencesWindow = new Preferences(this,this->vagoSettings);
1018 preferencesWindow->exec(); //it destroys itself when finished.
1019 }
1020
1021
1022 void MainWindow::closeEvent(QCloseEvent *event){
1023 if(this->vagoSettings->value("ConfirmExit").toBool()){
1024 if(!Util::showQuestionPopUp(this,"Exit Vago?")){
1025 event->ignore();
1026 }
1027 }
1028 }
1029
1030 void MainWindow::on_cbToGeneral_currentIndexChanged(const QString &arg1)
1031 {
1032
1033 ui->cbDatGeneral->setEnabled(false);
1034 ui->cbDatGeneral->setChecked(false);
1035 ui->cbTRAMGeneral->setEnabled(false);
1036 ui->cbTRAMGeneral->setChecked(false);
1037
1038 if(QString::compare(ui->cbFromGeneral->currentText(),"ONI",Qt::CaseSensitive)==0){
1039 if(QString::compare(arg1,"DAT",Qt::CaseSensitive)==0){
1040 ui->cbDatGeneral->setEnabled(true);
1041 }
1042 else{
1043 ui->cbTRAMGeneral->setEnabled(true);
1044 }
1045 }
1046
1047 }
1048
1049 void MainWindow::on_cbToModels_currentIndexChanged(const QString &arg1)
1050 {
1051 ui->cbWithAnimation->setEnabled(false);
1052 ui->cbWithAnimation->setChecked(false);
1053
1054 if(arg1=="DAE"){
1055 ui->cbWithAnimation->setEnabled(true);
1056 }
1057 }
1058
1059 void MainWindow::on_cbToLevels_currentIndexChanged(const QString &arg1)
1060 {
1061
1062 ui->cbDatLevels->setEnabled(false);
1063 ui->cbDatLevels->setChecked(false);
1064 ui->cbBnvLevels->setEnabled(false);
1065 ui->cbBnvLevels->setChecked(false);
1066 ui->cbAdditionalSourcesLevels->setEnabled(false);
1067 ui->cbAdditionalSourcesLevels->setChecked(false);
1068 ui->cbGridsLevels->setEnabled(false);
1069 ui->cbGridsLevels->setChecked(false);
1070
1071 if(ui->cbFromLevels->currentText()=="MASTER XML" && arg1=="DAT"){
1072 ui->cbDatLevels->setEnabled(true);
1073 }
1074 else if(ui->cbFromLevels->currentText()=="DAE" && arg1=="ONI"){
1075 ui->cbBnvLevels->setEnabled(true);
1076 ui->cbAdditionalSourcesLevels->setEnabled(true);
1077 }
1078 }
1079
1080 void MainWindow::on_cbDatGeneral_toggled(bool checked)
1081 {
1082 ui->leTargetDatGeneral->setEnabled(checked);
1083 }
1084
1085 void MainWindow::on_cbTRAMGeneral_toggled(bool checked)
1086 {
1087 ui->leTRAMGeneral->setEnabled(checked);
1088 if(checked){
1089 QString file=QFileDialog::getOpenFileName(this,"Choose the TRAM.oni file...","./" , "All Files (*.*)");
1090 if(!file.isEmpty()){
1091 ui->leTRAMGeneral->setText(file);
1092 }
1093 }
1094 }
1095
1096 void MainWindow::on_cbDatLevels_toggled(bool checked)
1097 {
1098 ui->leTargetDatLevels->setEnabled(checked);
1099 }
1100
1101 void MainWindow::on_cbBnvLevels_toggled(bool checked)
1102 {
1103 ui->leBnvLevels->setEnabled(checked);
1104 ui->cbGridsLevels->setEnabled(checked);
1105 ui->cbGridsLevels->setChecked(checked);
1106 if(checked){
1107 QString file=QFileDialog::getOpenFileName(this,"Choose the BNV.dae file...","./" , "All Files (*.*)");
1108 if(!file.isEmpty()){
1109 ui->leBnvLevels->setText(file);
1110 }
1111 }
1112 }
1113
1114 void MainWindow::on_cbAdditionalSourcesLevels_toggled(bool checked)
1115 {
1116 ui->leAdditSourcesLevels->setEnabled(checked);
1117
1118 if(checked){
1119 QStringList filesSelected=QFileDialog::getOpenFileNames(this,"Choose the additional .dae files...","./" , "All Files (*.*)");
1120 QString filesJoined;
1121 int size=filesSelected.size();
1122
1123 if(!filesSelected.isEmpty()){
1124 for(int i=0; i<size-1; i++){
1125 filesJoined+=filesSelected.at(i)+" ";
1126 }
1127 filesJoined+=filesSelected.at(size-1); //last doesn't have space after
1128 ui->leAdditSourcesLevels->setText(filesJoined);
1129 }
1130
1131 }
1132 }
1133
1134 void MainWindow::on_actionCheck_OniSplit_version_triggered()
1135 {
1136 QProcess *myProcess = new QProcess();
1137 myProcess->start(GlobalVars::OniSplitExeName+" -version");
1138 myProcess->waitForFinished(-1);
1139 QString result=myProcess->readAllStandardOutput();
1140 delete myProcess;
1141 Util::showPopUp("This Vago version was built with base in OniSplit version "+GlobalVars::BuiltOniSplitVersion+"\n\nActual version is:\n"+result);
1142 }
1143
1144 void MainWindow::on_actionCheck_xmlTools_version_triggered()
1145 {
1146 QProcess *myProcess = new QProcess();
1147 myProcess->start(GlobalVars::XmlToolsExeName+" version");
1148 myProcess->waitForFinished(-1);
1149 QString result=myProcess->readLine();
1150 delete myProcess;
1151 Util::showPopUp("This Vago version was built with base in xmlTools version "+GlobalVars::BuiltXmlToolsVersion+"\n\nActual version is:\n"+result);
1152 }
1153
1154 /**
1155 Update items loaded
1156 **/
1157 void MainWindow::on_tabWidget_selected(const QString &arg1)
1158 {
1159 if(arg1.compare("General",Qt::CaseSensitive)==0){ //case sentive is faster
1160 updateItemsLoaded(ui->twSourcesGeneral);
1161 }
1162 else if(arg1.compare("Textures",Qt::CaseSensitive)==0){
1163 updateItemsLoaded(ui->twSourcesTextures);
1164 }
1165 else if(arg1.compare("Models",Qt::CaseSensitive)==0){
1166 updateItemsLoaded(ui->twSourcesModels);
1167 }
1168 else if(arg1.compare("Levels",Qt::CaseSensitive)==0){
1169 updateItemsLoaded(ui->twSourcesLevels);
1170 }
1171 else{
1172 updateItemsLoaded(ui->twSourcesMisc);
1173 }
1174 }
1175
1176 void MainWindow::updateItemsLoaded(DropTableWidget *currentTable){
1177
1178 int numItems=currentTable->rowCount();
1179
1180 this->itemsLoaded->setText(QString().setNum(numItems)+ (numItems==1?" item ":" items ") +"loaded");
1181 }
1182
1183 void MainWindow::on_tbCommand_clicked()
1184 {
1185 //Show preferences
1186 ManualCommands *commandsWindow = new ManualCommands(this);
1187 commandsWindow->show(); //it destroys itself when finished.
1188 }
1189
1190 void MainWindow::on_actionWorkspace_triggered()
1191 {
1192 ui->actionWorkspace->setChecked(true);
1193 ui->actionOther->setChecked(false);
1194 this->outputFolder=this->workspaceLocation;
1195 ui->tbOpenFolder->setToolTip("Open Vago workspace");
1196 showSuccessStatusMessage("Vago is now outputting the NEW items for Vago workspace.");
1197 }
1198
1199 void MainWindow::on_actionOther_triggered()
1200 {
1201 QString newDir=QFileDialog::getExistingDirectory(this,"Choose the folder for output NEW files directly...",this->AeLocation+"/GameDataFolder");
1202 newDir=Util::normalizePath(newDir);
1203
1204 if(newDir.isEmpty()){
1205 ui->actionOther->setChecked(false);
1206 return; //do nothing
1207 }
1208
1209 if(newDir==this->workspaceLocation){
1210 on_actionWorkspace_triggered(); //set it to vago workspace
1211 return;
1212 }
1213
1214 ui->actionOther->setChecked(true);
1215 ui->actionWorkspace->setChecked(false);
1216
1217 this->outputFolder=newDir;
1218
1219 QString newDirName=Util::cutName(newDir);
1220 ui->tbOpenFolder->setToolTip("Open "+newDirName+" output folder");
1221 showSuccessStatusMessage("Vago is now outputting the NEW items for "+newDirName+".");
1222 }
1223
1224 void MainWindow::on_actionView_log_triggered()
1225 {
1226 Util::openLogFile();
1227 }
1228
1229 QString MainWindow::getTypeConversion(DropTableWidget *myTable){
1230 QString from,to;
1231
1232 if(myTable==ui->twSourcesGeneral){
1233 from=ui->cbFromGeneral->currentText();
1234 to=ui->cbToGeneral->currentText();
1235 }
1236 else if(myTable==ui->twSourcesTextures){
1237 from=ui->cbFromTextures->currentText();
1238 to=ui->cbToTextures->currentText();
1239 }
1240 else if(myTable==ui->twSourcesModels){
1241 from=ui->cbFromModels->currentText();
1242 to=ui->cbToModels->currentText();
1243 }
1244 else if(myTable==ui->twSourcesAnimations){
1245 from=ui->cbFromAnimations->currentText();
1246 to=ui->cbToAnimations->currentText();
1247 }
1248 else if(myTable==ui->twSourcesLevels){
1249 from=ui->cbFromLevels->currentText();
1250 to=ui->cbToLevels->currentText();
1251 }
1252 else{
1253 from=ui->cbFromMisc->currentText();
1254 to=ui->cbToMisc->currentText();
1255 }
1256
1257 return from + " > " + to;
1258 }
1259
1260 //Drop table widget context menu
1261 void MainWindow::dtContextMenu(DropTableWidget* myTable, QContextMenuEvent *event){
1262 QModelIndex index = myTable->indexAt(event->pos());
1263
1264 //item exists?
1265 if(!index.isValid())
1266 return;
1267
1268 if(myTable->selectionModel()->selectedRows().size()==0){ //No multiple rows selected
1269 myTable->selectRow(myTable->itemAt(event->pos())->row()); //select all the row of the item clicked
1270 }
1271
1272 QList<int> selectedRows = QList<int>();
1273
1274 foreach(QModelIndex rowItem, myTable->selectionModel()->selectedRows()){
1275 selectedRows << rowItem.row();
1276 }
1277
1278 QMenu *menu = new QMenu();
1279 QAction *copy = new QAction("Copy",myTable);
1280 QAction *moveUp = new QAction("Move Up",myTable);
1281 QAction *moveDown = new QAction("Move Down",myTable);
1282 QAction *changeOptions = new QAction("Change To Current Options",myTable);
1283 QMenu *changeOutput = new QMenu("Change Output for:");
1284 QAction *outWorkspace = new QAction("Workspace",myTable);
1285 QAction *outCurrOutput = new QAction("Current Output Folder",myTable);
1286 QAction *outOther = new QAction("Other...",myTable);
1287 QAction *edisable = new QAction("Enable/Disable",myTable);
1288
1289 menu->addAction(copy);
1290 menu->addSeparator();
1291 menu->addAction(moveUp);
1292 menu->addAction(moveDown);
1293 menu->addSeparator();
1294 menu->addAction(changeOptions);
1295 menu->addMenu(changeOutput);
1296 changeOutput->addActions(QList<QAction*>() << outWorkspace << outCurrOutput << outOther);
1297 menu->addAction(edisable);
1298
1299
1300 //if it's in the first row it can't be setted up
1301 if(selectedRows.at(0)==0){
1302 moveUp->setEnabled(false);
1303 }
1304
1305 //if we are at bottom we can't go down
1306 if(selectedRows.at(selectedRows.size()-1)==myTable->rowCount()-1){
1307 moveDown->setEnabled(false);
1308 }
1309
1310 //Can we change the settings? (the conversion must be the same)
1311 QString currentSettings = (getTypeConversion(myTable)); //call function at the mainWindow with a signal (different threads?)
1312 foreach(int row, selectedRows){
1313 if( myTable->item(row,1)->text() != currentSettings){ //If we find out any of the selected items can't be convert disable operation
1314 changeOptions->setEnabled(false);
1315 break;
1316 }
1317 }
1318
1319 QAction* selectedOption = menu->exec(event->globalPos());
1320
1321 if(selectedOption==copy){
1322 //Let's copy the contents to the clipboard
1323
1324 QString toCopy;
1325
1326 int size=selectedRows.size();
1327
1328 //Let's format it a bit...
1329 for(int i=0; i<size; i++){
1330 for(int j=0; j<myTable->columnCount(); j++){
1331 toCopy+=myTable->item(selectedRows.at(i),j)->text();
1332 if(j!=myTable->columnCount()-1){
1333 toCopy+="\t";
1334 }
1335 }
1336 if(i!=size-1){
1337 toCopy+="\n";
1338 }
1339 }
1340
1341 QApplication::clipboard()->setText(toCopy);
1342 showSuccessStatusMessage(QString::number(size) + (size==1?" item ":" items ")+ "copied to the clipboard");
1343 }
1344 else if(selectedOption==moveUp){
1345 qSort(selectedRows); //let's order the selections by the row number, so we know exactly how to swap it
1346 myTable->swapPositions(selectedRows,-1);
1347 }
1348 else if(selectedOption==moveDown){
1349 qSort(selectedRows);
1350 myTable->swapPositions(selectedRows,+1);
1351 }
1352 else if(selectedOption==changeOptions){
1353 changeToCurrentSettings(selectedRows,myTable);
1354 }
1355 else if(selectedOption==outWorkspace){
1356 changeItemsOutput(myTable,selectedRows,this->workspaceLocation);
1357 }
1358 else if(selectedOption==outCurrOutput){
1359 changeItemsOutput(myTable,selectedRows,this->outputFolder);
1360 }
1361 else if(selectedOption==outOther){
1362
1363 QString newDir=QFileDialog::getExistingDirectory(this,"Choose the folder for the output of the files selected...",this->AeLocation+"/GameDataFolder");
1364 newDir=Util::normalizePath(newDir);
1365
1366 if(newDir.isEmpty()){
1367 return; //do nothing
1368 }
1369
1370 changeItemsOutput(myTable,selectedRows,newDir);
1371
1372 }
1373 else if(selectedOption==edisable){
1374
1375 int enabledCount=0, disabledCount=0;
1376
1377 for(int i=0; i<selectedRows.size(); i++){
1378
1379 for(int j=0; j<myTable->columnCount(); j++){
1380 QTableWidgetItem *currentItem=myTable->item(selectedRows.at(i),j);
1381
1382 if(currentItem->background()!=myTable->disabledBackStyle){
1383 myTable->setDisableStyleWidgetItem(currentItem);
1384 if(j==0){ //Only count the row, not the columns
1385 disabledCount++;
1386 }
1387 }
1388 else{ //reset to initial state (enable)
1389 myTable->resetStyleWidgetItem(currentItem);
1390 if(j==0){
1391 enabledCount++;
1392 }
1393 }
1394 }
1395 }
1396
1397 QString result;
1398
1399 if(enabledCount!=0){
1400 result+=QString::number(enabledCount) + (enabledCount==1?" item ":" items ") + "Enabled";
1401 }
1402 if(enabledCount!=0 && disabledCount!=0){
1403 result+=" and ";
1404 }
1405 if(disabledCount!=0){
1406 result+=QString::number(disabledCount) + (disabledCount==1?" item ":" items ") + "Disabled";
1407 }
1408
1409 showSuccessStatusMessage(result);
1410 }
1411
1412 delete copy;
1413 delete moveUp;
1414 delete moveDown;
1415 delete changeOptions;
1416 delete outWorkspace;
1417 delete outCurrOutput;
1418 delete outOther;
1419 delete changeOutput;
1420 delete edisable;
1421 delete menu;
1422 }
1423
1424 void MainWindow::changeToCurrentSettings(QList<int> rows, DropTableWidget* myTable){
1425 //construct a command for each one
1426 //Output a status message saying the number of changed files
1427 QString fromTo=getTypeConversion(myTable);
1428 QString from = QString(fromTo).remove(fromTo.indexOf(" >"),fromTo.size()-1); //parse the string to get the from, only 1 time parsed by each group of files = very fast
1429 QString to = QString(fromTo).remove(0,fromTo.lastIndexOf("> ")+2); //+2 to start after "> "
1430
1431 QString command;
1432
1433 foreach(int row, rows){
1434
1435 command=getCommand(myTable,getFileOutputFolder(fromTo,myTable->getOutputAbsolute(row)),from,to,myTable->getFileAbsolute(row));
1436
1437 if(command.isEmpty()){ //something wrong was happening (not inputted a texture name?)
1438 return; //stop changing settings
1439 }
1440
1441 myTable->item(row,2)->setText(command); //update settings to the current row
1442 myTable->updateTableToolTips(row);
1443 }
1444
1445 showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed to the current settings");
1446 }
1447
1448 void MainWindow::changeItemsOutput(DropTableWidget* myTable, QList<int> rows, QString newOutput){
1449
1450 QString command, currentAbsoluteFile, fromTo, from, to;
1451
1452 foreach(int row, rows){ //No optimization possible here, commands may be different
1453 fromTo=myTable->item(row,1)->text();
1454 from = QString(fromTo).remove(fromTo.indexOf(" >"),fromTo.size()-1); //parse the string to get the from
1455 to = QString(fromTo).remove(0,fromTo.lastIndexOf("> ")+2); //+2 to start after "> "
1456
1457 currentAbsoluteFile=myTable->getFileAbsolute(row);
1458 command=getCommand(myTable,getFileOutputFolder(fromTo,newOutput),from,to,currentAbsoluteFile);
1459
1460 if(command.isEmpty()){ //something wrong was happening (not inputted a texture name?)
1461 return; //stop changing output
1462 }
1463
1464 myTable->item(row,2)->setText(command); //update command to the current row
1465 myTable->updateTableToolTips(row);
1466 }
1467
1468 showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed the output to "+(newOutput!=this->workspaceLocation?Util::cutName(newOutput):"Vago workspace"));
1469 }
1470
1471 QString MainWindow::getCommand(DropTableWidget* myTable, QString myOutputFolder, QString from, QString to , QString file){
1472 if(myTable==ui->twSourcesGeneral){ //So we only need to parse one command.
1473 return fileParsingGeneral(myOutputFolder,from,to,file);
1474 }
1475 else if(myTable==ui->twSourcesTextures){
1476 return fileParsingTextures(myOutputFolder,from,to,file);
1477 }
1478 else if(myTable==ui->twSourcesModels){
1479 return fileParsingModels(myOutputFolder,from,to,file);
1480 }
1481 else if(myTable==ui->twSourcesAnimations){
1482 return fileParsingAnimations(myOutputFolder,from,to,file);
1483 }
1484 else if(myTable==ui->twSourcesLevels){
1485 return fileParsingLevels(myOutputFolder,from,to,file);
1486 }
1487 else{
1488 return fileParsingMisc(myOutputFolder,from,to,file);
1489 }
1490
1491 }
1492
1493 void MainWindow::connectSlots(){
1494
1495 //This signal is for thread that is working setup the progress bar (make it visible and set it's min-max)
1496 connect(myConverter, SIGNAL(setupPB(int)), this, SLOT(TsetupProgressBar(int)), Qt::BlockingQueuedConnection);
1497
1498 //This signal is for thread that is working can update the progress bar of the gui
1499 connect(myConverter, SIGNAL(taskDone()), this, SLOT(TupdateProgressBar()),Qt::BlockingQueuedConnection);
1500
1501 //This signal is for thread that is working can show the result of a conversion
1502 connect(myConverter, SIGNAL(resultConversion(QString,int)), this, SLOT(TresultConversion(QString,int)));
1503
1504 //Drop signal for General table
1505 connect(ui->twSourcesGeneral, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList)));
1506
1507 //Drop signal for Textures table
1508 connect(ui->twSourcesTextures, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList)));
1509
1510 //Drop signal for Models table
1511 connect(ui->twSourcesModels, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList)));
1512
1513 //Drop signal for Animations table
1514 connect(ui->twSourcesAnimations, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList)));
1515
1516 //Drop signal for Levels table
1517 connect(ui->twSourcesLevels, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList)));
1518
1519 //Drop signal for Misc table
1520 connect(ui->twSourcesMisc, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList)));
1521
1522 //Context menu for General table
1523 connect(ui->twSourcesGeneral, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*)));
1524
1525 //Context menu for Textures table
1526 connect(ui->twSourcesTextures, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*)));
1527
1528 //Context menu for Models table
1529 connect(ui->twSourcesModels, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*)));
1530
1531 //Context menu for Animations table
1532 connect(ui->twSourcesAnimations, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*)));
1533
1534 //Context menu for Levels table
1535 connect(ui->twSourcesLevels, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*)));
1536
1537 //Context menu for Misc table
1538 connect(ui->twSourcesMisc, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*)));
1539 }
1540
1541