ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/mainwindow.cpp
Revision: 790
Committed: Sat Apr 6 20:54:26 2013 UTC (12 years, 6 months ago) by s10k
Content type: text/x-c++src
Original Path: Vago/trunk/Vago/mainwindow.cpp
File size: 58596 byte(s)
Log Message:
Some updates in 0.8 version related with Mac OS. They should improve the application on Mac.

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