--- Vago/trunk/Vago/mainwindow.cpp 2016/09/16 22:51:26 1047 +++ Vago/trunk/Vago/mainwindow.cpp 2016/10/12 21:35:13 1054 @@ -16,12 +16,12 @@ MainWindow::MainWindow(QWidget *parent) setVagoWindowTitle(); - if(!QFile::exists(UtilVago::getOniSplitExeAbsolutePath())){ + if(!QFile::exists(UtilVago::getOniSplitExecutableAbsolutePath())){ UtilVago::showAndLogErrorPopUp(this->myLogger, "OniSplit not found. Please download it at "+GlobalVars::ModsDomain+" and put it the Vago's tools folder. \n\nProgram will now exit."); exit(1); } - if(!QFile::exists(UtilVago::getXmlToolsExeAbsolutePath())){ + if(!QFile::exists(UtilVago::getXmlToolsExecutableAbsolutePath())){ UtilVago::showAndLogErrorPopUp(this->myLogger, "XmlTools not found. Please download it at "+GlobalVars::ModsDomain+" and put it the Vago's tools folder. \n\nProgram will now exit."); exit(1); } @@ -71,8 +71,12 @@ MainWindow::MainWindow(QWidget *parent) this->vagoSettings->setValue("SeparateInWorkspace",true); iniChanged=true; } - if(!this->vagoSettings->contains("ConfirmExit")){ - this->vagoSettings->setValue("ConfirmExit", false); + if(!this->vagoSettings->contains("AskSaveProject")){ + this->vagoSettings->setValue("AskSaveProject", true); + iniChanged=true; + } + if(!this->vagoSettings->contains("AskToOpenLastProject")){ + this->vagoSettings->setValue("AskToOpenLastProject", false); iniChanged=true; } if(!this->vagoSettings->contains("LastProjectPath")){ @@ -179,7 +183,20 @@ MainWindow::~MainWindow() void MainWindow::showEvent(QShowEvent *e) { - #ifdef Q_OS_WIN + // If we don't have a converter yet, application wasn't started. + if(!this->applicationIsFullyLoaded) + { + // Apparently Qt doesn't contains a slot to when the application was fully load (mainwindow). So we do our own implementation instead. + connect(this, SIGNAL(signalAppIsLoaded()), this, SLOT(applicationWasLoaded()), Qt::ConnectionType::QueuedConnection); + emit signalAppIsLoaded(); + } + + e->accept(); +} + +// Called only when the MainWindow was fully loaded and painted on the screen. This slot is only called once. +void MainWindow::applicationWasLoaded(){ +#ifdef Q_OS_WIN // QProgressBar only works after the windows was shown // http://stackoverflow.com/questions/24840941/qwintaskbarprogress-wont-show (Kervala answer) @@ -191,15 +208,23 @@ void MainWindow::showEvent(QShowEvent *e //Create a thread for do the conversion in background this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, this->listToProccess, this->win7TaskBarProgress); - #else +#else this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, this->listToProccess); - #endif +#endif connectSlots(); this->myLogger->writeString("Application started."); - e->accept(); + this->applicationIsFullyLoaded = true; + + QString lastSavedProject = this->vagoSettings->value("RecentProject1").toString(); + + if(!lastSavedProject.isEmpty() && this->vagoSettings->value("AskToOpenLastProject").toBool()){ + if(Util::showQuestionPopUp(this,"Do you want to load latest project?\n\nLatest project was '" + Util::cutNameWithoutBackSlash(lastSavedProject) + "'.")){ + loadProjectState(lastSavedProject); + } + } } @@ -227,6 +252,12 @@ void MainWindow::on_actionSound_Wizard_t myWizard.exec(); } +void MainWindow::on_actionBackground_Image_Wizard_triggered() +{ + BGImageWizard myWizard (UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger); + myWizard.exec(); +} + void MainWindow::on_tbOni_clicked() { QStringList arguments; @@ -433,6 +464,7 @@ void MainWindow::addFilesSource(DropTabl addRowTable(myTable,lastFileName,fromTo,command); } updateItemsLoaded(myTable); + rowsWereChangedInDropTableWidget(); } QString MainWindow::fileParsingXML(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){ @@ -735,14 +767,13 @@ void MainWindow::TresultConversion(QStri if(numErrors!=0){ QString sNumErrors=QString::number(numErrors); if(numErrors>1){ - UtilVago::showErrorPopUpLogButton(result+"\n This is the last of "+sNumErrors+" Errors."); - showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" Errors)."); + UtilVago::showErrorPopUpLogButton(result+"\n This is the last of "+sNumErrors+" errors."); + showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" errors)."); } else{ UtilVago::showErrorPopUpLogButton(result); showErrStatusMessage("Something gone wrong. Check log file."); } - } else{ showSuccessStatusMessage("Everything went well!"); @@ -1107,6 +1138,7 @@ void MainWindow::removeTableContents(Dro myTable->removeRow(myTable->selectionModel()->selectedRows().at(size-i-1).row()); } updateItemsLoaded(myTable); + rowsWereChangedInDropTableWidget(); } } @@ -1130,8 +1162,10 @@ void MainWindow::clearTableContents(Drop if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?",defaultButton)){ clearTableNoPrompt(myTable); + updateItemsLoaded(myTable); + rowsWereChangedInDropTableWidget(); } - updateItemsLoaded(myTable); + } void MainWindow::clearTableNoPrompt(DropTableWidget *myTable){ @@ -1148,13 +1182,25 @@ void MainWindow::on_actionPreferences_tr void MainWindow::closeEvent(QCloseEvent *event){ - if(this->vagoSettings->value("ConfirmExit").toBool()){ - if(!Util::showQuestionPopUp(this,"Exit Vago?")){ + if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){ + QMessageBox::StandardButton result = askToSaveCurrentProject(); + if(result == QMessageBox::StandardButton::Cancel){ event->ignore(); } } } +QMessageBox::StandardButton MainWindow::askToSaveCurrentProject(){ + QMessageBox::StandardButton result = + Util::showQuestionPopUpWithCancel(this,"There are unsaved changes. Do you want to save the current project?", QMessageBox::StandardButton::Yes); + + if(result == QMessageBox::StandardButton::Yes){ + on_actionSave_triggered(); + } + + return result; +} + void MainWindow::on_cbToLevels_currentIndexChanged(const QString &arg1) { @@ -1215,7 +1261,7 @@ void MainWindow::on_actionCheck_OniSplit { QProcess myProcess; myProcess.setWorkingDirectory(UtilVago::getAppPath()); - myProcess.start(UtilVago::getOniSplitExeAbsolutePath()+" -version"); + myProcess.start(UtilVago::getOniSplitExecutable()+" -version"); myProcess.waitForFinished(); QString result=myProcess.readAllStandardOutput(); @@ -1227,7 +1273,7 @@ void MainWindow::on_actionCheck_xmlTools { QProcess myProcess; myProcess.setWorkingDirectory(UtilVago::getAppPath()); - myProcess.start(UtilVago::getXmlToolsExeAbsolutePath()+" --version"); + myProcess.start(UtilVago::getXmlToolsExecutable()+" --version"); myProcess.waitForFinished(); QString result=myProcess.readLine(); @@ -1249,6 +1295,14 @@ void MainWindow::updateItemsLoaded(DropT this->itemsLoaded->setText(QString().setNum(numItems)+ (numItems==1?" item ":" items ") +"loaded"); } +void MainWindow::rowsWereChangedInDropTableWidget(){ + // We have changed rows, we have now unsaved changes. + if(!this->unsavedChangesExist){ + this->unsavedChangesExist = true; + setVagoWindowTitle(); + } +} + void MainWindow::on_tbCommand_clicked() { //Show preferences @@ -1313,6 +1367,28 @@ void MainWindow::on_actionSave_Project_t } +// New Project +void MainWindow::on_actionNew_Project_triggered() +{ + if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){ + QMessageBox::StandardButton result = askToSaveCurrentProject(); + if(result == QMessageBox::StandardButton::Cancel){ + return; + } + } + + QList myTables = getAllTableWidgets(); + + for(DropTableWidget* const currTable : myTables){ + clearTableNoPrompt(currTable); + } + + this->lastProjectFilePath=""; // clear last project file path + this->unsavedChangesExist = false; + + setVagoWindowTitle(); // update vago title +} + void MainWindow::on_actionSave_triggered() { if(this->lastProjectFilePath.isEmpty()){ @@ -1477,10 +1553,12 @@ void MainWindow::dtContextMenu(DropTable else if(selectedOption==moveUp.get()){ qSort(selectedRows); //let's order the selections by the row number, so we know exactly how to swap it myTable->swapPositions(selectedRows,-1); + rowsWereChangedInDropTableWidget(); } else if(selectedOption==moveDown.get()){ qSort(selectedRows); myTable->swapPositions(selectedRows,+1); + rowsWereChangedInDropTableWidget(); } else if(selectedOption==changeOptions.get()){ changeToCurrentSettings(selectedRows,myTable); @@ -1539,6 +1617,7 @@ void MainWindow::dtContextMenu(DropTable result+=QString::number(disabledCount) + (disabledCount==1?" item ":" items ") + "Disabled"; } + rowsWereChangedInDropTableWidget(); showSuccessStatusMessage(result); } } @@ -1564,6 +1643,7 @@ void MainWindow::changeToCurrentSettings myTable->updateTableToolTips(row); } + rowsWereChangedInDropTableWidget(); showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed to the current settings"); } @@ -1587,6 +1667,7 @@ void MainWindow::changeItemsOutput(DropT myTable->updateTableToolTips(row); } + rowsWereChangedInDropTableWidget(); showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed the output to "+(newOutput!=this->workspaceLocation?Util::cutName(newOutput):"Vago workspace")); } @@ -1677,7 +1758,7 @@ void MainWindow::saveProjectState(const pugi::xml_document doc; pugi::xml_node rootNode = doc.append_child("VagoProject"); - rootNode.append_attribute("vagoVersion").set_value(GlobalVars::AppVersion.toUtf8().constData()); + rootNode.append_attribute("vagoVersion").set_value(GlobalVars::LastCompatibleVersion.toUtf8().constData()); foreach(DropTableWidget* const &myTable, tableWidgets){ saveProjectWidget(rootNode, myTable); @@ -1691,10 +1772,13 @@ void MainWindow::saveProjectState(const this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); this->lastProjectFilePath = filePath; + this->unsavedChangesExist = false; addNewRecentProject(filePath); setVagoWindowTitle(); + + showSuccessStatusMessage("Project saved sucessfully."); } void MainWindow::saveProjectWidget(pugi::xml_node &rootNode, DropTableWidget* table) @@ -1841,6 +1925,10 @@ void MainWindow::setVagoWindowTitle(){ vagoTitle += Util::cutNameWithoutBackSlash(this->lastProjectFilePath); } + if(this->unsavedChangesExist){ + vagoTitle += "*"; + } + setWindowTitle(vagoTitle); } @@ -1913,6 +2001,13 @@ QList MainWindow::getA void MainWindow::loadProjectState(const QString &filePath) { + if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){ + QMessageBox::StandardButton result = askToSaveCurrentProject(); + if(result == QMessageBox::StandardButton::Cancel){ + return; + } + } + QString statusError = "Couldn't load project."; pugi::xml_document doc; @@ -1968,6 +2063,7 @@ void MainWindow::loadProjectState(const this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); this->lastProjectFilePath = filePath; + this->unsavedChangesExist = false; addNewRecentProject(filePath);