--- Vago/trunk/Vago/mainwindow.cpp 2014/01/08 11:32:55 897 +++ Vago/trunk/Vago/mainwindow.cpp 2016/03/24 22:28:41 1035 @@ -9,26 +9,24 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); - this->AppDir=getOSIndependentAppPath(); + this->myLogger = new Logger(Util::getAppPath()); //start logger - this->myLogger = new Logger(this->AppDir); //start logger - - this->myLogger->writeString("Detected AppDir: "+this->AppDir); + this->myLogger->writeString("Detected AppDir: "+Util::getAppPath()); this->myLogger->writeString("True app dir: "+QDir::currentPath()); this->setWindowTitle("Vago v"+GlobalVars::AppVersion); - if(!QFile::exists(this->AppDir+"/"+GlobalVars::OniSplitString)){ + if(!QFile::exists(Util::getAppPath()+"/"+GlobalVars::OniSplitString)){ 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."); exit(1); } - if(!QFile::exists(this->AppDir+"/"+GlobalVars::XmlToolsString)){ + if(!QFile::exists(Util::getAppPath()+"/"+GlobalVars::XmlToolsString)){ 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."); exit(1); } - this->vagoSettings = new QSettings(this->AppDir + "/" + this->VagoSettingsName, QSettings::IniFormat); + this->vagoSettings = new QSettings(Util::getAppPath() + "/" + this->VagoSettingsName, QSettings::IniFormat); //First Execution? Old configuration? Settings missed? bool iniChanged=false; @@ -37,7 +35,7 @@ MainWindow::MainWindow(QWidget *parent) iniChanged=true; } if(!this->vagoSettings->contains("Workspace")){ - this->vagoSettings->setValue("Workspace", this->AppDir+"/VagoWorkspace"); + this->vagoSettings->setValue("Workspace", Util::getAppPath()+"/VagoWorkspace"); iniChanged=true; } if(!this->vagoSettings->contains("AeFolder")){ @@ -77,6 +75,12 @@ MainWindow::MainWindow(QWidget *parent) this->vagoSettings->setValue("ConfirmExit", false); iniChanged=true; } +#ifdef Q_OS_MAC + if(!this->vagoSettings->contains("useYesAsDefaultWhenRemovingItems")){ + this->vagoSettings->setValue("useYesAsDefaultWhenRemovingItems", false); + iniChanged=true; + } +#endif if(iniChanged){ this->vagoSettings->sync(); @@ -89,6 +93,9 @@ MainWindow::MainWindow(QWidget *parent) this->outputFolder=this->workspaceLocation; this->startedWindowWidth=this->vagoSettings->value("WindowWidth").toInt(); this->startedWindowHeight=this->vagoSettings->value("WindowHeight").toInt(); +#ifdef Q_OS_MAC + this->useYesAsDefaultWhenRemovingItems=this->vagoSettings->value("useYesAsDefaultWhenRemovingItems").toBool(); +#endif //Create our workspace if it doesn't exists yet if(!QDir(this->workspaceLocation).exists()){ @@ -111,7 +118,7 @@ MainWindow::MainWindow(QWidget *parent) this->listToProccess = new QStringList; //Create a thread for do the conversion in background - this->myConverter = new Converter(this->AppDir,this->myLogger,this->listToProccess); + this->myConverter = new Converter(Util::getAppPath(),this->myLogger,this->listToProccess); // User interface ui->mainToolBar->addWidget(ui->tbAE); //add ae installer launch button @@ -126,7 +133,7 @@ MainWindow::MainWindow(QWidget *parent) setConverterButtonsSize(); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC // 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 ui->tbOni->setIcon(QIcon(":/new/icons/oni_icon_mac.png")); // Oni executable on mac have a different icon than windows // Set mac platform the first one in the menu, and also make it checkable by default @@ -179,7 +186,7 @@ void MainWindow::on_actionAE_Package_Cre void MainWindow::on_actionSound_Wizard_triggered() { - SoundWizard myWizard (this->AppDir, this->workspaceWizardsLocation, this->myLogger, &this->commandMap); + SoundWizard myWizard (Util::getAppPath(), this->workspaceWizardsLocation, this->myLogger, &this->commandMap); myWizard.exec(); } @@ -190,7 +197,7 @@ void MainWindow::on_tbOni_clicked() if(this->vagoSettings->value("OniWindow").toBool()){ // Run in a window? arguments << "-noswitch"; } -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN else{ arguments << "-switch"; // only supported on windows. Was added by daodan dll. } @@ -530,7 +537,13 @@ QString MainWindow::fileParsingLevels(QS command+=":"+ui->leSpecificFilesLevels->text(); } - command+=" "+myOutputFolder+" "+file; + + if(from=="DAT" && to=="ONI FILES"){ // extract files to a subdir with the files name ex: level0_Final + command += " " + myOutputFolder.insert(myOutputFolder.size()-2,QString(Util::cutName(file)).replace(".dat","")) + " " + file; + } + else{ + command+=" "+myOutputFolder+" "+file; + } } @@ -1046,12 +1059,24 @@ void MainWindow::on_pbClearSourcesMisc_c void MainWindow::removeTableContents(DropTableWidget *myTable){ int size = myTable->selectionModel()->selectedRows().size(); + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton; // default button for clear asking question, only customizable in mac os + if(size==0){ Util::showPopUp("Select a row first."); return; } - if(Util::showQuestionPopUp(this,"Are you sure you want to delete the selected rows?")){ +#ifdef Q_OS_MAC + if(this->useYesAsDefaultWhenRemovingItems){ + defaultButton = QMessageBox::Yes; + } + else{ + defaultButton = QMessageBox::No; + } +#endif + + + if(Util::showQuestionPopUp(this,"Are you sure you want to delete the selected rows?",defaultButton)){ for(int i=0; iremoveRow(myTable->selectedItems().at(size-i-1)->row()); myTable->removeRow(myTable->selectionModel()->selectedRows().at(size-i-1).row()); @@ -1061,12 +1086,24 @@ void MainWindow::removeTableContents(Dro } void MainWindow::clearTableContents(DropTableWidget *myTable){ + + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton; // default button for clear asking question, only customizable in mac os + if(myTable->rowCount()==0){ Util::showPopUp("Nothing to clear."); return; } - if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?")){ +#ifdef Q_OS_MAC + if(this->useYesAsDefaultWhenRemovingItems){ + defaultButton = QMessageBox::Yes; + } + else{ + defaultButton = QMessageBox::No; + } +#endif + + if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?",defaultButton)){ myTable->clearContents(); myTable->setRowCount(0); } @@ -1149,8 +1186,8 @@ void MainWindow::on_cbWithTRBS_ONCC_togg void MainWindow::on_actionCheck_OniSplit_version_triggered() { QProcess *myProcess = new QProcess(); - myProcess->setWorkingDirectory(this->AppDir); - myProcess->start(GlobalVars::OniSplitExeName+" -version"); + myProcess->setWorkingDirectory(Util::getAppPath()); + myProcess->start(Util::getOniSplitExeName()+" -version"); myProcess->waitForFinished(-1); QString result=myProcess->readAllStandardOutput(); delete myProcess; @@ -1160,8 +1197,8 @@ void MainWindow::on_actionCheck_OniSplit void MainWindow::on_actionCheck_xmlTools_version_triggered() { QProcess *myProcess = new QProcess(); - myProcess->setWorkingDirectory(this->AppDir); - myProcess->start(GlobalVars::XmlToolsExeName+" version"); + myProcess->setWorkingDirectory(Util::getAppPath()); + myProcess->start(Util::getXmlToolsExeName()+" version"); myProcess->waitForFinished(-1); QString result=myProcess->readLine(); delete myProcess; @@ -1170,19 +1207,24 @@ void MainWindow::on_actionCheck_xmlTools /** Update items loaded - **/ -void MainWindow::on_tabWidget_selected(const QString &arg1) +**/ +void MainWindow::on_tabWidget_currentChanged(int index) { - if(arg1.compare("General",Qt::CaseSensitive)==0){ //case sentive is faster + QString tabtext = ui->tabWidget->tabText(index); + + if(tabtext.compare("XML",Qt::CaseSensitive)==0){ //case sentive is faster updateItemsLoaded(ui->twSourcesXML); } - else if(arg1.compare("Textures",Qt::CaseSensitive)==0){ + else if(tabtext.compare("Textures",Qt::CaseSensitive)==0){ updateItemsLoaded(ui->twSourcesTextures); } - else if(arg1.compare("Objects",Qt::CaseSensitive)==0){ + else if(tabtext.compare("Characters",Qt::CaseSensitive)==0){ + updateItemsLoaded(ui->twSourcesCharacters); + } + else if(tabtext.compare("Objects",Qt::CaseSensitive)==0){ updateItemsLoaded(ui->twSourcesObjects); } - else if(arg1.compare("Levels",Qt::CaseSensitive)==0){ + else if(tabtext.compare("Levels",Qt::CaseSensitive)==0){ updateItemsLoaded(ui->twSourcesLevels); } else{ @@ -1528,23 +1570,6 @@ void MainWindow::setConverterButtonsSize ui->pbConvertMisc->setMinimumHeight(height); } -/** - Gets application directory. In mac os gets the .app directory - **/ -QString MainWindow::getOSIndependentAppPath(){ -#ifdef Q_WS_MAC - QDir dir = QDir::current(); - if(dir.absolutePath().contains(".app")){ // include bundle, but we don't want it - dir.cdUp(); - dir.cdUp(); - dir.cdUp(); - } - return dir.absolutePath(); -#else - return QDir::currentPath(); -#endif -} - void MainWindow::connectSlots(){ //This signal is for thread that is working setup the progress bar (make it visible and set it's min-max)