From 452f4b2815e685789ef921152b01d02168c2117d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 26 Oct 2018 15:49:34 +0200 Subject: Show export error in export dialog. Make sure export path is altered if the path is changed in the exportdialog lineedit. --- src/audioextractor.cc | 12 ++++++++---- src/audioextractor.h | 2 +- src/projectrenderer.cc | 14 ++++++++++++-- src/renderdialog.cc | 34 +++++++++++++++++++++++++++++++--- src/renderdialog.h | 1 + 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/audioextractor.cc b/src/audioextractor.cc index 21a4108..95fe6b2 100644 --- a/src/audioextractor.cc +++ b/src/audioextractor.cc @@ -50,7 +50,7 @@ AudioExtractor::AudioExtractor(Instrument& instrument, QObject *parent) { } -void AudioExtractor::exportSelections() +bool AudioExtractor::exportSelections() { auto selections = instrument.getSelections(); auto exportpath = instrument.getProject().getExportPath(); @@ -77,7 +77,7 @@ void AudioExtractor::exportSelections() if(!audiodata[idx].fh) { printf("AudioExtractor load error '%s'\n", file.toStdString().c_str()); - return; + return false; } if(samplerate == -1) @@ -183,7 +183,7 @@ void AudioExtractor::exportSelections() if(!ofh) { printf("Open for write error. %s\n", file.toStdString().c_str()); - return; + return false; } for(size_t ob = 0; ob < size; ob++) @@ -274,10 +274,14 @@ void AudioExtractor::exportSelections() } QFile xmlfile(exportpath + QDir::separator() + prefix + QDir::separator() + prefix + ".xml"); - xmlfile.open(QIODevice::WriteOnly); + if(!xmlfile.open(QIODevice::WriteOnly)) + { + return false; + } xmlfile.write(doc.toByteArray()); xmlfile.close(); emit progressUpdate(progress++); qApp->processEvents(); + return true; } diff --git a/src/audioextractor.h b/src/audioextractor.h index 35eb5ba..134c582 100644 --- a/src/audioextractor.h +++ b/src/audioextractor.h @@ -45,7 +45,7 @@ public: AudioExtractor(Instrument& instrument, QObject* parent); public slots: - void exportSelections(); + bool exportSelections(); signals: void progressUpdate(int value); diff --git a/src/projectrenderer.cc b/src/projectrenderer.cc index 729f929..62d646e 100644 --- a/src/projectrenderer.cc +++ b/src/projectrenderer.cc @@ -94,7 +94,12 @@ void ProjectRenderer::render() connect(&extractor, SIGNAL(progressUpdate(int)), this, SIGNAL(progressRenderTask(int))); - extractor.exportSelections(); + if(!extractor.exportSelections()) + { + emit progressFinished(1); + qApp->processEvents(); + return; + } QDomElement instrument_node = doc.createElement("instrument"); instrument_node.setAttribute("name", instrument.getInstrumentName()); @@ -126,7 +131,12 @@ void ProjectRenderer::render() } QFile xmlfile(project.getExportPath() + QDir::separator() + "drumkit.xml"); - xmlfile.open(QIODevice::WriteOnly); + if(!xmlfile.open(QIODevice::WriteOnly)) + { + emit progressFinished(1); + qApp->processEvents(); + return; + } xmlfile.write(doc.toByteArray()); xmlfile.close(); diff --git a/src/renderdialog.cc b/src/renderdialog.cc index 758f99e..5f61eae 100644 --- a/src/renderdialog.cc +++ b/src/renderdialog.cc @@ -194,7 +194,7 @@ public: return QVariant(); } - if(role == Qt::DecorationRole ) + if(role == Qt::DecorationRole) { if(index.column() == 0) { @@ -204,8 +204,14 @@ public: } else if(index.row() == current_row) { - //return QPixmap(":/icons/task_error.png"); - return QPixmap(":/icons/task_running.png"); + if(error) + { + return QPixmap(":/icons/task_error.png"); + } + else + { + return QPixmap(":/icons/task_running.png"); + } } else { @@ -228,6 +234,10 @@ public: return QVariant(); } + void setError() + { + error = true; + } QVariant headerData(int section, Qt::Orientation orientation, int role) const override { @@ -259,6 +269,7 @@ public: private: Project& project; int current_row{-1}; + bool error{false}; }; RenderDialog::RenderDialog(QWidget* parent, Project& project) @@ -278,6 +289,8 @@ RenderDialog::RenderDialog(QWidget* parent, Project& project) auto hl = new QHBoxLayout(); export_path = new QLineEdit(this); export_path->setText(project.getExportPath()); + connect(export_path, SIGNAL(textEdited(const QString&)), + this, SLOT(exportPathChanged(const QString&))); auto btn = new QPushButton(tr("...")); btn->setMaximumWidth(32); connect(btn, SIGNAL(clicked()), this, SLOT(chooseExportPath())); @@ -367,11 +380,21 @@ void RenderDialog::progressRenderFinished(int success) model->setActiveTask(*instrument_id); // note this id is invalid bar->setValue(task + 1); + if(success != 0) + { + model->setError(); + } model->refresh(); } void RenderDialog::progressFinished(int success) { + if(success != 0) + { + model->setError(); + } + model->refresh(); + export_btn->setEnabled(true); } @@ -388,3 +411,8 @@ void RenderDialog::chooseExportPath() project.setExportPath(path); } } + +void RenderDialog::exportPathChanged(const QString& path) +{ + project.setExportPath(path); +} diff --git a/src/renderdialog.h b/src/renderdialog.h index 3952c64..70405e4 100644 --- a/src/renderdialog.h +++ b/src/renderdialog.h @@ -56,6 +56,7 @@ private slots: void progressFinished(int success); void chooseExportPath(); + void exportPathChanged(const QString&); private: Project& project; -- cgit v1.2.3