From d74588827ebfd5d6e899a8f1fc634c2bfbc8c0bb Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Fri, 28 Oct 2016 15:57:57 +0200 Subject: [PATCH 1/2] change the focus from 'cancel' to 'ok' --- src/musredit_qt5/PMsr2DataDialog.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/musredit_qt5/PMsr2DataDialog.cpp b/src/musredit_qt5/PMsr2DataDialog.cpp index b2c52a48..2a2b2f4e 100644 --- a/src/musredit_qt5/PMsr2DataDialog.cpp +++ b/src/musredit_qt5/PMsr2DataDialog.cpp @@ -105,6 +105,8 @@ PMsr2DataDialog::PMsr2DataDialog(PMsr2DataParam *msr2DataParam, const QString he fGlobal_checkBox->setChecked(fMsr2DataParam->global); fGlobalPlus_checkBox->setChecked(fMsr2DataParam->globalPlus); + fOk_pushButton->setDefault(true); + connect(fGlobal_checkBox, SIGNAL(clicked(bool)), this, SLOT(globalOptionSet(bool))); connect(fGlobalPlus_checkBox, SIGNAL(clicked(bool)), this, SLOT(globalPlusOptionSet(bool))); } From ea841ec186a357d9ec87b2ec8dea292331ba7788 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Tue, 8 Nov 2016 08:53:43 +0100 Subject: [PATCH 2/2] got rid of direct 'system()' calls wherever possible. --- src/musredit_qt5/PTextEdit.cpp | 100 ++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/src/musredit_qt5/PTextEdit.cpp b/src/musredit_qt5/PTextEdit.cpp index 9888fa02..6fe92bdc 100644 --- a/src/musredit_qt5/PTextEdit.cpp +++ b/src/musredit_qt5/PTextEdit.cpp @@ -2185,29 +2185,29 @@ void PTextEdit::musrView() fileSave(); } - QString cmd; + QString cmd = fAdmin->getExecPath() + "/musrview"; + QString workDir = QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(); + QStringList arg; QString str; - str = "cd \"" + QFileInfo(*fFilenames.find( currentEditor() )).absolutePath() + "\"; "; - - str += fAdmin->getExecPath() + "/musrview"; - cmd = str + " \""; - + // file name str = *fFilenames.find( currentEditor() ); int pos = str.lastIndexOf("/"); if (pos != -1) str.remove(0, pos+1); - QString numStr; - numStr.setNum(fAdmin->getTimeout()); - cmd += str + "\" --timeout " + numStr; + arg << str; + + // timeout + str.setNum(fAdmin->getTimeout()); + arg << "--timeout" << str; + + // start with Fourier? if (fAdmin->getMusrviewShowFourierFlag()) - cmd += " -f "; - cmd += " &"; + arg << "-f"; - int status=system(cmd.toLatin1()); - - if (status != 0) { - cerr << "**WARNING** musrView: something went wrong ..." << endl; + QProcess proc(this); + if (!proc.startDetached(cmd, arg, workDir)) { + QMessageBox::critical(this, "ERROR", "**ERROR** musrview process couldn't be launched properly, sorry."); } } @@ -2230,20 +2230,26 @@ void PTextEdit::musrT0() fileSave(); } - QString cmd; + QString cmd = fAdmin->getExecPath() + "/musrt0"; + QString workDir = QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(); + QStringList arg; QString str; - str = fAdmin->getExecPath() + "/musrt0"; - cmd = str + " \""; - + // file name str = *fFilenames.find( currentEditor() ); - QString numStr; - numStr.setNum(fAdmin->getTimeout()); - cmd += str + "\" --timeout " + numStr + " &"; + int pos = str.lastIndexOf("/"); + if (pos != -1) + str.remove(0, pos+1); + arg << str; - int status=system(cmd.toLatin1()); + // timeout + str.setNum(fAdmin->getTimeout()); + arg << "--timeout" << str; - QString fln = *fFilenames.find( currentEditor() ); + QProcess proc(this); + if (!proc.startDetached(cmd, arg, workDir)) { + QMessageBox::critical(this, "ERROR", "**ERROR** musrt0 process couldn't be launched properly, sorry."); + } } //---------------------------------------------------------------------------------------------------- @@ -2355,16 +2361,44 @@ void PTextEdit::musrSwapMsrMlog() fileSave(); } + QMessageBox::information(0, "INFO", QString("Will now swap files: %1 <-> %2").arg(currentFileName).arg(swapFileName)); + // swap files - QString cmd; - cmd = QString("cp \"") + currentFileName + QString("\" \"") + tempFileName + QString("\""); - int status=system(cmd.toLatin1()); - cmd = QString("cp \"") + swapFileName + QString("\" \"") + currentFileName + QString("\""); - status=system(cmd.toLatin1()); - cmd = QString("cp \"") + tempFileName + QString("\" \"") + swapFileName + QString("\""); - status=system(cmd.toLatin1()); - cmd = QString("rm \"") + tempFileName + QString("\""); - status=system(cmd.toLatin1()); + + // copy currentFile -> tempFile + if (QFile::exists(tempFileName)) { + if (!QFile::remove(tempFileName)) { + QMessageBox::critical(0, "ERROR", QString("failed to remove %1").arg(tempFileName)); + return; + } + } + if (!QFile::copy(currentFileName, tempFileName)) { + QMessageBox::critical(0, "ERROR", QString("failed to copy %1 -> %2").arg(currentFileName).arg(tempFileName)); + return; + } + // copy swapFile -> currentFile + if (!QFile::remove(currentFileName)) { + QMessageBox::critical(0, "ERROR", QString("failed to remove %1").arg(currentFileName)); + return; + } + if (!QFile::copy(swapFileName, currentFileName)) { + QMessageBox::critical(0, "ERROR", QString("failed to copy %1 -> %2").arg(swapFileName).arg(currentFileName)); + return; + } + // copy tempFile -> swapFile + if (!QFile::remove(swapFileName)) { + QMessageBox::critical(0, "ERROR", QString("failed to remove %1").arg(swapFileName)); + return; + } + if (!QFile::copy(tempFileName, swapFileName)) { + QMessageBox::critical(0, "ERROR", QString("failed to copy %1 -> %2").arg(tempFileName).arg(swapFileName)); + return; + } + // clean up + if (!QFile::remove(tempFileName)) { + QMessageBox::critical(0, "ERROR", QString("failed to remove %1").arg(tempFileName)); + return; + } int currentIdx = fTabWidget->currentIndex();