From: Mohammed Sameer Date: Sun, 4 Aug 2013 00:36:18 +0000 (+0300) Subject: Cleanup current mode when Camera emits prepareForDeviceChange() X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=commitdiff_plain;h=3de1dd13b3d3b4d0c1fa75a064cd6facccbdc027 Cleanup current mode when Camera emits prepareForDeviceChange() --- diff --git a/declarative/mode.cpp b/declarative/mode.cpp index 45fb4cd..79e9109 100644 --- a/declarative/mode.cpp +++ b/declarative/mode.cpp @@ -47,6 +47,7 @@ void Mode::setCamera(Camera *camera) { } if (m_cam) { + QObject::disconnect(m_cam, SIGNAL(prepareForDeviceChange()), this, SLOT(prepareForDeviceChange())); QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged())); QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged())); } @@ -54,6 +55,7 @@ void Mode::setCamera(Camera *camera) { m_cam = camera; if (m_cam) { + QObject::connect(m_cam, SIGNAL(prepareForDeviceChange()), this, SLOT(prepareForDeviceChange())); QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged())); QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged())); } @@ -74,22 +76,6 @@ bool Mode::canCapture() { } void Mode::deviceChanged() { - if (m_mode) { - QObject::disconnect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged())); - QObject::disconnect(m_mode, SIGNAL(saved(const QString&)), - this, SIGNAL(saved(const QString&))); - QObject::disconnect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)), - this, SLOT(gotPreview(const QImage&, const QString&))); - QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged())); - QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged())); - QObject::disconnect(m_cam->device(), SIGNAL(idleStateChanged(bool)), - this, SIGNAL(canCaptureChanged())); - QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)), - this, SIGNAL(canCaptureChanged())); - - preChangeMode(); - } - if (!m_cam || !m_cam->device()) { return; } @@ -128,3 +114,21 @@ void Mode::gotPreview(const QImage& image, const QString& fileName) { bool Mode::isReady() const { return m_mode; } + +void Mode::prepareForDeviceChange() { + if (m_mode) { + QObject::disconnect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged())); + QObject::disconnect(m_mode, SIGNAL(saved(const QString&)), + this, SIGNAL(saved(const QString&))); + QObject::disconnect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)), + this, SLOT(gotPreview(const QImage&, const QString&))); + QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged())); + QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged())); + QObject::disconnect(m_cam->device(), SIGNAL(idleStateChanged(bool)), + this, SIGNAL(canCaptureChanged())); + QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)), + this, SIGNAL(canCaptureChanged())); + + preChangeMode(); + } +} diff --git a/declarative/mode.h b/declarative/mode.h index f8fb30b..95925d8 100644 --- a/declarative/mode.h +++ b/declarative/mode.h @@ -62,6 +62,7 @@ signals: private slots: void gotPreview(const QImage& image, const QString& fileName); void deviceChanged(); + void prepareForDeviceChange(); protected: virtual void preChangeMode() = 0;