/*!
* This file is part of CameraPlus.
*
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include "qtcamgstreamermessagelistener.h"
#include "qtcamdevice.h"
#include "qtcamdevice_p.h"
-
+#include <QPointer>
#include <QDebug>
#ifndef GST_USE_UNSTABLE_API
QObject(parent),
dev(device),
q_ptr(q),
- status(QtCamAutoFocus::None) {
+ status(QtCamAutoFocus::None),
+ cafStatus(QtCamAutoFocus::None) {
handler = new QtCamGStreamerMessageHandler(GST_PHOTOGRAPHY_AUTOFOCUS_DONE, this);
this, SLOT(handleMessage(GstMessage *)));
dev->listener()->addHandler(handler);
+
+ cafHandler = new QtCamGStreamerMessageHandler("caf-update", this);
+
+ QObject::connect(cafHandler, SIGNAL(messageSent(GstMessage *)),
+ this, SLOT(handleCafMessage(GstMessage *)));
+
+ dev->listener()->addHandler(cafHandler);
}
~QtCamAutoFocusPrivate() {
- dev->listener()->removeHandler(handler);
- delete handler; handler = 0;
+ if (dev && dev->listener()) {
+ dev->listener()->removeHandler(handler);
+ delete handler; handler = 0;
+ }
+
dev = 0;
q_ptr = 0;
}
gst_photography_set_autofocus(photo, enabled ? TRUE : FALSE);
+ if (enabled) {
+ status = QtCamAutoFocus::Running;
+ emit q_ptr->statusChanged();
+ }
+ else {
+ status = QtCamAutoFocus::None;
+ emit q_ptr->statusChanged();
+ }
+
return true;
}
-public slots:
- void handleMessage(GstMessage *message) {
+ bool setStatus(QtCamAutoFocus::Status *status, GstMessage *message) {
const GstStructure *s = gst_message_get_structure(message);
int st = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
-
if (gst_structure_get_int(s, "status", &st)) {
- if (status != st) {
- status = (QtCamAutoFocus::Status) st;
-
- // TODO: focus-window-rows, focus-window-columns, focus-windows and the rest
- emit q_ptr->statusChanged();
+ if (*status != st) {
+ *status = (QtCamAutoFocus::Status) st;
+ return true;
}
}
+
+ return false;
+ }
+
+public slots:
+ void handleMessage(GstMessage *message) {
+ if (setStatus(&status, message)) {
+ emit q_ptr->statusChanged();
+ }
+ }
+
+ void handleCafMessage(GstMessage *message) {
+ if (setStatus(&cafStatus, message)) {
+ emit q_ptr->cafStatusChanged();
+ }
}
public:
- QtCamDevice *dev;
+ QPointer<QtCamDevice> dev;
QtCamAutoFocus *q_ptr;
+
QtCamAutoFocus::Status status;
+ QtCamAutoFocus::Status cafStatus;
+
QtCamGStreamerMessageHandler *handler;
+ QtCamGStreamerMessageHandler *cafHandler;
};
#endif /* QT_CAM_AUTO_FOCUS_P_H */