Error handling now there
This commit is contained in:
parent
e71ecfec34
commit
f04aa81b9f
@ -8,6 +8,7 @@
|
|||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <formats.hpp>
|
#include <formats.hpp>
|
||||||
|
#include <notifications.hpp>
|
||||||
#include <platformbackend.hpp>
|
#include <platformbackend.hpp>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -15,7 +16,6 @@
|
|||||||
|
|
||||||
RecordingFormats::RecordingFormats(formats::Recording f) {
|
RecordingFormats::RecordingFormats(formats::Recording f) {
|
||||||
QString tmp = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
QString tmp = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
||||||
|
|
||||||
if (tmp.isEmpty()) {
|
if (tmp.isEmpty()) {
|
||||||
validator = [](QSize) { return false; };
|
validator = [](QSize) { return false; };
|
||||||
return;
|
return;
|
||||||
@ -29,6 +29,10 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
|
|||||||
path = tmpDir.absoluteFilePath("res." + formats::recordingFormatName(f).toLower());
|
path = tmpDir.absoluteFilePath("res." + formats::recordingFormatName(f).toLower());
|
||||||
finalizer = [&] {
|
finalizer = [&] {
|
||||||
delete enc;
|
delete enc;
|
||||||
|
if (interrupt) {
|
||||||
|
tmpDir.removeRecursively();
|
||||||
|
return;
|
||||||
|
}
|
||||||
QFile res(path);
|
QFile res(path);
|
||||||
if (!res.open(QFile::ReadOnly)) {
|
if (!res.open(QFile::ReadOnly)) {
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
@ -40,15 +44,31 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
|
|||||||
};
|
};
|
||||||
validator = [&](QSize s) {
|
validator = [&](QSize s) {
|
||||||
if (!enc) {
|
if (!enc) {
|
||||||
enc = new Encoder(path, s);
|
try {
|
||||||
if (!enc->isRunning()) {
|
enc = new Encoder(path, s);
|
||||||
|
if (!enc->isRunning()) {
|
||||||
|
delete enc;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (std::runtime_error e) {
|
||||||
|
notifications::notify("KShare Video Encoder Error", e.what(), QSystemTrayIcon::Critical);
|
||||||
|
qCritical() << "Encoder error: " << e.what();
|
||||||
|
interrupt = true;
|
||||||
delete enc;
|
delete enc;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
consumer = [&](QImage img) { enc->addFrame(img); };
|
consumer = [&](QImage img) {
|
||||||
|
if (interrupt) try {
|
||||||
|
enc->addFrame(img);
|
||||||
|
} catch (std::runtime_error e) {
|
||||||
|
notifications::notify("KShare Video Encoder Error", e.what(), QSystemTrayIcon::Critical);
|
||||||
|
qCritical() << "Encoder error: " << e.what();
|
||||||
|
interrupt = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
anotherFormat = formats::recordingFormatName(f);
|
anotherFormat = formats::recordingFormatName(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ private:
|
|||||||
QDir tmpDir;
|
QDir tmpDir;
|
||||||
QString path;
|
QString path;
|
||||||
Encoder *enc = NULL;
|
Encoder *enc = NULL;
|
||||||
|
bool interrupt = false;
|
||||||
QString anotherFormat;
|
QString anotherFormat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user