ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/mainwindow.cpp
(Generate patch)

Comparing Vago/trunk/Vago/mainwindow.cpp (file contents):
Revision 1047 by s10k, Fri Sep 16 22:51:26 2016 UTC vs.
Revision 1058 by s10k, Sun Oct 30 14:42:39 2016 UTC

# Line 16 | Line 16 | MainWindow::MainWindow(QWidget *parent)
16  
17      setVagoWindowTitle();
18  
19 <    if(!QFile::exists(UtilVago::getOniSplitExeAbsolutePath())){
19 >    if(!QFile::exists(UtilVago::getOniSplitExecutableAbsolutePath())){
20          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.");
21          exit(1);
22      }
23  
24 <    if(!QFile::exists(UtilVago::getXmlToolsExeAbsolutePath())){
24 >    if(!QFile::exists(UtilVago::getXmlToolsExecutableAbsolutePath())){
25          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.");
26          exit(1);
27      }
# Line 71 | Line 71 | MainWindow::MainWindow(QWidget *parent)
71          this->vagoSettings->setValue("SeparateInWorkspace",true);
72          iniChanged=true;
73      }
74 <    if(!this->vagoSettings->contains("ConfirmExit")){
75 <        this->vagoSettings->setValue("ConfirmExit", false);
74 >    if(!this->vagoSettings->contains("AskSaveProject")){
75 >        this->vagoSettings->setValue("AskSaveProject", true);
76 >        iniChanged=true;
77 >    }
78 >    if(!this->vagoSettings->contains("AskToOpenLastProject")){
79 >        this->vagoSettings->setValue("AskToOpenLastProject", false);
80          iniChanged=true;
81      }
82      if(!this->vagoSettings->contains("LastProjectPath")){
# Line 124 | Line 128 | MainWindow::MainWindow(QWidget *parent)
128      ui->statusBar->addPermanentWidget(this->myBar); //this adds automatically in right
129      ui->statusBar->addPermanentWidget(ui->tbAbortConversion);
130  
127    //Initialize list pointers
128    this->listToProccess = new QStringList;
129
131      // User interface
132      ui->mainToolBar->addWidget(ui->tbAE); //add ae installer launch button
133      ui->mainToolBar->addWidget(ui->emptySpacerLabel); //trick, we can't add directly a space so we add an empty
# Line 134 | Line 135 | MainWindow::MainWindow(QWidget *parent)
135      ui->mainToolBar->addWidget(ui->emptySpacerLabel2); //same as before
136      ui->mainToolBar->addWidget(ui->tbCommand); //add option to manual onisplit commands
137      ui->mainToolBar->addWidget(ui->emptySpacerLabel3); //same as before
138 +    ui->mainToolBar->addWidget(ui->tbXmlToolsInterface); //add option to manual onisplit commands
139 +    ui->mainToolBar->addWidget(ui->emptySpacerLabel4); //same as before
140      ui->mainToolBar->addWidget(ui->tbOpenFolder); //add option to open folder with files converted etc
141  
142      ui->mainToolBar->setLayoutDirection(Qt::RightToLeft);
# Line 179 | Line 182 | MainWindow::~MainWindow()
182  
183   void MainWindow::showEvent(QShowEvent *e)
184   {
185 <    #ifdef Q_OS_WIN
185 >    // If we don't have a converter yet, application wasn't started.
186 >    if(!this->applicationIsFullyLoaded)
187 >    {
188 >        // Apparently Qt doesn't contains a slot to when the application was fully load (mainwindow). So we do our own implementation instead.
189 >        connect(this, SIGNAL(signalAppIsLoaded()), this, SLOT(applicationWasLoaded()), Qt::ConnectionType::QueuedConnection);
190 >        emit signalAppIsLoaded();
191 >    }
192 >
193 >    e->accept();
194 > }
195 >
196 > // Called only when the MainWindow was fully loaded and painted on the screen. This slot is only called once.
197 > void MainWindow::applicationWasLoaded(){
198 > #ifdef Q_OS_WIN
199      // QProgressBar only works after the windows was shown
200      // http://stackoverflow.com/questions/24840941/qwintaskbarprogress-wont-show (Kervala answer)
201  
# Line 190 | Line 206 | void MainWindow::showEvent(QShowEvent *e
206      this->win7TaskBarProgress = this->win7TaskBarButton->progress();
207  
208      //Create a thread for do the conversion in background
209 <    this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, this->listToProccess, this->win7TaskBarProgress);
210 <    #else
211 <    this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, this->listToProccess);
212 <    #endif
209 >    this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, &this->listToProccess, this->win7TaskBarProgress);
210 > #else
211 >    this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, &this->listToProccess);
212 > #endif
213  
214      connectSlots();
215  
216      this->myLogger->writeString("Application started.");
217  
218 <    e->accept();
218 >    this->applicationIsFullyLoaded = true;
219 >
220 >    QString lastSavedProject = this->vagoSettings->value("RecentProject1").toString();
221 >
222 >    if(!lastSavedProject.isEmpty() && this->vagoSettings->value("AskToOpenLastProject").toBool()){
223 >        if(Util::showQuestionPopUp(this,"Do you want to load latest project?\n\nLatest project was '" + Util::cutNameWithoutBackSlash(lastSavedProject) + "'.")){
224 >            loadProjectState(lastSavedProject);
225 >        }
226 >    }
227   }
228  
229  
# Line 227 | Line 251 | void MainWindow::on_actionSound_Wizard_t
251      myWizard.exec();
252   }
253  
254 + void MainWindow::on_actionBackground_Image_Wizard_triggered()
255 + {
256 +    BGImageWizard myWizard (UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger);
257 +    myWizard.exec();
258 + }
259 +
260   void MainWindow::on_tbOni_clicked()
261   {
262      QStringList arguments;
# Line 261 | Line 291 | void MainWindow::on_tbOpenFolder_clicked
291      QDesktopServices::openUrl(QUrl("file:///"+this->outputFolder));
292   }
293  
294 +
295 + void MainWindow::on_tbXmlToolsInterface_clicked()
296 + {
297 +    //We pass no parent because we want to have an independent window for XmlToolsInterface,
298 +    //so we can minimize it or maximize indepently from the MainWindow
299 +    XmlToolsInterface *xmlToolsWindow = new XmlToolsInterface(this->myLogger);
300 +    xmlToolsWindow->show(); //it destroys itself when finished.
301 + }
302 +
303   void MainWindow::on_tbAbortConversion_clicked()
304   {
305      if(Util::showQuestionPopUp(this,"Are you sure you want to abort the current conversion?")){
# Line 433 | Line 472 | void MainWindow::addFilesSource(DropTabl
472          addRowTable(myTable,lastFileName,fromTo,command);
473      }
474      updateItemsLoaded(myTable);
475 +    rowsWereChangedInDropTableWidget();
476   }
477  
478   QString MainWindow::fileParsingXML(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){
# Line 709 | Line 749 | void MainWindow::startConversion(){
749      for(int i=0; i<currTable->rowCount(); i++){
750          //Only process enabled items
751          if(currTable->item(i,2)->background()!=currTable->disabledBackStyle){
752 <            this->listToProccess->append(currTable->item(i,2)->text());
752 >            this->listToProccess.append(currTable->item(i,2)->text());
753          }
754      }
755  
# Line 735 | Line 775 | void MainWindow::TresultConversion(QStri
775      if(numErrors!=0){
776          QString sNumErrors=QString::number(numErrors);
777          if(numErrors>1){
778 <            UtilVago::showErrorPopUpLogButton(result+"\n This is the last of "+sNumErrors+" Errors.");
779 <            showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" Errors).");
778 >            UtilVago::showErrorPopUpLogButton(result+"\n This is the last of "+sNumErrors+" errors.");
779 >            showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" errors).");
780          }
781          else{
782              UtilVago::showErrorPopUpLogButton(result);
783              showErrStatusMessage("Something gone wrong. Check log file.");
784          }
745
785      }
786      else{
787          showSuccessStatusMessage("Everything went well!");
# Line 1107 | Line 1146 | void MainWindow::removeTableContents(Dro
1146              myTable->removeRow(myTable->selectionModel()->selectedRows().at(size-i-1).row());
1147          }
1148          updateItemsLoaded(myTable);
1149 +        rowsWereChangedInDropTableWidget();
1150      }
1151   }
1152  
# Line 1130 | Line 1170 | void MainWindow::clearTableContents(Drop
1170  
1171      if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?",defaultButton)){
1172          clearTableNoPrompt(myTable);
1173 +        updateItemsLoaded(myTable);
1174 +        rowsWereChangedInDropTableWidget();
1175      }
1176 <    updateItemsLoaded(myTable);
1176 >
1177   }
1178  
1179   void MainWindow::clearTableNoPrompt(DropTableWidget *myTable){
# Line 1148 | Line 1190 | void MainWindow::on_actionPreferences_tr
1190  
1191  
1192   void MainWindow::closeEvent(QCloseEvent *event){
1193 <    if(this->vagoSettings->value("ConfirmExit").toBool()){
1194 <        if(!Util::showQuestionPopUp(this,"Exit Vago?")){
1193 >    if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){
1194 >        QMessageBox::StandardButton result = askToSaveCurrentProject();
1195 >        if(result == QMessageBox::StandardButton::Cancel){
1196              event->ignore();
1197 +            return;
1198          }
1199      }
1200 +
1201 +    // Exit application (this will also close all other windows which don't have parent, for instance ManualCommands)
1202 +    QApplication::quit();
1203 + }
1204 +
1205 + QMessageBox::StandardButton MainWindow::askToSaveCurrentProject(){
1206 +    QMessageBox::StandardButton result =
1207 +            Util::showQuestionPopUpWithCancel(this,"There are unsaved changes. Do you want to save the current project?", QMessageBox::StandardButton::Yes);
1208 +
1209 +    if(result == QMessageBox::StandardButton::Yes){
1210 +        on_actionSave_triggered();
1211 +    }
1212 +
1213 +    return result;
1214   }
1215  
1216   void MainWindow::on_cbToLevels_currentIndexChanged(const QString &arg1)
# Line 1178 | Line 1236 | void MainWindow::on_cbBnvLevels_toggled(
1236      ui->leBnvLevels->setEnabled(checked);
1237      ui->cbGridsLevels->setEnabled(checked);
1238      ui->cbGridsLevels->setChecked(checked);
1239 <    if(checked){
1239 >    if(checked && !projectIsLoading){
1240          QString file=QFileDialog::getOpenFileName(this,"Choose the BNV.dae file...","./" , "All Files (*.*)");
1241          if(!file.isEmpty()){
1242              ui->leBnvLevels->setText(file);
# Line 1190 | Line 1248 | void MainWindow::on_cbAdditionalSourcesL
1248   {
1249      ui->leAdditSourcesLevels->setEnabled(checked);
1250  
1251 <    if(checked){
1251 >    if(checked && !projectIsLoading){
1252          QStringList filesSelected=QFileDialog::getOpenFileNames(this,"Choose the additional .dae files...","./" , "All Files (*.*)");
1253          QString filesJoined;
1254          int size=filesSelected.size();
# Line 1215 | Line 1273 | void MainWindow::on_actionCheck_OniSplit
1273   {
1274      QProcess myProcess;
1275      myProcess.setWorkingDirectory(UtilVago::getAppPath());
1276 <    myProcess.start(UtilVago::getOniSplitExeAbsolutePath()+" -version");
1276 >    myProcess.start(UtilVago::getOniSplitExecutable()+" -version");
1277      myProcess.waitForFinished();
1278  
1279      QString result=myProcess.readAllStandardOutput();
# Line 1227 | Line 1285 | void MainWindow::on_actionCheck_xmlTools
1285   {
1286      QProcess myProcess;
1287      myProcess.setWorkingDirectory(UtilVago::getAppPath());
1288 <    myProcess.start(UtilVago::getXmlToolsExeAbsolutePath()+" --version");
1288 >    myProcess.start(UtilVago::getXmlToolsExecutable()+" --version");
1289      myProcess.waitForFinished();
1290      QString result=myProcess.readLine();
1291  
# Line 1249 | Line 1307 | void MainWindow::updateItemsLoaded(DropT
1307      this->itemsLoaded->setText(QString().setNum(numItems)+ (numItems==1?" item ":" items ") +"loaded");
1308   }
1309  
1310 + void MainWindow::rowsWereChangedInDropTableWidget(){
1311 +    // We have changed rows, we have now unsaved changes.
1312 +    if(!this->unsavedChangesExist){
1313 +        this->unsavedChangesExist = true;
1314 +        setVagoWindowTitle();
1315 +    }
1316 + }
1317 +
1318   void MainWindow::on_tbCommand_clicked()
1319   {
1320 <    //Show preferences
1321 <    ManualCommands *commandsWindow = new ManualCommands(this);
1320 >    //We pass no parent because we want to have an independent window for ManualCommands,
1321 >    //so we can minimize it or maximize indepently from the MainWindow
1322 >    ManualCommands *commandsWindow = new ManualCommands();
1323      commandsWindow->show(); //it destroys itself when finished.
1324   }
1325  
# Line 1313 | Line 1380 | void MainWindow::on_actionSave_Project_t
1380  
1381   }
1382  
1383 + // New Project
1384 + void MainWindow::on_actionNew_Project_triggered()
1385 + {
1386 +    if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){
1387 +        QMessageBox::StandardButton result = askToSaveCurrentProject();
1388 +        if(result == QMessageBox::StandardButton::Cancel){
1389 +            return;
1390 +        }
1391 +    }
1392 +
1393 +    QList<DropTableWidget*> myTables = getAllTableWidgets();
1394 +
1395 +    for(DropTableWidget* const currTable : myTables){
1396 +        clearTableNoPrompt(currTable);
1397 +    }
1398 +
1399 +    this->lastProjectFilePath=""; // clear last project file path
1400 +    this->unsavedChangesExist = false;
1401 +
1402 +    setVagoWindowTitle(); // update vago title
1403 + }
1404 +
1405   void MainWindow::on_actionSave_triggered()
1406   {
1407      if(this->lastProjectFilePath.isEmpty()){
# Line 1477 | Line 1566 | void MainWindow::dtContextMenu(DropTable
1566      else if(selectedOption==moveUp.get()){
1567          qSort(selectedRows); //let's order the selections by the row number, so we know exactly how to swap it
1568          myTable->swapPositions(selectedRows,-1);
1569 +        rowsWereChangedInDropTableWidget();
1570      }
1571      else if(selectedOption==moveDown.get()){
1572          qSort(selectedRows);
1573          myTable->swapPositions(selectedRows,+1);
1574 +        rowsWereChangedInDropTableWidget();
1575      }
1576      else if(selectedOption==changeOptions.get()){
1577          changeToCurrentSettings(selectedRows,myTable);
# Line 1539 | Line 1630 | void MainWindow::dtContextMenu(DropTable
1630              result+=QString::number(disabledCount) + (disabledCount==1?" item ":" items ") + "Disabled";
1631          }
1632  
1633 +        rowsWereChangedInDropTableWidget();
1634          showSuccessStatusMessage(result);
1635      }
1636   }
# Line 1564 | Line 1656 | void MainWindow::changeToCurrentSettings
1656          myTable->updateTableToolTips(row);
1657      }
1658  
1659 +    rowsWereChangedInDropTableWidget();
1660      showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed to the current settings");
1661   }
1662  
# Line 1587 | Line 1680 | void MainWindow::changeItemsOutput(DropT
1680          myTable->updateTableToolTips(row);
1681      }
1682  
1683 +    rowsWereChangedInDropTableWidget();
1684      showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed the output to "+(newOutput!=this->workspaceLocation?Util::cutName(newOutput):"Vago workspace"));
1685   }
1686  
# Line 1677 | Line 1771 | void MainWindow::saveProjectState(const
1771      pugi::xml_document doc;
1772  
1773      pugi::xml_node rootNode = doc.append_child("VagoProject");
1774 <    rootNode.append_attribute("vagoVersion").set_value(GlobalVars::AppVersion.toUtf8().constData());
1774 >    rootNode.append_attribute("vagoVersion").set_value(GlobalVars::LastCompatibleVersion.toUtf8().constData());
1775  
1776      foreach(DropTableWidget* const &myTable, tableWidgets){
1777          saveProjectWidget(rootNode, myTable);
# Line 1691 | Line 1785 | void MainWindow::saveProjectState(const
1785      this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path());
1786  
1787      this->lastProjectFilePath = filePath;
1788 +    this->unsavedChangesExist = false;
1789  
1790      addNewRecentProject(filePath);
1791  
1792      setVagoWindowTitle();
1793 +
1794 +    showSuccessStatusMessage("Project saved sucessfully.");
1795   }
1796  
1797   void MainWindow::saveProjectWidget(pugi::xml_node &rootNode, DropTableWidget* table)
# Line 1841 | Line 1938 | void MainWindow::setVagoWindowTitle(){
1938          vagoTitle += Util::cutNameWithoutBackSlash(this->lastProjectFilePath);
1939      }
1940  
1941 +    if(this->unsavedChangesExist){
1942 +        vagoTitle += "*";
1943 +    }
1944 +
1945      setWindowTitle(vagoTitle);
1946   }
1947  
# Line 1913 | Line 2014 | QList<DropTableWidget*> MainWindow::getA
2014   void MainWindow::loadProjectState(const QString &filePath)
2015   {
2016  
2017 +    this->projectIsLoading = true;
2018 +
2019 +    if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){
2020 +        QMessageBox::StandardButton result = askToSaveCurrentProject();
2021 +        if(result == QMessageBox::StandardButton::Cancel){
2022 +            this->projectIsLoading = false;
2023 +            return;
2024 +        }
2025 +    }
2026 +
2027      QString statusError = "Couldn't load project.";
2028  
2029      pugi::xml_document doc;
# Line 1922 | Line 2033 | void MainWindow::loadProjectState(const
2033      if(result.status!=pugi::status_ok){
2034          UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error ocurred while loading project file.\n" + QString(result.description()));
2035          showErrStatusMessage(statusError);
2036 +        this->projectIsLoading = false;
2037          return;
2038      }
2039  
# Line 1929 | Line 2041 | void MainWindow::loadProjectState(const
2041      if(QString(doc.root().first_child().name()) != "VagoProject"){
2042          UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, QString(doc.root().name()) + "The file opened is not a valid VagoProject file. Load aborted.");
2043          showErrStatusMessage(statusError);
2044 +        this->projectIsLoading = false;
2045          return;
2046      }
2047  
# Line 1941 | Line 2054 | void MainWindow::loadProjectState(const
2054      {
2055          UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't find the vagoVersion of the current project. Load aborted.\n" + QString(e.what()));
2056          showErrStatusMessage(statusError);
2057 +        this->projectIsLoading = false;
2058          return;
2059      }
2060  
2061      if(!projVagoVersion.startsWith(GlobalVars::LastCompatibleVersion)){
2062          UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "The project that you are trying to load seems it is not compatible with your Vago Version. Please update Vago and try again.");
2063          showErrStatusMessage(statusError);
2064 +        this->projectIsLoading = false;
2065          return;
2066      }
2067  
# Line 1962 | Line 2077 | void MainWindow::loadProjectState(const
2077      catch(const std::exception& e){
2078          UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't load the vago project. Error: " + QString(e.what()));
2079          showErrStatusMessage(statusError);
2080 +        this->projectIsLoading = false;
2081          return;
2082      }
2083  
2084      this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path());
2085  
2086      this->lastProjectFilePath = filePath;
2087 +    this->unsavedChangesExist = false;
2088  
2089      addNewRecentProject(filePath);
2090  
2091      setVagoWindowTitle();
2092  
2093 +    this->projectIsLoading = false;
2094 +
2095      showSuccessStatusMessage("Project loaded sucessfully.");
2096   }
2097  
# Line 2035 | Line 2154 | void MainWindow::loadProjectWidget(pugi:
2154          ui->leBnvLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@bnvSourceValue")).attribute().value()));
2155          ui->cbGridsLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@generateGrids")).attribute().as_bool());
2156          ui->cbAdditionalSourcesLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@additionalSources")).attribute().as_bool());
2157 <        ui->leAdditSourcesLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@bnvSource")).attribute().value()));
2157 >        ui->leAdditSourcesLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@additionalSourcesValue")).attribute().value()));
2158      }
2159      else{
2160          ui->cbFromMisc->setCurrentText(from);

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)