Automatisierte Screenshot Aufnahme per [SCREENSHOT] datei implementiert
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QPainter>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
#include <QStandardPaths>
|
||||
@@ -164,6 +165,55 @@ void VideoWidget::onScreenshot()
|
||||
m_frame.save(path);
|
||||
}
|
||||
|
||||
void VideoWidget::saveAutoScreenshot(const QString &filename)
|
||||
{
|
||||
if (m_frame.isNull()) {
|
||||
emit autoScreenshotResult(false,
|
||||
tr("[SCREENSHOT] tag received, but no video frame is available yet."));
|
||||
return;
|
||||
}
|
||||
if (m_autoScreenshotDir.isEmpty()) {
|
||||
emit autoScreenshotResult(false,
|
||||
tr("[SCREENSHOT] tag received, but no auto-screenshot folder is "
|
||||
"configured (toolbar → \"Screenshot folder…\")."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Only take the bare filename from what the firmware sent - this
|
||||
// strips any directory components (incl. attempts at '../' path
|
||||
// traversal), so the firmware can never dictate where on disk we
|
||||
// write. Fall back to a timestamp if it sent nothing usable, and
|
||||
// default to .png if it didn't specify an extension.
|
||||
QString name = QFileInfo(filename.trimmed()).fileName();
|
||||
if (name.isEmpty()) {
|
||||
name = QStringLiteral("screenshot_%1.png")
|
||||
.arg(QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss_zzz"));
|
||||
} else if (QFileInfo(name).suffix().isEmpty()) {
|
||||
name += QStringLiteral(".png");
|
||||
}
|
||||
|
||||
const QDir dir(m_autoScreenshotDir);
|
||||
QString path = dir.filePath(name);
|
||||
|
||||
// Don't silently overwrite an earlier capture if the firmware reuses
|
||||
// the same filename on every trigger (e.g. a generic "dump.png") -
|
||||
// append a numeric suffix instead so nothing gets lost.
|
||||
if (QFileInfo::exists(path)) {
|
||||
const QString base = QFileInfo(name).completeBaseName();
|
||||
const QString suffix = QFileInfo(name).suffix();
|
||||
int n = 1;
|
||||
do {
|
||||
path = dir.filePath(QStringLiteral("%1_%2.%3").arg(base).arg(n).arg(suffix));
|
||||
++n;
|
||||
} while (QFileInfo::exists(path));
|
||||
}
|
||||
|
||||
if (m_frame.save(path))
|
||||
emit autoScreenshotResult(true, tr("Screenshot saved: %1").arg(path));
|
||||
else
|
||||
emit autoScreenshotResult(false, tr("Failed to save screenshot to %1").arg(path));
|
||||
}
|
||||
|
||||
void VideoWidget::onNewFrame(const QImage &frame)
|
||||
{
|
||||
// Feed the recorder regardless of freeze state, so pausing the preview
|
||||
|
||||
Reference in New Issue
Block a user