diff options
author | Artem Dyomin <artem.dyomin@qt.io> | 2023-10-26 14:01:47 +0200 |
---|---|---|
committer | Artem Dyomin <artem.dyomin@qt.io> | 2023-10-30 15:07:46 +0100 |
commit | a69450f5e12d3cd0ff3367980c2fa9f4ab205457 (patch) | |
tree | e255e6b4f2ad77333140dd4f1d04dbab9aed592a /src/multimedia/platform | |
parent | eb6656beae99e53fabeea40fe77d91c5b06c36d5 (diff) |
Unify logic of enum error+string holding and changing notification
We use the pair error + errorsString in several places,
let's handle the update in notification in one place and
have unit tests for the logic.
Thus, the change fixes errors notification for camera.
Pick-to: 6.6 6.5
Change-Id: Ie94ec728b051047bdd63ae3860e8942c3c245b1e
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia/platform')
4 files changed, 10 insertions, 26 deletions
diff --git a/src/multimedia/platform/qplatformmediarecorder.cpp b/src/multimedia/platform/qplatformmediarecorder.cpp index c2e4df053..6aa76e066 100644 --- a/src/multimedia/platform/qplatformmediarecorder.cpp +++ b/src/multimedia/platform/qplatformmediarecorder.cpp @@ -47,13 +47,7 @@ void QPlatformMediaRecorder::actualLocationChanged(const QUrl &location) void QPlatformMediaRecorder::error(QMediaRecorder::Error error, const QString &errorString) { - if (error == m_error && errorString == m_errorString) - return; - m_error = error; - m_errorString = errorString; - if (error != QMediaRecorder::NoError) - emit q->errorOccurred(error, errorString); - emit q->errorChanged(); + m_error.setAndNotify(error, errorString, *q); } void QPlatformMediaRecorder::metaDataChanged() diff --git a/src/multimedia/platform/qplatformmediarecorder_p.h b/src/multimedia/platform/qplatformmediarecorder_p.h index 1ff26f5bf..31df21710 100644 --- a/src/multimedia/platform/qplatformmediarecorder_p.h +++ b/src/multimedia/platform/qplatformmediarecorder_p.h @@ -22,6 +22,7 @@ #include <QtMultimedia/qmediarecorder.h> #include <QtMultimedia/qmediametadata.h> #include <QtMultimedia/qmediaformat.h> +#include <QtMultimedia/private/qerrorinfo_p.h> #include <QtCore/private/qglobal_p.h> QT_BEGIN_NAMESPACE @@ -115,8 +116,8 @@ public: virtual void setMetaData(const QMediaMetaData &) {} virtual QMediaMetaData metaData() const { return {}; } - QMediaRecorder::Error error() const { return m_error;} - QString errorString() const { return m_errorString; } + QMediaRecorder::Error error() const { return m_error.code(); } + QString errorString() const { return m_error.description(); } QUrl outputLocation() const { return m_outputLocation; } virtual void setOutputLocation(const QUrl &location) { m_outputLocation = location; } @@ -137,8 +138,7 @@ protected: private: QMediaRecorder *q = nullptr; - QMediaRecorder::Error m_error = QMediaRecorder::NoError; - QString m_errorString; + QErrorInfo<QMediaRecorder::Error> m_error; QUrl m_actualLocation; QUrl m_outputLocation; qint64 m_duration = 0; diff --git a/src/multimedia/platform/qplatformsurfacecapture.cpp b/src/multimedia/platform/qplatformsurfacecapture.cpp index 89adf3715..a56f48b62 100644 --- a/src/multimedia/platform/qplatformsurfacecapture.cpp +++ b/src/multimedia/platform/qplatformsurfacecapture.cpp @@ -53,27 +53,17 @@ void QPlatformSurfaceCapture::setSource(Source source) QPlatformSurfaceCapture::Error QPlatformSurfaceCapture::error() const { - return m_error; + return m_error.code(); } QString QPlatformSurfaceCapture::errorString() const { - return m_errorString; + return m_error.description(); } void QPlatformSurfaceCapture::updateError(Error error, const QString &errorString) { - bool changed = error != m_error || errorString != m_errorString; - m_error = error; - m_errorString = errorString; - if (changed) { - if (m_error != NoError) { - emit errorOccurred(error, errorString); - qWarning() << "Screen capture fail:" << error << "," << errorString; - } - - emit errorChanged(); - } + m_error.setAndNotify(error, errorString, *this); } bool QPlatformSurfaceCapture::checkScreenWithError(ScreenSource &screen) diff --git a/src/multimedia/platform/qplatformsurfacecapture_p.h b/src/multimedia/platform/qplatformsurfacecapture_p.h index c99708f9a..42fbda474 100644 --- a/src/multimedia/platform/qplatformsurfacecapture_p.h +++ b/src/multimedia/platform/qplatformsurfacecapture_p.h @@ -19,6 +19,7 @@ #include "qscreen.h" #include "qcapturablewindow.h" #include "qpointer.h" +#include "private/qerrorinfo_p.h" #include <optional> #include <variant> @@ -77,8 +78,7 @@ Q_SIGNALS: void errorOccurred(Error error, QString errorString); private: - Error m_error = NoError; - QString m_errorString; + QErrorInfo<Error> m_error; Source m_source; bool m_active = false; }; |